~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/directory_service.py

  • Committer: Samuel Bronson
  • Date: 2012-08-30 20:36:18 UTC
  • mto: (6015.57.3 2.4)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: naesten@gmail.com-20120830203618-y2dzw91nqpvpgxvx
Update INSTALL for switch to Python 2.6 and up.

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