/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: Andrew Bennetts
  • Date: 2007-12-19 02:44:29 UTC
  • mfrom: (3126 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3127.
  • Revision ID: andrew.bennetts@canonical.com-20071219024429-fs7rnw9jygo0bj6g
Merge from 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
 
1435
1435
def supports_mapi():
1436
1436
    """Return True if we can use MAPI to launch a mail client."""
1437
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()