/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-02-13 03:30:01 UTC
  • mfrom: (3221 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3224.
  • Revision ID: robertc@robertcollins.net-20080213033001-rw70ul0zb02ph856
Merge to fix conflicts.

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
353
360
 
354
361
 
355
362
def _mac_getcwd():
356
 
    return unicodedata.normalize('NFKC', os.getcwdu())
 
363
    return unicodedata.normalize('NFC', os.getcwdu())
357
364
 
358
365
 
359
366
# Default is to just use the python builtins, but these can be rebound on
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
 
663
670
        tt = time.localtime(t)
664
671
        offset = local_time_offset(t)
665
672
    else:
666
 
        raise errors.BzrError("unsupported timezone format %r" % timezone,
667
 
                              ['options are "utc", "original", "local"'])
 
673
        raise errors.UnsupportedTimezoneFormat(timezone)
668
674
    if date_fmt is None:
669
675
        date_fmt = "%a %Y-%m-%d %H:%M:%S"
670
676
    if show_offset:
1008
1014
    On platforms where the system does not normalize filenames 
1009
1015
    (Windows, Linux), you have to access a file by its exact path.
1010
1016
 
1011
 
    Internally, bzr only supports NFC/NFKC normalization, since that is 
 
1017
    Internally, bzr only supports NFC normalization, since that is 
1012
1018
    the standard for XML documents.
1013
1019
 
1014
1020
    So return the normalized path, and a flag indicating if the file
1015
1021
    can be accessed by that path.
1016
1022
    """
1017
1023
 
1018
 
    return unicodedata.normalize('NFKC', unicode(path)), True
 
1024
    return unicodedata.normalize('NFC', unicode(path)), True
1019
1025
 
1020
1026
 
1021
1027
def _inaccessible_normalized_filename(path):
1022
1028
    __doc__ = _accessible_normalized_filename.__doc__
1023
1029
 
1024
 
    normalized = unicodedata.normalize('NFKC', unicode(path))
 
1030
    normalized = unicodedata.normalize('NFC', unicode(path))
1025
1031
    return normalized, normalized == path
1026
1032
 
1027
1033
 
1399
1405
        b += new
1400
1406
    return b
1401
1407
 
 
1408
 
 
1409
def send_all(socket, bytes):
 
1410
    """Send all bytes on a socket.
 
1411
 
 
1412
    Regular socket.sendall() can give socket error 10053 on Windows.  This
 
1413
    implementation sends no more than 64k at a time, which avoids this problem.
 
1414
    """
 
1415
    chunk_size = 2**16
 
1416
    for pos in xrange(0, len(bytes), chunk_size):
 
1417
        socket.sendall(bytes[pos:pos+chunk_size])
 
1418
 
 
1419
 
1402
1420
def dereference_path(path):
1403
1421
    """Determine the real path to a file.
1404
1422
 
1416
1434
def supports_mapi():
1417
1435
    """Return True if we can use MAPI to launch a mail client."""
1418
1436
    return sys.platform == "win32"
 
1437
 
 
1438
 
 
1439
def resource_string(package, resource_name):
 
1440
    """Load a resource from a package and return it as a string.
 
1441
 
 
1442
    Note: Only packages that start with bzrlib are currently supported.
 
1443
 
 
1444
    This is designed to be a lightweight implementation of resource
 
1445
    loading in a way which is API compatible with the same API from
 
1446
    pkg_resources. See
 
1447
    http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access.
 
1448
    If and when pkg_resources becomes a standard library, this routine
 
1449
    can delegate to it.
 
1450
    """
 
1451
    # Check package name is within bzrlib
 
1452
    if package == "bzrlib":
 
1453
        resource_relpath = resource_name
 
1454
    elif package.startswith("bzrlib."):
 
1455
        package = package[len("bzrlib."):].replace('.', os.sep)
 
1456
        resource_relpath = pathjoin(package, resource_name)
 
1457
    else:
 
1458
        raise errors.BzrError('resource package %s not in bzrlib' % package)
 
1459
 
 
1460
    # Map the resource to a file and read its contents
 
1461
    base = dirname(bzrlib.__file__)
 
1462
    if getattr(sys, 'frozen', None):    # bzr.exe
 
1463
        base = abspath(pathjoin(base, '..', '..'))
 
1464
    filename = pathjoin(base, resource_relpath)
 
1465
    return open(filename, 'rU').read()