/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Robert Collins
  • Date: 2008-09-22 23:21:26 UTC
  • mfrom: (3723 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3724.
  • Revision ID: robertc@robertcollins.net-20080922232126-liu0qmrb1lacom17
Resolve conflicts in NEWS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
569
569
    return length
570
570
 
571
571
 
 
572
def pump_string_file(bytes, file_handle, segment_size=None):
 
573
    """Write bytes to file_handle in many smaller writes.
 
574
 
 
575
    :param bytes: The string to write.
 
576
    :param file_handle: The file to write to.
 
577
    """
 
578
    # Write data in chunks rather than all at once, because very large
 
579
    # writes fail on some platforms (e.g. Windows with SMB  mounted
 
580
    # drives).
 
581
    if not segment_size:
 
582
        segment_size = 5242880 # 5MB
 
583
    segments = range(len(bytes) / segment_size + 1)
 
584
    write = file_handle.write
 
585
    for segment_index in segments:
 
586
        segment = buffer(bytes, segment_index * segment_size, segment_size)
 
587
        write(segment)
 
588
 
 
589
 
572
590
def file_iterator(input_file, readsize=32768):
573
591
    while True:
574
592
        b = input_file.read(readsize)
1260
1278
    """
1261
1279
    _lstat = os.lstat
1262
1280
    _directory = _directory_kind
1263
 
    _listdir = os.listdir
 
1281
    # Use C accelerated directory listing.
 
1282
    _listdir = _read_dir
1264
1283
    _kind_from_mode = _formats.get
1265
1284
 
1266
1285
    # 0 - relpath, 1- basename, 2- kind, 3- stat, 4-toppath
1276
1295
 
1277
1296
        dirblock = []
1278
1297
        append = dirblock.append
1279
 
        for name in sorted(_listdir(top)):
 
1298
        # read_dir supplies in should-stat order.
 
1299
        for _, name in sorted(_listdir(top)):
1280
1300
            abspath = top_slash + name
1281
1301
            statvalue = _lstat(abspath)
1282
1302
            kind = _kind_from_mode(statvalue.st_mode & 0170000, 'unknown')
1283
1303
            append((relprefix + name, name, kind, statvalue, abspath))
 
1304
        dirblock.sort()
1284
1305
        yield (relroot, top), dirblock
1285
1306
 
1286
1307
        # push the user specified dirs from dirblock
1404
1425
        return _cached_user_encoding
1405
1426
 
1406
1427
    if sys.platform == 'darwin':
1407
 
        # work around egregious python 2.4 bug
 
1428
        # python locale.getpreferredencoding() always return
 
1429
        # 'mac-roman' on darwin. That's a lie.
1408
1430
        sys.platform = 'posix'
1409
1431
        try:
 
1432
            if os.environ.get('LANG', None) is None:
 
1433
                # If LANG is not set, we end up with 'ascii', which is bad
 
1434
                # ('mac-roman' is more than ascii), so we set a default which
 
1435
                # will give us UTF-8 (which appears to work in all cases on
 
1436
                # OSX). Users are still free to override LANG of course, as
 
1437
                # long as it give us something meaningful. This work-around
 
1438
                # *may* not be needed with python 3k and/or OSX 10.5, but will
 
1439
                # work with them too -- vila 20080908
 
1440
                os.environ['LANG'] = 'en_US.UTF-8'
1410
1441
            import locale
1411
1442
        finally:
1412
1443
            sys.platform = 'darwin'
1449
1480
    return user_encoding
1450
1481
 
1451
1482
 
 
1483
def get_host_name():
 
1484
    """Return the current unicode host name.
 
1485
 
 
1486
    This is meant to be used in place of socket.gethostname() because that
 
1487
    behaves inconsistently on different platforms.
 
1488
    """
 
1489
    if sys.platform == "win32":
 
1490
        import win32utils
 
1491
        return win32utils.get_host_name()
 
1492
    else:
 
1493
        import socket
 
1494
        return socket.gethostname().decode(get_user_encoding())
 
1495
 
 
1496
 
1452
1497
def recv_all(socket, bytes):
1453
1498
    """Receive an exact number of bytes.
1454
1499
 
1525
1570
        base = abspath(pathjoin(base, '..', '..'))
1526
1571
    filename = pathjoin(base, resource_relpath)
1527
1572
    return open(filename, 'rU').read()
 
1573
 
 
1574
 
 
1575
try:
 
1576
    from bzrlib._readdir_pyx import read_dir as _read_dir
 
1577
except ImportError:
 
1578
    from bzrlib._readdir_py import read_dir as _read_dir