~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 20:51:58 UTC
  • Revision ID: ursinha@canonical.com-20101216205158-ntcuh2mmgyde3azj
Fixed tests path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2008 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
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 controlling a Patch Queue Manager (pqm).
 
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
 
 
23
 
version_info = (1, 4, 0, 'dev', 0)
 
21
from bzrlib.errors import BzrCommandError
 
22
 
 
23
 
 
24
version_info = (0, 0, 1, 'dev', 0)
24
25
 
25
26
if version_info[3] == 'final':
26
27
    version_string = '%d.%d.%d' % version_info[:3]
29
30
__version__ = version_string
30
31
 
31
32
 
32
 
class cmd_pqm_submit(Command):
33
 
    """Submit the parent tree to the pqm.
34
 
 
35
 
    This acts like:
36
 
        $ echo "star-merge $PARENT $TARGET"
37
 
            | gpg --cl
38
 
            | mail pqm@somewhere -s "merge text"
39
 
 
40
 
    But it pays attention to who the local committer is
41
 
    (using their e-mail address), and uses the local
42
 
    gpg signing configuration. (As well as target pqm
43
 
    settings, etc.)
44
 
 
45
 
    The reason we use 'parent' instead of the local branch
46
 
    is that most likely the local branch is not a public
47
 
    branch. And the branch must be available to the pqm.
48
 
 
49
 
    This can be configured at the branch level using ~/.bazaar/locations.conf.
50
 
    Here is an example:
51
 
        [/home/emurphy/repo]
52
 
        pqm_email = PQM <pqm@example.com>
53
 
        pqm_user_email = User Name <user@example.com>
54
 
        submit_branch = http://code.example.com/code/project/devel
55
 
        # Set public_branch appropriately for all branches in repository:
56
 
        public_branch = http://code.example.com/code/emurphy/project
57
 
        public_branch:policy = appendpath
58
 
        [/home/emurphy/repo/branch]
59
 
        # Override public_branch for this repository:
60
 
        public_branch = http://alternate.host.example.com/other/public/branch
61
 
 
62
 
        smtp_server = host:port
63
 
        smtp_username =
64
 
        smtp_password =
65
 
 
66
 
    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.
67
39
    """
68
40
 
69
41
    takes_args = ['location?']
 
42
 
70
43
    takes_options = [
71
 
        Option('message',
72
 
               help='Message to use on merge to pqm.  '
73
 
                    'Currently must be a single line because of pqm limits.',
74
 
               short_name='m',
75
 
               type=unicode),
76
 
        Option('dry-run', help='Print request instead of sending.'),
77
 
        Option('public-location', type=str,
78
 
               help='Use this url as the public location to the pqm.'),
79
 
        Option('submit-branch', type=str,
80
 
               help='Use this url as the target submission branch.'),
81
 
        Option('ignore-local', help='Do not check the local branch or tree.'),
 
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]).")),
82
59
        ]
83
60
 
84
 
    def run(self, location=None, message=None, public_location=None,
85
 
            dry_run=False, submit_branch=None, ignore_local=False):
86
 
        from bzrlib import errors, trace, bzrdir
87
 
        if __name__ != 'bzrlib.plugins.pqm':
88
 
            trace.warning('The bzr-pqm plugin needs to be called'
89
 
                          ' "bzrlib.plugins.pqm" not "%s"\n'
90
 
                          'Please rename the plugin.',
91
 
                          __name__)
92
 
            return 1
93
 
        from bzrlib.plugins.pqm.pqm_submit import 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)
94
67
 
95
 
        if ignore_local:
96
 
            tree, b, relpath = None, None, None
 
68
        if dry_run:
 
69
            outf = self.outf
97
70
        else:
98
 
            if location is None:
99
 
                location = '.'
100
 
            tree, b, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
101
 
                location)
102
 
        if relpath and not tree and location != '.':
103
 
            raise errors.BzrCommandError(
104
 
                'No working tree was found, but we were not given the '
105
 
                'exact path to the branch.\n'
106
 
                'We found a branch at: %s' % (b.base,))
107
 
        if message is None:
108
 
            raise errors.BzrCommandError(
109
 
                'You must supply a commit message for the pqm to use.')
110
 
        submit(b, message=message, dry_run=dry_run,
111
 
               public_location=public_location,
112
 
               submit_location=submit_branch,
113
 
               tree=tree, ignore_local=ignore_local)
114
 
 
115
 
 
116
 
register_command(cmd_pqm_submit)
 
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)
117
96
 
118
97
 
119
98
def test_suite():
120
99
    from bzrlib.tests import TestLoader
121
 
    import test_pqm_submit
 
100
    from unittest import TestSuite
 
101
 
 
102
    from tests import test_tarmac_land
122
103
 
123
104
    loader = TestLoader()
124
 
    return loader.loadTestsFromModule(test_pqm_submit)
 
105
    return TestSuite([
 
106
        loader.loadTestsFromModule(test_tarmac_land),
 
107
        ])