/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: Aaron Bentley
  • Date: 2008-09-08 20:26:41 UTC
  • mfrom: (3696 +trunk)
  • mto: (3363.13.5 extras)
  • mto: This revision was merged to the branch mainline in revision 3715.
  • Revision ID: aaron@aaronbentley.com-20080908202641-7w9dyg04344t262b
Merge with bzr.dev

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
1449
1470
    return user_encoding
1450
1471
 
1451
1472
 
 
1473
def get_host_name():
 
1474
    """Return the current unicode host name.
 
1475
 
 
1476
    This is meant to be used in place of socket.gethostname() because that
 
1477
    behaves inconsistently on different platforms.
 
1478
    """
 
1479
    if sys.platform == "win32":
 
1480
        import win32utils
 
1481
        return win32utils.get_host_name()
 
1482
    else:
 
1483
        import socket
 
1484
        return socket.gethostname().decode(get_user_encoding())
 
1485
 
 
1486
 
1452
1487
def recv_all(socket, bytes):
1453
1488
    """Receive an exact number of bytes.
1454
1489
 
1525
1560
        base = abspath(pathjoin(base, '..', '..'))
1526
1561
    filename = pathjoin(base, resource_relpath)
1527
1562
    return open(filename, 'rU').read()
 
1563
 
 
1564
 
 
1565
try:
 
1566
    from bzrlib._readdir_pyx import read_dir as _read_dir
 
1567
except ImportError:
 
1568
    from bzrlib._readdir_py import read_dir as _read_dir