/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/cmds.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Launchpad plugin commands."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from ... import (
20
22
    branch as _mod_branch,
21
23
    controldir,
25
27
    Command,
26
28
    )
27
29
from ...errors import (
28
 
    CommandError,
 
30
    BzrCommandError,
 
31
    InvalidURL,
29
32
    NotBranchError,
30
33
    )
31
34
from ...i18n import gettext
62
65
 
63
66
    def _get_web_url(self, service, location):
64
67
        from .lp_registration import (
65
 
            InvalidURL,
66
68
            NotLaunchpadBranch)
67
69
        for branch_url in self._possible_locations(location):
68
70
            try:
80
82
        trace.note(gettext('Opening %s in web browser') % web_url)
81
83
        if not dry_run:
82
84
            import webbrowser   # this import should not be lazy
83
 
            # otherwise brz.exe lacks this module
 
85
                                # otherwise brz.exe lacks this module
84
86
            webbrowser.open(web_url)
85
87
 
86
88
 
135
137
            account.set_lp_login(name)
136
138
            if verbose:
137
139
                self.outf.write(gettext("Launchpad user ID set to '%s'.\n") %
138
 
                                (name,))
139
 
 
140
 
 
141
 
class cmd_launchpad_logout(Command):
142
 
    __doc__ = """Unset the Launchpad user ID.
143
 
 
144
 
    When communicating with Launchpad, some commands need to know your
145
 
    Launchpad user ID.  This command will log you out from Launchpad.
146
 
    This means that communication with Launchpad will happen over
147
 
    HTTPS, and will not require one of your SSH keys to be available.
 
140
                                                                        (name,))
 
141
 
 
142
 
 
143
# XXX: cmd_launchpad_mirror is untested
 
144
class cmd_launchpad_mirror(Command):
 
145
    __doc__ = """Ask Launchpad to mirror a branch now."""
 
146
 
 
147
    aliases = ['lp-mirror']
 
148
    takes_args = ['location?']
 
149
 
 
150
    def run(self, location='.'):
 
151
        from . import lp_api
 
152
        from .lp_registration import LaunchpadService
 
153
        branch, _ = _mod_branch.Branch.open_containing(location)
 
154
        service = LaunchpadService()
 
155
        launchpad = lp_api.login(service)
 
156
        lp_branch = lp_api.LaunchpadBranch.from_bzr(launchpad, branch,
 
157
                create_missing=False)
 
158
        lp_branch.lp.requestMirror()
 
159
 
 
160
 
 
161
class cmd_lp_propose_merge(Command):
 
162
    __doc__ = """Propose merging a branch on Launchpad.
 
163
 
 
164
    This will open your usual editor to provide the initial comment.  When it
 
165
    has created the proposal, it will open it in your default web browser.
 
166
 
 
167
    The branch will be proposed to merge into SUBMIT_BRANCH.  If SUBMIT_BRANCH
 
168
    is not supplied, the remembered submit branch will be used.  If no submit
 
169
    branch is remembered, the development focus will be used.
 
170
 
 
171
    By default, the SUBMIT_BRANCH's review team will be requested to review
 
172
    the merge proposal.  This can be overriden by specifying --review (-R).
 
173
    The parameter the launchpad account name of the desired reviewer.  This
 
174
    may optionally be followed by '=' and the review type.  For example:
 
175
 
 
176
      brz lp-propose-merge --review jrandom --review review-team=qa
 
177
 
 
178
    This will propose a merge,  request "jrandom" to perform a review of
 
179
    unspecified type, and request "review-team" to perform a "qa" review.
