~bzr-pqm/bzr/bzr.dev

2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
1
# Copyright (C) 2006, 2007 Canonical Ltd
0.4.1 by Martin Pool
Start lp-register command
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
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
2245.8.3 by Martin Pool
Start adding indirection transport
17
"""Launchpad.net integration plugin for Bazaar
18
0.4.1 by Martin Pool
Start lp-register command
19
To install this file, put the 'bzr_lp' directory, or a symlink to it,
20
in your ~/.bazaar/plugins/ directory.
21
"""
22
0.4.17 by Martin Pool
Allow xmlrpc service url to be overridden by $BZR_LP_XMLRPC_URL
23
# The XMLRPC server address can be overridden by setting the environment
24
# variable $BZR_LP_XMLRPL_URL
25
0.4.9 by Martin Pool
Don't transmit non-standard xmlrpc <nil> value.
26
# see http://bazaar-vcs.org/Specs/BranchRegistrationTool
27
0.4.1 by Martin Pool
Start lp-register command
28
from bzrlib.commands import Command, Option, register_command
2245.8.3 by Martin Pool
Start adding indirection transport
29
from bzrlib.transport import register_lazy_transport
2245.8.6 by Martin Pool
Documentation under 'help launchpad'
30
from bzrlib.help_topics import topic_registry
0.4.4 by Martin Pool
Start forming xmlrpc requests
31
32
0.4.2 by Martin Pool
Rename command to 'register-branch'
33
class cmd_register_branch(Command):
34
    """Register a branch with launchpad.net.
0.4.1 by Martin Pool
Start lp-register command
35
36
    This command lists a bzr branch in the directory of branches on
37
    launchpad.net.  Registration allows the bug to be associated with
38
    bugs or specifications.
39
    
0.4.15 by Martin Pool
(register-branch) Add command-line options
40
    Before using this command you must register the product to which the
0.4.1 by Martin Pool
Start lp-register command
41
    branch belongs, and create an account for yourself on launchpad.net.
0.4.3 by Martin Pool
More command line processing
42
43
    arguments:
44
        branch_url: The publicly visible url for the branch.
45
                    This must be an http or https url, not a local file
46
                    path.
47
48
    example:
0.4.15 by Martin Pool
(register-branch) Add command-line options
49
        bzr register-branch http://foo.com/bzr/fooproduct.mine \\
50
                --product fooproduct
0.4.1 by Martin Pool
Start lp-register command
51
    """
0.4.3 by Martin Pool
More command line processing
52
    takes_args = ['branch_url']
0.4.15 by Martin Pool
(register-branch) Add command-line options
53
    takes_options = \
54
        [Option('product', 
55
                'launchpad product short name to associate with the branch',
56
                unicode),
57
         Option('branch-name',
58
                'short name for the branch; '
59
                'by default taken from the last component of the url',
60
                unicode),
61
         Option('branch-title',
62
                'one-sentence description of the branch',
63
                unicode),
64
         Option('branch-description',
65
                'longer description of the purpose or contents of the branch',
66
                unicode),
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
67
         Option('author', 
68
                'email of the branch\'s author, if not yourself',
69
                unicode),
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
70
         Option('link-bug',
71
                'the bug this branch fixes',
72
                int),
0.4.15 by Martin Pool
(register-branch) Add command-line options
73
         Option('dry-run',
74
                'prepare the request but don\'t actually send it')
75
        ]
76
77
78
    def run(self, 
79
            branch_url, 
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
80
            product='',
0.4.15 by Martin Pool
(register-branch) Add command-line options
81
            branch_name='',
82
            branch_title='',
83
            branch_description='',
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
84
            author='',
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
85
            link_bug=None,
0.4.15 by Martin Pool
(register-branch) Add command-line options
86
            dry_run=False):
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
87
        from lp_registration import (
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
88
            LaunchpadService, BranchRegistrationRequest, BranchBugLinkRequest,
89
            DryRunLaunchpadService)
90
        rego = BranchRegistrationRequest(branch_url=branch_url,
0.4.15 by Martin Pool
(register-branch) Add command-line options
91
                                         branch_name=branch_name,
92
                                         branch_title=branch_title,
93
                                         branch_description=branch_description,
94
                                         product_name=product,
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
95
                                         author_email=author,
0.4.15 by Martin Pool
(register-branch) Add command-line options
96
                                         )
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
97
        linko = BranchBugLinkRequest(branch_url=branch_url,
98
                                     bug_id=link_bug)
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
99
        if not dry_run:
100
            service = LaunchpadService()
101
            # This gives back the xmlrpc url that can be used for future
102
            # operations on the branch.  It's not so useful to print to the
103
            # user since they can't do anything with it from a web browser; it
104
            # might be nice for the server to tell us about an html url as
105
            # well.
106
        else:
107
            # Run on service entirely in memory
108
            service = DryRunLaunchpadService()
0.4.19 by test at canonical
add possibility to link to a bug when registering a branch. factor out some common functionality from BranchRegistrationRequest.
109
        service.gather_user_credentials()
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
110
        branch_object_url = rego.submit(service)
111
        if link_bug:
112
            link_bug_url = linko.submit(service)
113
        print 'Branch registered.'
0.4.1 by Martin Pool
Start lp-register command
114
0.4.2 by Martin Pool
Rename command to 'register-branch'
115
register_command(cmd_register_branch)
2245.8.4 by Martin Pool
lp:/// indirection works
116
2245.8.3 by Martin Pool
Start adding indirection transport
117
register_lazy_transport(
2245.8.5 by Martin Pool
Add short-form lp:PRODUCT url form
118
    'lp:',
119
    'bzrlib.plugins.launchpad.lp_indirect',
120
    'launchpad_transport_indirect')
121
122
register_lazy_transport(
2245.8.3 by Martin Pool
Start adding indirection transport
123
    'lp://',
124
    'bzrlib.plugins.launchpad.lp_indirect',
2245.8.4 by Martin Pool
lp:/// indirection works
125
    'launchpad_transport_indirect')
0.4.1 by Martin Pool
Start lp-register command
126
127
def test_suite():
128
    """Called by bzrlib to fetch tests for this plugin"""
129
    from unittest import TestSuite, TestLoader
130
    import test_register
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
131
    import test_lp_indirect
132
133
    loader = TestLoader()
134
    suite = TestSuite()
135
    for m in [test_register, test_lp_indirect]:
136
        suite.addTests(loader.loadTestsFromModule(m))
137
    return suite
2245.8.6 by Martin Pool
Documentation under 'help launchpad'
138
139
_launchpad_help = """Integration with Launchpad.net
140
141
Launchpad.net provides free Bazaar branch hosting with integrated bug and
142
specification tracking.
143
144
The bzr client (through the plugin called 'launchpad') has two special
145
features to communicate with Launchpad:
146
147
    * The register-branch command tells launchpad about the url of a 
148
      public branch.  Launchpad will then mirror the branch, display
149
      its contents and allow it to be attached to bugs and other 
150
      objects.
151
152
    * The 'lp:' transport uses Launchpad as a directory service: 
153
      for example 'lp:bzr' and 'lp:python' refer to the main branches of the
154
      relevant projects and may be branched, logged, etc.  (Only read access
155
      is supported at present.)
156
157
For more information see http://help.launchpad.net/
158
"""
159
topic_registry.register('launchpad',
160
    _launchpad_help,
161
    'Using Bazaar with Launchpad.net')