~ursinha/lp-qa-tools/bzr-tarmacland

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Ursula Junque (Ursinha)
  • Date: 2010-12-16 13:57:20 UTC
  • Revision ID: ursinha@canonical.com-20101216135720-gdo31w7hqirijyu8
removing cruft

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 by Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
12
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
"""Functionality for controlling a Patch Queue Manager (pqm).
 
13
# You should have received a copy of the GNU General Public License along
 
14
# with this program; if not, write to the Free Software Foundation, Inc.,
 
15
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
16
"""Functionality for updating merge proposals for Tarmac submission.
17
17
"""
18
18
 
19
19
from bzrlib.commands import Command, register_command
20
20
from bzrlib.option import Option
21
 
 
22
 
from bzrlib.bzrdir import BzrDir
23
 
 
24
 
 
25
 
version_info = (1, 0, 0, 'dev', 0)
 
21
from bzrlib.errors import BzrCommandError
 
22
 
 
23
 
 
24
version_info = (0, 0, 1, 'dev', 0)
26
25
 
27
26
if version_info[3] == 'final':
28
27
    version_string = '%d.%d.%d' % version_info[:3]
29
28
else:
30
 
    version_string = '%d.%d.%d.%s.%d' % version_info
 
29
    version_string = '%d.%d.%d%s%d' % version_info
31
30
__version__ = version_string
32
31
 
33
32
 
34
 
class cmd_pqm_submit(Command):
35
 
    """Submit the parent tree to the pqm.
36
 
 
37
 
    This acts like:
38
 
        $ echo "star-merge $PARENT $TARGET"
39
 
            | gpg --cl
40
 
            | mail pqm@somewhere -s "merge text"
41
 
 
42
 
    But it pays attention to who the local committer is
43
 
    (using their e-mail address), and uses the local
44
 
    gpg signing configuration. (As well as target pqm
45
 
    settings, etc.)
46
 
 
47
 
    The reason we use 'parent' instead of the local branch
48
 
    is that most likely the local branch is not a public
49
 
    branch. And the branch must be available to the pqm.
50
 
 
51
 
    This can be configured at the branch level using ~/.bazaar/locations.conf.
52
 
    Here is an example:
53
 
        [/home/emurphy/repo]
54
 
        pqm_email = PQM <pqm@example.com>
55
 
        pqm_user_email = User Name <user@example.com>
56
 
        submit_branch = http://code.example.com/code/project/devel
57
 
        # Set public_branch appropriately for all branches in repository:
58
 
        public_branch = http://code.example.com/code/emurphy/project
59
 
        public_branch:policy = appendpath
60
 
        [/home/emurphy/repo/branch]
61
 
        # Override public_branch for this repository:
62
 
        public_branch = http://alternate.host.example.com/other/public/branch
63
 
 
64
 
        smtp_server = host:port
65
 
        smtp_username =
66
 
        smtp_password =
67
 
 
68
 
    If you don't specify the smtp server, the message will be sent via localhost.
 
33
class cmd_tarmac_land(Command):
 
34
    """Set the Merge Proposal to be processed by Tarmac.
 
35
 
 
36
    The branch will be handled by Tarmac according to the merge proposal.  If
 
37
    there is more than one one outstanding proposal for the branch, its
 
38
    location must be specified.
69
39
    """
70
40
 
71
41
    takes_args = ['location?']
 
42
 
72
43
    takes_options = [
73
 
        Option('message',
74
 
               help='Message to use on merge to pqm.  '
75
 
                    'Currently must be a single line because of pqm limits.',
76
 
               short_name='m',
77
 
               type=unicode),
78
 
        Option('dry-run', help='Print request instead of sending.'),
79
 
        Option('public-location', type=str,
80
 
               help='Use this url as the public location to the pqm.'),
81
 
        Option('submit-branch', type=str,
82
 
               help='Use this url as the target submission branch.'),
 
44
        Option('dry-run', help='Display the commit message instead of sending.'),
 
45
        Option(
 
46
            'testfix',
 
47
            help="This is a testfix (tags commit with [testfix])."),
 
48
        Option(
 
49
            'no-qa',
 
50
            help="Does not require QA (tags commit with [no-qa])."),
 
51
        Option(
 
52
            'incremental',
 
53
            help="Incremental to other bug fix (tags commit with [incr])."),
 
54
        Option(
 
55
            'rollback', type=int,
 
56
            help=(
 
57
                "Rollback given revision number. (tags commit with "
 
58
                "[rollback=revno]).")),
83
59
        ]