148
180
    """
149
 
    aliases = ['lp-logout']
150
 
    takes_options = ['verbose']
151
 
 
152
 
    def run(self, verbose=False):
153
 
        from . import account
154
 
        old_username = account.get_lp_login()
155
 
        if old_username is None:
156
 
            self.outf.write(gettext('Not logged into Launchpad.\n'))
157
 
            return 1
158
 
        account.set_lp_login(None)
159
 
        if verbose:
160
 
            self.outf.write(gettext(
161
 
                "Launchpad user ID %s logged out.\n") %
162
 
                old_username)
 
181
 
 
182
    takes_options = [Option('staging',
 
183
                            help='Propose the merge on staging.'),
 
184
                     Option('message', short_name='m', type=unicode,
 
185
                            help='Commit message.'),
 
186
                     Option('approve',
 
187
                            help=('Mark the proposal as approved immediately, '
 
188
                                  'setting the approved revision to tip.')),
 
189
                     Option('fixes', 'The bug this proposal fixes.', str),
 
190
                     ListOption('review', short_name='R', type=unicode,
 
191
                            help='Requested reviewer and optional type.')]
 
192
 
 
193
    takes_args = ['submit_branch?']
 
194
 
 
195
    aliases = ['lp-submit', 'lp-propose']
 
196
 
 
197
    def run(self, submit_branch=None, review=None, staging=False,
 
198
            message=None, approve=False, fixes=None):
 
199
        from . import lp_propose
 
200
        tree, branch, relpath = controldir.ControlDir.open_containing_tree_or_branch(
 
201
            '.')
 
202
        if review is None:
 
203
            reviews = None
 
204
        else:
 
205
            reviews = []
 
206
            for review in review:
 
207
                if '=' in review:
 
208
                    reviews.append(review.split('=', 2))
 
209
                else:
 
210
                    reviews.append((review, ''))
 
211
            if submit_branch is None:
 
212
                submit_branch = branch.get_submit_branch()
 
213
        if submit_branch is None:
 
214
            target = None
 
215
        else:
 
216
            target = _mod_branch.Branch.open(submit_branch)
 
217
        proposer = lp_propose.Proposer(tree, branch, target, message,
 
218
                                       reviews, staging, approve=approve,
 
219
                                       fixes=fixes)
 
220
        proposer.check_proposal()
 
221
        proposer.create_proposal()
163
222
 
164
223
 
165
224
class cmd_lp_find_proposal(Command):
185
244
        from . import lp_api
186
245
        import webbrowser
187
246
        b = _mod_branch.Branch.open_containing('.')[0]
188
 
        with ui.ui_factory.nested_progress_bar() as pb, b.lock_read():
 
247
        pb = ui.ui_factory.nested_progress_bar()
 
248
        b.lock_read()
 
249
        try:
189
250
            if revision is None:
190
251
                revision_id = b.last_revision()
191
252
            else:
192
253
                revision_id = revision[0].as_revision_id(b)
193
254
            merged = self._find_proposals(revision_id, pb)
194
255
            if len(merged) == 0:
195
 
                raise CommandError(gettext('No review found.'))
 
256
                raise BzrCommandError(gettext('No review found.'))
196
257
            trace.note(gettext('%d proposals(s) found.') % len(merged))
197
258
            for mp in merged:
198
259
                webbrowser.open(lp_api.canonical_url(mp))
 
260
        finally:
 
261
            b.unlock()
 
262
            pb.finished()
199
263
 
200
264
    def _find_proposals(self, revision_id, pb):
201
 
        from launchpadlib import uris
202
 
        from . import lp_api
 
265
        from . import (lp_api, lp_registration)
203
266
        # "devel" because branches.getMergeProposals is not part of 1.0 API.
204
 
        lp_base_url = uris.LPNET_SERVICE_ROOT
205
 
        launchpad = lp_api.connect_launchpad(lp_base_url, version='devel')
 
267
        launchpad = lp_api.login(lp_registration.LaunchpadService(),
 
268
                                 version='devel')
206
269
        pb.update(gettext('Finding proposals'))
207
270
        return list(launchpad.branches.getMergeProposals(
208
 
                    merged_revision=revision_id.decode('utf-8')))
 
271
                    merged_revision=revision_id))