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

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: James Henstridge
  • Date: 2008-04-03 09:23:19 UTC
  • Revision ID: james@jamesh.id.au-20080403092319-apc2zvonzt6eathe
Tags: 1.3.0
* Bump version number to 1.3.0 final.
* Update copyright headers on files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 by Canonical Ltd
 
1
# Copyright (C) 2005-2008 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
13
13
# You should have received a copy of the GNU General Public License along
14
14
# with this program; if not, write to the Free Software Foundation, Inc.,
15
15
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
 
"""Functionality for updating merge proposals for Tarmac submission.
 
16
"""Functionality for controlling a Patch Queue Manager (pqm).
17
17
"""
18
18
 
19
19
from bzrlib.commands import Command, register_command
20
20
from bzrlib.option import Option
21
 
from bzrlib.errors import BzrCommandError
22
 
 
23
 
 
24
 
version_info = (0, 0, 1, 'dev', 0)
 
21
 
 
22
from bzrlib.bzrdir import BzrDir
 
23
 
 
24
 
 
25
version_info = (1, 3, 0, 'final', 0)
25
26
 
26
27
if version_info[3] == 'final':
27
28
    version_string = '%d.%d.%d' % version_info[:3]
30
31
__version__ = version_string
31
32
 
32
33
 
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.
 
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.
39
69
    """
40
70
 
41
71
    takes_args = ['location?']
42
 
 
43
72
    takes_options = [
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]).")),
 
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.'),
59
83
        ]
60
84
 
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)
 
85
    def run(self, location=None, message=None, public_location=None,
 
86
            dry_run=False, submit_branch=None):
 
87
        from bzrlib import errors, trace
 
88
        if __name__ != 'bzrlib.plugins.pqm':
 
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 and location != '.':
 
100
            raise errors.BzrCommandError(
 
101
                'No working tree was found, but we were not given the '
 
102
                'exact path to the branch.\n'
 
103
                'We found a branch at: %s' % (b.base,))
 
104
        if message is None:
 
105
            raise errors.BzrCommandError(
 
106
                'You must supply a commit message for the pqm to use.')
 
107
        submit(b, message=message, dry_run=dry_run,
 
108
               public_location=public_location,
 
109
               submit_location=submit_branch,
 
110
               tree=tree)
 
111
 
 
112
 
 
113
register_command(cmd_pqm_submit)
96
114
 
97
115
 
98
116
def test_suite():
99
117
    from bzrlib.tests import TestLoader
100
 
    from unittest import TestSuite
101
 
 
102
 
    from tests import test_tarmac_land
 
118
    import test_pqm_submit
103
119
 
104
120
    loader = TestLoader()
105
 
    return TestSuite([
106
 
        loader.loadTestsFromModule(test_tarmac_land),
107
 
        ])
 
121
    return loader.loadTestsFromModule(test_pqm_submit)