84
60
 
85
 
    def run(self, location=None, message=None, public_location=None,
86
 
            dry_run=False, submit_branch=None):
87
 
        if __name__ != 'bzrlib.plugins.pqm':
88
 
            from bzrlib import trace
89
 
            trace.warning('The bzr-pqm plugin needs to be called'
90
 
                          ' "bzrlib.plugins.pqm" not "%s"\n'
91
 
                          'Please rename the plugin.',
92
 
                          __name__)
93
 
            return 1
94
 
        from bzrlib.plugins.pqm.pqm_submit import submit
95
 
 
96
 
        if location is None:
97
 
            location = '.'
98
 
        tree, b, relpath = BzrDir.open_containing_tree_or_branch(location)
99
 
        if relpath and not tree:
100
 
            from bzrlib import errors
101
 
            raise errors.BzrCommandError('No working tree was found, but we'
102
 
                                          ' were not given the exact path to'
103
 
                                          ' the branch.\n'
104
 
                                          ' We found the branch at: %s'
105
 
                                          % (b.base,))
106
 
        submit(b, message=message, dry_run=dry_run,
107
 
               public_location=public_location,
108
 
               submit_location=submit_branch,
109
 
               tree=tree)
110
 
 
111
 
 
112
 
register_command(cmd_pqm_submit)
 
61
    def run(self, location=None, dry_run=False, testfix=False,
 
62
            no_qa=False, incremental=False, rollback=None):
 
63
        from bzrlib.plugins.tarmac_land.tarmac_land import Submitter
 
64
        from bzrlib import branch as _mod_branch
 
65
        from bzrlib.plugins.tarmac_land.tarmac_land import (
 
66
            MissingReviewError, MissingBugsError, MissingBugsIncrementalError)
 
67
 
 
68
        if dry_run:
 
69
            outf = self.outf
 
70
        else:
 
71
            outf = None
 
72
 
 
73
        branch = _mod_branch.Branch.open_containing('.')[0]
 
74
        if rollback and (no_qa or incremental):
 
75
            print "--rollback option used. Ignoring --no-qa and --incremental."
 
76
        try:
 
77
            submitter = Submitter(branch, location, testfix, no_qa,
 
78
                incremental, rollback=rollback).run(outf)
 
79
        except MissingReviewError:
 
80
            raise BzrCommandError(
 
81
                "Cannot land branches that haven't got approved code "
 
82
                "reviews. Get an 'Approved' vote so we can fill in the "
 
83
                "[r=REVIEWER] section.")
 
84
        except MissingBugsError:
 
85
            raise BzrCommandError(
 
86
                "Branch doesn't have linked bugs and doesn't have no-qa "
 
87
                "option set. Use --no-qa, or link the related bugs to the "
 
88
                "branch.")
 
89
        except MissingBugsIncrementalError:
 
90
            raise BzrCommandError(
 
91
                "--incremental option requires bugs linked to the branch. "
 
92
                "Link the bugs or remove the --incremental option.")
 
93
 
 
94
 
 
95
register_command(cmd_tarmac_land)
113
96
 
114
97
 
115
98
def test_suite():
116
99
    from bzrlib.tests import TestLoader
117
 
    import test_pqm_submit
 
100
    from unittest import TestSuite
 
101
 
 
102
    from tests import test_tarmac_land
118
103
 
119
104
    loader = TestLoader()
120
 
    return loader.loadTestsFromModule(test_pqm_submit)
 
105
    return TestSuite([
 
106
        loader.loadTestsFromModule(test_tarmac_land),
 
107
        ])