~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/directory_service.py

  • Committer: Aaron Bentley
  • Date: 2008-06-26 05:10:31 UTC
  • mto: This revision was merged to the branch mainline in revision 3514.
  • Revision ID: aaron@aaronbentley.com-20080626051031-ylyzlwa3t41dd3it
Add support for branch-associated locations

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
to true URLs.  Examples include lp:urls and per-user location aliases.
21
21
"""
22
22
 
23
 
from bzrlib import registry
 
23
from bzrlib import errors, registry
 
24
from bzrlib.branch import Branch
24
25
 
25
26
class DirectoryServiceRegistry(registry.Registry):
26
27
    """This object maintains and uses a list of directory services.
52
53
        return service().look_up(name, url)
53
54
 
54
55
directories = DirectoryServiceRegistry()
 
56
 
 
57
 
 
58
class AliasDirectory(object):
 
59
    """Directory lookup for locations associated with a branch.
 
60
 
 
61
    :parent, :submit, :public, and :bound are currently supported.  On error,
 
62
    a subclass of DirectoryLookupFailure will be raised.
 
63
    """
 
64
 
 
65
    def look_up(self, name, url):
 
66
        branch = Branch.open_containing('.')[0]
 
67
        lookups = {
 
68
            'parent': branch.get_parent,
 
69
            'submit': branch.get_submit_branch,
 
70
            'public': branch.get_public_branch,
 
71
            'bound': branch.get_bound_location,
 
72
        }
 
73
        try:
 
74
            method = lookups[url[1:]]
 
75
        except KeyError:
 
76
            raise errors.InvalidLocationAlias(url)
 
77
        else:
 
78
            result = method()
 
79
        if result is None:
 
80
            raise errors.UnsetLocationAlias(url)
 
81
        return result
 
82
 
 
83
directories.register(':', AliasDirectory,
 
84
                     'Easy access to remembered branch locations')