~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/directory_service.py

(gz) Never raise KnownFailure in tests,
 use knownFailure method instead (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
 
65
65
directories = DirectoryServiceRegistry()
66
66
 
 
67
 
67
68
class AliasDirectory(object):
68
69
    """Directory lookup for locations associated with a branch.
69
70
 
71
72
    supported.  On error, a subclass of DirectoryLookupFailure will be raised.
72
73
    """
73
74
 
74
 
    branch_aliases = registry.Registry()
75
 
    branch_aliases.register('parent', lambda b: b.get_parent(),
76
 
        help="The parent of this branch.")
77
 
    branch_aliases.register('submit', lambda b: b.get_submit_branch(),
78
 
        help="The submit branch for this branch.")
79
 
    branch_aliases.register('public', lambda b: b.get_public_branch(),
80
 
        help="The public location of this branch.")
81
 
    branch_aliases.register('bound', lambda b: b.get_bound_location(),
82
 
        help="The branch this branch is bound to, for bound branches.")
83
 
    branch_aliases.register('push', lambda b: b.get_push_location(),
84
 
        help="The saved location used for `bzr push` with no arguments.")
85
 
    branch_aliases.register('this', lambda b: b.base,
86
 
        help="This branch.")
87
 
 
88
75
    def look_up(self, name, url):
89
76
        branch = _mod_branch.Branch.open_containing('.')[0]
 
77
        lookups = {
 
78
            'parent': branch.get_parent,
 
79
            'submit': branch.get_submit_branch,
 
80
            'public': branch.get_public_branch,
 
81
            'bound': branch.get_bound_location,
 
82
            'push': branch.get_push_location,
 
83
            'this': lambda: branch.base
 
84
        }
90
85
        parts = url.split('/', 1)
91
86
        if len(parts) == 2:
92
87
            name, extra = parts
94
89
            (name,) = parts
95
90
            extra = None
96
91
        try:
97
 
            method = self.branch_aliases.get(name[1:])
 
92
            method = lookups[name[1:]]
98
93
        except KeyError:
99
94
            raise errors.InvalidLocationAlias(url)
100
95
        else:
101
 
            result = method(branch)
 
96
            result = method()
102
97
        if result is None:
103
98
            raise errors.UnsetLocationAlias(url)
104
99
        if extra is not None:
105
100
            result = urlutils.join(result, extra)
106
101
        return result
107
102
 
108
 
    @classmethod
109
 
    def help_text(cls, topic):
110
 
        alias_lines = []
111
 
        for key in cls.branch_aliases.keys():
112
 
            help = cls.branch_aliases.get_help(key)
113
 
            alias_lines.append("  :%-10s%s\n" % (key, help))
114
 
        return """\
115
 
Location aliases
116
 
================
117
 
 
118
 
Bazaar defines several aliases for locations associated with a branch.  These
119
 
can be used with most commands that expect a location, such as `bzr push`.
120
 
 
121
 
The aliases are::
122
 
 
123
 
%s
124
 
For example, to push to the parent location::
125
 
 
126
 
    bzr push :parent
127
 
""" % "".join(alias_lines)
128
 
 
129
 
 
130
103
directories.register(':', AliasDirectory,
131
104
                     'Easy access to remembered branch locations')