~ubuntu-branches/ubuntu/karmic/bzr/karmic-proposed

« back to all changes in this revision

Viewing changes to bzrlib/directory_service.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2008-08-25 19:06:49 UTC
  • mfrom: (1.1.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825190649-pq87jonr4uvs7s0y
Tags: 1.6-1
New upstream release.

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, :push, :this, and :bound are currently
 
62
    supported.  On error, 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
            'push': branch.get_push_location,
 
73
            'this': lambda: branch.base
 
74
        }
 
75
        try:
 
76
            method = lookups[url[1:]]
 
77
        except KeyError:
 
78
            raise errors.InvalidLocationAlias(url)
 
79
        else:
 
80
            result = method()
 
81
        if result is None:
 
82
            raise errors.UnsetLocationAlias(url)
 
83
        return result
 
84
 
 
85
directories.register(':', AliasDirectory,
 
86
                     'Easy access to remembered branch locations')