~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Ian Clatworthy
  • Date: 2007-12-17 04:49:20 UTC
  • mfrom: (3089.3.17 bzr.ug-tweaks)
  • mto: This revision was merged to the branch mainline in revision 3120.
  • Revision ID: ian.clatworthy@internode.on.net-20071217044920-8fjh9v6m1t93c8dc
Move material out of User Guide into User Reference (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1406
1406
        b += new
1407
1407
    return b
1408
1408
 
 
1409
 
1409
1410
def dereference_path(path):
1410
1411
    """Determine the real path to a file.
1411
1412
 
1423
1424
def supports_mapi():
1424
1425
    """Return True if we can use MAPI to launch a mail client."""
1425
1426
    return sys.platform == "win32"
 
1427
 
 
1428
 
 
1429
def resource_string(package, resource_name):
 
1430
    """Load a resource from a package and return it as a string.
 
1431
 
 
1432
    Note: Only packages that start with bzrlib are currently supported.
 
1433
 
 
1434
    This is designed to be a lightweight implementation of resource
 
1435
    loading in a way which is API compatible with the same API from
 
1436
    pkg_resources. See
 
1437
    http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access.
 
1438
    If and when pkg_resources becomes a standard library, this routine
 
1439
    can delegate to it.
 
1440
    """
 
1441
    # Check package name is within bzrlib
 
1442
    if package == "bzrlib":
 
1443
        resource_relpath = resource_name
 
1444
    elif package.startswith("bzrlib."):
 
1445
        package = package[len("bzrlib."):].replace('.', os.sep)
 
1446
        resource_relpath = pathjoin(package, resource_name)
 
1447
    else:
 
1448
        raise errors.BzrError('resource package %s not in bzrlib' % package)
 
1449
 
 
1450
    # Map the resource to a file and read its contents
 
1451
    base = dirname(bzrlib.__file__)
 
1452
    if getattr(sys, 'frozen', None):    # bzr.exe
 
1453
        base = abspath(pathjoin(base, '..', '..'))
 
1454
    filename = pathjoin(base, resource_relpath)
 
1455
    return open(filename, 'rU').read()