/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/launchpad/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Launchpad.net integration plugin for Bazaar.
18
18
 
19
19
This plugin provides facilities for working with Bazaar branches that are
20
 
hosted on Launchpad (http://launchpad.net).  It provides a directory service 
 
20
hosted on Launchpad (http://launchpad.net).  It provides a directory service
21
21
for referring to Launchpad branches using the "lp:" prefix.  For example,
22
22
lp:bzr refers to the Bazaar's main development branch and
23
23
lp:~username/project/branch-name can be used to refer to a specific branch.
29
29
 
30
30
    launchpad-login: Show or set the Launchpad user ID
31
31
    launchpad-open: Open a Launchpad branch page in your web browser
 
32
 
 
33
As well as the following deprecated command:
 
34
 
32
35
    lp-propose-merge: Propose merging a branch on Launchpad
33
 
    launchpad-mirror: Ask Launchpad to mirror a branch now
 
36
         (deprecated in favour of the more generic 'brz propose-merge')
34
37
 
35
38
"""
36
39
 
47
50
    lazy_regex,
48
51
    # Since we are a built-in plugin we share the breezy version
49
52
    trace,
50
 
    version_info,
 
53
    version_info,  # noqa: F401
51
54
    )
52
55
from ...commands import (
53
56
    plugin_cmds,
59
62
    ("cmd_launchpad_open", ["lp-open"]),
60
63
    ("cmd_launchpad_login", ["lp-login"]),
61
64
    ("cmd_launchpad_logout", ["lp-logout"]),
62
 
    ("cmd_launchpad_mirror", ["lp-mirror"]),
63
65
    ("cmd_lp_propose_merge", ["lp-submit", "lp-propose"]),
64
 
    ("cmd_lp_find_proposal", [])]:
 
66
        ("cmd_lp_find_proposal", [])]:
65
67
    plugin_cmds.register_lazy(klsname, aliases,
66
 
        "breezy.plugins.launchpad.cmds")
 
68
                              "breezy.plugins.launchpad.cmds")
67
69
 
68
70
 
69
71
def _register_directory():
70
72
    directories.register_lazy('lp:', 'breezy.plugins.launchpad.lp_directory',
71
73
                              'LaunchpadDirectory',
72
74
                              'Launchpad-based directory service',)
 
75
    directories.register_lazy('lp+bzr:', 'breezy.plugins.launchpad.lp_directory',
 
76
                              'LaunchpadDirectory',
 
77
                              'Bazaar-specific Launchpad directory service',)
73
78
    directories.register_lazy(
74
79
        'debianlp:', 'breezy.plugins.launchpad.lp_directory',
75
80
        'LaunchpadDirectory',
79
84
        'LaunchpadDirectory',
80
85
        'ubuntu: shortcut')
81
86
 
 
87
 
82
88
_register_directory()
83
89
 
84
 
# This is kept in __init__ so that we don't load lp_api_lite unless the branch
85
 
# actually matches. That way we can avoid importing extra dependencies like
86
 
# json.
87
 
_package_branch = lazy_regex.lazy_compile(
88
 
    r'bazaar.launchpad.net.*?/'
89
 
    r'(?P<user>~[^/]+/)?(?P<archive>ubuntu|debian)/(?P<series>[^/]+/)?'
90
 
    r'(?P<project>[^/]+)(?P<branch>/[^/]+)?'
91
 
    )
92
 
 
93
 
def _get_package_branch_info(url):
94
 
    """Determine the packaging information for this URL.
95
 
 
96
 
    :return: If this isn't a packaging branch, return None. If it is, return
97
 
        (archive, series, project)
98
 
    """
99
 
    if url is None:
100
 
        return None
101
 
    m = _package_branch.search(url)
102
 
    if m is None:
103
 
        return None
104
 
    archive, series, project, user = m.group('archive', 'series',
105
 
                                             'project', 'user')
106
 
    if series is not None:
107
 
        # series is optional, so the regex includes the extra '/', we don't
108
 
        # want to send that on (it causes Internal Server Errors.)
109
 
        series = series.strip('/')
110
 
    if user is not None:
111
 
        user = user.strip('~/')
112
 
        if user != 'ubuntu-branches':
113
 
            return None
114
 
    return archive, series, project
115
 
 
116
 
 
117
 
def _check_is_up_to_date(the_branch):
118
 
    info = _get_package_branch_info(the_branch.base)
119
 
    if info is None:
120
 
        return
121
 
    c = the_branch.get_config_stack()
122
 
    verbosity = c.get('launchpad.packaging_verbosity')
123
 
    if not verbosity:
124
 
        trace.mutter('not checking %s because verbosity is turned off'
125
 
                     % (the_branch.base,))
126
 
        return
127
 
    archive, series, project = info
128
 
    from . import lp_api_lite
129
 
    latest_pub = lp_api_lite.LatestPublication(archive, series, project)
130
 
    lp_api_lite.report_freshness(the_branch, verbosity, latest_pub)
131
 
 
132
 
 
133
 
def _register_hooks():
134
 
    _mod_branch.Branch.hooks.install_named_hook('open',
135
 
        _check_is_up_to_date, 'package-branch-up-to-date')
136
 
 
137
 
 
138
 
_register_hooks()
139
 
 
140
90
def load_tests(loader, basic_tests, pattern):
141
91
    testmod_names = [
142
92
        'test_account',
143
93
        'test_register',
144
94
        'test_lp_api',
145
 
        'test_lp_api_lite',
146
95
        'test_lp_directory',
147
96
        'test_lp_login',
148
97
        'test_lp_open',
149
98
        'test_lp_service',
150
99
        ]
151
100
    basic_tests.addTest(loader.loadTestsFromModuleNames(
152
 
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
101
        ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
153
102
    return basic_tests
154
103
 
155
104
 
179
128
For more information see http://help.launchpad.net/
180
129
"""
181
130
topic_registry.register('launchpad',
182
 
    _launchpad_help,
183
 
    'Using Bazaar with Launchpad.net')
184
 
 
185
 
_mod_config.option_registry.register(
186
 
    _mod_config.Option('launchpad.packaging_verbosity', default=True,
187
 
          from_unicode=_mod_config.bool_from_store,
188
 
          help="""\
189
 
Whether to warn if a UDD package import branch is accessed that is out of date.
190
 
 
191
 
Setting this option to 'off' will disable verbosity.
192
 
"""))
193
 
_mod_config.option_registry.register(
194
 
    _mod_config.Option('launchpad_username', default=None,
195
 
        help="The username to login with when conneting to Launchpad."))
 
131
                        _launchpad_help,
 
132
                        'Using Bazaar with Launchpad.net')