~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/directory_service.py

  • Committer: Vincent Ladeuil
  • Date: 2012-03-09 16:48:55 UTC
  • mto: (6437.23.24 2.5)
  • mto: This revision was merged to the branch mainline in revision 6499.
  • Revision ID: v.ladeuil+lp@free.fr-20120309164855-htdn25hp7x65mmir
Rely on sphinx for texinfo doc generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
to true URLs.  Examples include lp:urls and per-user location aliases.
21
21
"""
22
22
 
23
 
from bzrlib import errors, registry
 
23
from __future__ import absolute_import
 
24
 
 
25
from bzrlib import (
 
26
    errors,
 
27
    registry,
 
28
    )
24
29
from bzrlib.lazy_import import lazy_import
25
30
lazy_import(globals(), """
26
 
from bzrlib.branch import Branch
27
 
from bzrlib import urlutils
 
31
from bzrlib import (
 
32
    branch as _mod_branch,
 
33
    urlutils,
 
34
    )
28
35
""")
29
36
 
30
37
 
59
66
 
60
67
directories = DirectoryServiceRegistry()
61
68
 
62
 
 
63
69
class AliasDirectory(object):
64
70
    """Directory lookup for locations associated with a branch.
65
71
 
67
73
    supported.  On error, a subclass of DirectoryLookupFailure will be raised.
68
74
    """
69
75
 
 
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
 
70
90
    def look_up(self, name, url):
71
 
        branch = Branch.open_containing('.')[0]
72
 
        lookups = {
73
 
            'parent': branch.get_parent,
74
 
            'submit': branch.get_submit_branch,
75
 
            'public': branch.get_public_branch,
76
 
            'bound': branch.get_bound_location,
77
 
            'push': branch.get_push_location,
78
 
            'this': lambda: branch.base
79
 
        }
 
91
        branch = _mod_branch.Branch.open_containing('.')[0]
80
92
        parts = url.split('/', 1)
81
93
        if len(parts) == 2:
82
94
            name, extra = parts
84
96
            (name,) = parts
85
97
            extra = None
86
98
        try:
87
 
            method = lookups[name[1:]]
 
99
            method = self.branch_aliases.get(name[1:])
88
100
        except KeyError:
89
101
            raise errors.InvalidLocationAlias(url)
90
102
        else:
91
 
            result = method()
 
103
            result = method(branch)
92
104
        if result is None:
93
105
            raise errors.UnsetLocationAlias(url)
94
106
        if extra is not None:
95
107
            result = urlutils.join(result, extra)
96
108
        return result
97
109
 
 
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
 
98
132
directories.register(':', AliasDirectory,
99
133
                     'Easy access to remembered branch locations')