/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: John Arbash Meinel
  • Date: 2007-12-20 12:34:06 UTC
  • mfrom: (3133 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3134.
  • Revision ID: john@arbash-meinel.com-20071220123406-4ijq232s46ecsutz
[merge] bzr.dev 3133

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
 
234
234
 
235
235
    success = False
236
236
    try:
237
 
        # This may throw an exception, in which case success will
238
 
        # not be set.
239
 
        rename_func(old, new)
240
 
        success = True
 
237
        try:
 
238
            # This may throw an exception, in which case success will
 
239
            # not be set.
 
240
            rename_func(old, new)
 
241
            success = True
 
242
        except (IOError, OSError), e:
 
243
            # source and target may be aliases of each other (e.g. on a
 
244
            # case-insensitive filesystem), so we may have accidentally renamed
 
245
            # source by when we tried to rename target
 
246
            if not (file_existed and e.errno in (None, errno.ENOENT)):
 
247
                raise
241
248
    finally:
242
249
        if file_existed:
243
250
            # If the file used to exist, rename it back into place
461
468
        return pathjoin(F(p), e)
462
469
 
463
470
 
464
 
@deprecated_function(zero_ninetythree)
 
471
@deprecated_function(one_zero)
465
472
def backup_file(fn):
466
473
    """Copy a file to a backup.
467
474
 
1399
1406
        b += new
1400
1407
    return b
1401
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
 
1402
1421
def dereference_path(path):
1403
1422
    """Determine the real path to a file.
1404
1423
 
1416
1435
def supports_mapi():
1417
1436
    """Return True if we can use MAPI to launch a mail client."""
1418
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()