~bzr-pqm-devel/bzr-pqm/devel

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Jelmer Vernooij
  • Date: 2012-03-01 21:54:15 UTC
  • mfrom: (80.3.1 lazy)
  • Revision ID: jelmer@samba.org-20120301215415-kuhz0liy2hrilfx7
Merge lazy loading of plugin commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 by Canonical Ltd
 
1
# Copyright (C) 2006-2012 by 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
19
19
from __future__ import absolute_import
20
20
 
21
21
from bzrlib import version_info as bzrlib_version
22
 
from bzrlib.commands import Command, register_command
23
 
from bzrlib.option import Option
24
 
from bzrlib.errors import BzrCommandError
 
22
from bzrlib.commands import plugin_cmds
25
23
 
26
24
 
27
25
version_info = (1, 4, 0, 'dev', 0)
33
31
__version__ = version_string
34
32
 
35
33
 
36
 
class cmd_pqm_submit(Command):
37
 
    """Submit the parent tree to the pqm.
38
 
 
39
 
    This acts like:
40
 
        $ echo "star-merge $PARENT $TARGET"
41
 
            | gpg --cl
42
 
            | mail pqm@somewhere -s "merge text"
43
 
 
44
 
    But it pays attention to who the local committer is
45
 
    (using their e-mail address), and uses the local
46
 
    gpg signing configuration. (As well as target pqm
47
 
    settings, etc.)
48
 
 
49
 
    The reason we use 'parent' instead of the local branch
50
 
    is that most likely the local branch is not a public
51
 
    branch. And the branch must be available to the pqm.
52
 
 
53
 
    This can be configured at the branch level using ~/.bazaar/locations.conf.
54
 
    Here is an example:
55
 
        [/home/emurphy/repo]
56
 
        pqm_email = PQM <pqm@example.com>
57
 
        pqm_user_email = User Name <user@example.com>
58
 
        submit_branch = http://code.example.com/code/project/devel
59
 
        # Set public_branch appropriately for all branches in repository:
60
 
        public_branch = http://code.example.com/code/emurphy/project
61
 
        public_branch:policy = appendpath
62
 
        [/home/emurphy/repo/branch]
63
 
        # Override public_branch for this repository:
64
 
        public_branch = http://alternate.host.example.com/other/public/branch
65
 
 
66
 
        smtp_server = host:port
67
 
        smtp_username =
68
 
        smtp_password =
69
 
 
70
 
    If you don't specify the smtp server, the message will be sent via localhost.
71
 
    """
72
 
 
73
 
    takes_args = ['location?']
74
 
    takes_options = [
75
 
        Option('message',
76
 
               help='Message to use on merge to pqm.  '
77
 
                    'Currently must be a single line because of pqm limits.',
78
 
               short_name='m',
79
 
               type=unicode),
80
 
        Option('dry-run', help='Print request instead of sending.'),
81
 
        Option('public-location', type=str,
82
 
               help='Use this url as the public location to the pqm.'),
83
 
        Option('submit-branch', type=str,
84
 
               help='Use this url as the target submission branch.'),
85
 
        Option('ignore-local', help='Do not check the local branch or tree.'),
86
 
        ]
87
 
 
88
 
    def run(self, location=None, message=None, public_location=None,
89
 
            dry_run=False, submit_branch=None, ignore_local=False):
90
 
        from bzrlib import trace, bzrdir
91
 
        if __name__ != 'bzrlib.plugins.pqm':
92
 
            trace.warning('The bzr-pqm plugin needs to be called'
93
 
                          ' "bzrlib.plugins.pqm" not "%s"\n'
94
 
                          'Please rename the plugin.',
95
 
                          __name__)
96
 
            return 1
97
 
        from bzrlib.plugins.pqm.pqm_submit import submit
98
 
 
99
 
        if ignore_local:
100
 
            tree, b, relpath = None, None, None
101
 
        else:
102
 
            if location is None:
103
 
                location = '.'
104
 
            tree, b, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
105
 
                location)
106
 
            if b is not None:
107
 
                b.lock_read()
108
 
                self.add_cleanup(b.unlock)
109
 
        if relpath and not tree and location != '.':
110
 
            raise BzrCommandError(
111
 
                'No working tree was found, but we were not given the '
112
 
                'exact path to the branch.\n'
113
 
                'We found a branch at: %s' % (b.base,))
114
 
        if message is None:
115
 
            raise BzrCommandError(
116
 
                'You must supply a commit message for the pqm to use.')
117
 
        submit(b, message=message, dry_run=dry_run,
118
 
               public_location=public_location,
119
 
               submit_location=submit_branch,
120
 
               tree=tree, ignore_local=ignore_local)
121
 
 
122
 
class cmd_lp_land(Command):
123
 
    """Land the merge proposal for this branch via PQM.
124
 
 
125
 
    The branch will be submitted to PQM according to the merge proposal.  If
126
 
    there is more than one one outstanding proposal for the branch, its
127
 
    location must be specified.
128
 
    """
129
 
 
130
 
    takes_args = ['location?']
131
 
 
132
 
    takes_options = [
133
 
        Option('dry-run', help='Display the PQM message instead of sending.'),
134
 
        Option(
135
 
            'testfix',
136
 
            help="This is a testfix (tags commit with [testfix])."),
137
 
        Option(
138
 
            'no-qa',
139
 
            help="Does not require QA (tags commit with [no-qa])."),
140
 
        Option(
141
 
            'incremental',
142
 
            help="Incremental to other bug fix (tags commit with [incr])."),
143
 
        Option(
144
 
            'rollback', type=int,
145
 
            help=(
146
 
                "Rollback given revision number. (tags commit with "
147
 
                "[rollback=revno]).")),
148
 
        ]
149
 
 
150
 
    def run(self, location=None, dry_run=False, testfix=False,
151
 
            no_qa=False, incremental=False, rollback=None):
152
 
        from bzrlib.plugins.pqm.lpland import Submitter
153
 
        from bzrlib.plugins.pqm.lpland import (
154
 
            MissingReviewError, MissingBugsError, MissingBugsIncrementalError)
155
 
 
156
 
        if dry_run:
157
 
            outf = self.outf
158
 
        else:
159
 
            outf = None
160
 
        if rollback and (no_qa or incremental):
161
 
            print "--rollback option used. Ignoring --no-qa and --incremental."
162
 
        try:
163
 
            submitter = Submitter.from_cmdline(
164
 
                location, testfix, no_qa, incremental,
165
 
                rollback=rollback).run(outf)
166
 
        except MissingReviewError:
167
 
            raise BzrCommandError(
168
 
                "Cannot land branches that haven't got approved code "
169
 
                "reviews. Get an 'Approved' vote so we can fill in the "
170
 
                "[r=REVIEWER] section.")
171
 
        except MissingBugsError:
172
 
            raise BzrCommandError(
173
 
                "Branch doesn't have linked bugs and doesn't have no-qa "
174
 
                "option set. Use --no-qa, or link the related bugs to the "
175
 
                "branch.")
176
 
        except MissingBugsIncrementalError:
177
 
            raise BzrCommandError(
178
 
                "--incremental option requires bugs linked to the branch. "
179
 
                "Link the bugs or remove the --incremental option.")
180
 
 
181
 
 
182
 
register_command(cmd_pqm_submit)
183
 
register_command(cmd_lp_land)
184
 
 
 
34
plugin_cmds.register_lazy("cmd_pqm_submit", [], 'bzrlib.plugins.pqm.cmds')
 
35
plugin_cmds.register_lazy("cmd_lp_land", [], 'bzrlib.plugins.pqm.cmds')
185
36
 
186
37
if bzrlib_version >= (2, 5):
187
38
    from bzrlib import config as _mod_config