13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Directory service registration and usage.
20
20
to true URLs. Examples include lp:urls and per-user location aliases.
23
from __future__ import absolute_import
29
from bzrlib.lazy_import import lazy_import
30
lazy_import(globals(), """
32
branch as _mod_branch,
33
controldir as _mod_controldir,
23
from bzrlib import errors, registry
24
from bzrlib.branch import Branch
39
26
class DirectoryServiceRegistry(registry.Registry):
40
27
"""This object maintains and uses a list of directory services.
74
62
supported. On error, a subclass of DirectoryLookupFailure will be raised.
77
branch_aliases = registry.Registry()
78
branch_aliases.register('parent', lambda b: b.get_parent(),
79
help="The parent of this branch.")
80
branch_aliases.register('submit', lambda b: b.get_submit_branch(),
81
help="The submit branch for this branch.")
82
branch_aliases.register('public', lambda b: b.get_public_branch(),
83
help="The public location of this branch.")
84
branch_aliases.register('bound', lambda b: b.get_bound_location(),
85
help="The branch this branch is bound to, for bound branches.")
86
branch_aliases.register('push', lambda b: b.get_push_location(),
87
help="The saved location used for `bzr push` with no arguments.")
88
branch_aliases.register('this', lambda b: b.base,
91
65
def look_up(self, name, url):
92
branch = _mod_branch.Branch.open_containing('.')[0]
93
parts = url.split('/', 1)
66
branch = Branch.open_containing('.')[0]
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
100
method = self.branch_aliases.get(name[1:])
76
method = lookups[url[1:]]
102
78
raise errors.InvalidLocationAlias(url)
104
result = method(branch)
105
81
if result is None:
106
82
raise errors.UnsetLocationAlias(url)
107
if extra is not None:
108
result = urlutils.join(result, extra)
112
def help_text(cls, topic):
114
for key in cls.branch_aliases.keys():
115
help = cls.branch_aliases.get_help(key)
116
alias_lines.append(" :%-10s%s\n" % (key, help))
121
Bazaar defines several aliases for locations associated with a branch. These
122
can be used with most commands that expect a location, such as `bzr push`.
127
For example, to push to the parent location::
130
""" % "".join(alias_lines)
133
85
directories.register(':', AliasDirectory,
134
86
'Easy access to remembered branch locations')
137
class ColocatedDirectory(object):
138
"""Directory lookup for colocated branches.
140
co:somename will resolve to the colocated branch with "somename" in
141
the current directory.
144
def look_up(self, name, url):
145
dir = _mod_controldir.ControlDir.open_containing('.')[0]
146
return urlutils.join_segment_parameters(dir.user_url,
147
{"branch": urlutils.escape(name)})
150
directories.register('co:', ColocatedDirectory,
151
'Easy access to colocated branches')