/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

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
from bzrlib import symbol_versioning
58
58
from bzrlib.symbol_versioning import (
59
59
    deprecated_function,
60
 
    zero_ninetythree,
 
60
    one_zero,
61
61
    )
62
62
from bzrlib.trace import mutter
63
63
 
468
468
        return pathjoin(F(p), e)
469
469
 
470
470
 
471
 
@deprecated_function(zero_ninetythree)
 
471
@deprecated_function(one_zero)
472
472
def backup_file(fn):
473
473
    """Copy a file to a backup.
474
474
 
1406
1406
        b += new
1407
1407
    return b
1408
1408
 
 
1409
 
 
1410
def send_all(socket, bytes):
 
1411
    """Send all bytes on a socket.
 
1412
 
 
1413
    Regular socket.sendall() can give socket error 10053 on Windows.  This
 
1414
    implementation sends no more than 64k at a time, which avoids this problem.
 
1415
    """
 
1416
    chunk_size = 2**16
 
1417
    for pos in xrange(0, len(bytes), chunk_size):
 
1418
        socket.sendall(bytes[pos:pos+chunk_size])
 
1419
 
 
1420
 
1409
1421
def dereference_path(path):
1410
1422
    """Determine the real path to a file.
1411
1423
 
1423
1435
def supports_mapi():
1424
1436
    """Return True if we can use MAPI to launch a mail client."""
1425
1437
    return sys.platform == "win32"
 
1438
 
 
1439
 
 
1440
def resource_string(package, resource_name):
 
1441
    """Load a resource from a package and return it as a string.
 
1442
 
 
1443
    Note: Only packages that start with bzrlib are currently supported.
 
1444
 
 
1445
    This is designed to be a lightweight implementation of resource
 
1446
    loading in a way which is API compatible with the same API from
 
1447
    pkg_resources. See
 
1448
    http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access.
 
1449
    If and when pkg_resources becomes a standard library, this routine
 
1450
    can delegate to it.
 
1451
    """
 
1452
    # Check package name is within bzrlib
 
1453
    if package == "bzrlib":
 
1454
        resource_relpath = resource_name
 
1455
    elif package.startswith("bzrlib."):
 
1456
        package = package[len("bzrlib."):].replace('.', os.sep)
 
1457
        resource_relpath = pathjoin(package, resource_name)
 
1458
    else:
 
1459
        raise errors.BzrError('resource package %s not in bzrlib' % package)
 
1460
 
 
1461
    # Map the resource to a file and read its contents
 
1462
    base = dirname(bzrlib.__file__)
 
1463
    if getattr(sys, 'frozen', None):    # bzr.exe
 
1464
        base = abspath(pathjoin(base, '..', '..'))
 
1465
    filename = pathjoin(base, resource_relpath)
 
1466
    return open(filename, 'rU').read()