/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
2898.3.8 by James Henstridge
Get rid of relative imports in Launchpad plugin.
17
"""Launchpad.net integration plugin for Bazaar."""
0.4.1 by Martin Pool
Start lp-register command
18
0.4.17 by Martin Pool
Allow xmlrpc service url to be overridden by $BZR_LP_XMLRPC_URL
19
# The XMLRPC server address can be overridden by setting the environment
20
# variable $BZR_LP_XMLRPL_URL
21
0.4.9 by Martin Pool
Don't transmit non-standard xmlrpc <nil> value.
22
# see http://bazaar-vcs.org/Specs/BranchRegistrationTool
23
0.4.1 by Martin Pool
Start lp-register command
24
from bzrlib.commands import Command, Option, register_command
2245.8.3 by Martin Pool
Start adding indirection transport
25
from bzrlib.transport import register_lazy_transport
2245.8.6 by Martin Pool
Documentation under 'help launchpad'
26
from bzrlib.help_topics import topic_registry
0.4.4 by Martin Pool
Start forming xmlrpc requests
27
28
0.4.2 by Martin Pool
Rename command to 'register-branch'
29
class cmd_register_branch(Command):
30
    """Register a branch with launchpad.net.
0.4.1 by Martin Pool
Start lp-register command
31
32
    This command lists a bzr branch in the directory of branches on
2400.2.4 by Robert Collins
(robertc) Typo in the help for ``register-branch`` fixed. (Robert Collins, #96770)
33
    launchpad.net.  Registration allows the branch to be associated with
0.4.1 by Martin Pool
Start lp-register command
34
    bugs or specifications.
35
    
0.4.15 by Martin Pool
(register-branch) Add command-line options
36
    Before using this command you must register the product to which the
0.4.1 by Martin Pool
Start lp-register command
37
    branch belongs, and create an account for yourself on launchpad.net.
0.4.3 by Martin Pool
More command line processing
38
39
    arguments:
40
        branch_url: The publicly visible url for the branch.
41
                    This must be an http or https url, not a local file
42
                    path.
43
44
    example:
0.4.15 by Martin Pool
(register-branch) Add command-line options
45
        bzr register-branch http://foo.com/bzr/fooproduct.mine \\
46
                --product fooproduct
0.4.1 by Martin Pool
Start lp-register command
47
    """
0.4.3 by Martin Pool
More command line processing
48
    takes_args = ['branch_url']
2598.1.1 by Martin Pool
Add test for and documentation of option style, fix up existing options to comply
49
    takes_options = [
50
         Option('product',
51
                'Launchpad product short name to associate with the branch.',
0.4.15 by Martin Pool
(register-branch) Add command-line options
52
                unicode),
53
         Option('branch-name',
2598.1.1 by Martin Pool
Add test for and documentation of option style, fix up existing options to comply
54
                'Short name for the branch; '
55
                'by default taken from the last component of the url.',
0.4.15 by Martin Pool
(register-branch) Add command-line options
56
                unicode),
57
         Option('branch-title',
2598.1.1 by Martin Pool
Add test for and documentation of option style, fix up existing options to comply
58
                'One-sentence description of the branch.',
0.4.15 by Martin Pool
(register-branch) Add command-line options
59
                unicode),
60
         Option('branch-description',
2598.1.5 by Martin Pool
Fix one more option message.
61
                'Longer description of the purpose or contents of the branch.',
0.4.15 by Martin Pool
(register-branch) Add command-line options
62
                unicode),
2598.1.1 by Martin Pool
Add test for and documentation of option style, fix up existing options to comply
63
         Option('author',
64
                "Branch author's email address, if not yourself.",
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
65
                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.
66
         Option('link-bug',
2598.1.1 by Martin Pool
Add test for and documentation of option style, fix up existing options to comply
67
                'The bug this branch fixes.',
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.
68
                int),
0.4.15 by Martin Pool
(register-branch) Add command-line options
69
         Option('dry-run',
2598.1.1 by Martin Pool
Add test for and documentation of option style, fix up existing options to comply
70
                'Prepare the request but don\'t actually send it.')
0.4.15 by Martin Pool
(register-branch) Add command-line options
71
        ]
72
73
74
    def run(self, 
75
            branch_url, 
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
76
            product='',
0.4.15 by Martin Pool
(register-branch) Add command-line options
77
            branch_name='',
78
            branch_title='',
79
            branch_description='',
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
80
            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.
81
            link_bug=None,
0.4.15 by Martin Pool
(register-branch) Add command-line options
82
            dry_run=False):
2898.3.8 by James Henstridge
Get rid of relative imports in Launchpad plugin.
83
        from bzrlib.plugins.launchpad.lp_registration import (
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
84
            LaunchpadService, BranchRegistrationRequest, BranchBugLinkRequest,
85
            DryRunLaunchpadService)
86
        rego = BranchRegistrationRequest(branch_url=branch_url,
0.4.15 by Martin Pool
(register-branch) Add command-line options
87
                                         branch_name=branch_name,
88
                                         branch_title=branch_title,
89
                                         branch_description=branch_description,
90
                                         product_name=product,
0.4.16 by Martin Pool
(register-branch) Add --author option and respect --dry-run
91
                                         author_email=author,
0.4.15 by Martin Pool
(register-branch) Add command-line options
92
                                         )
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.
93
        linko = BranchBugLinkRequest(branch_url=branch_url,
94
                                     bug_id=link_bug)
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
95
        if not dry_run:
96
            service = LaunchpadService()
97
            # This gives back the xmlrpc url that can be used for future
98
            # operations on the branch.  It's not so useful to print to the
99
            # user since they can't do anything with it from a web browser; it
100
            # might be nice for the server to tell us about an html url as
101
            # well.
102
        else:
103
            # Run on service entirely in memory
104
            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.
105
        service.gather_user_credentials()
1668.1.12 by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service.
106
        branch_object_url = rego.submit(service)
107
        if link_bug:
108
            link_bug_url = linko.submit(service)
109
        print 'Branch registered.'
0.4.1 by Martin Pool
Start lp-register command
110
0.4.2 by Martin Pool
Rename command to 'register-branch'
111
register_command(cmd_register_branch)
2245.8.4 by Martin Pool
lp:/// indirection works
112
2898.3.3 by James Henstridge
Add launchpad-login command.
113
114
class cmd_launchpad_login(Command):
2934.1.1 by Ian Clatworthy
(James Henstridge) add a command for managing the Launchpad user ID
115
    """Show or set the Launchpad user ID.
2898.3.3 by James Henstridge
Add launchpad-login command.
116
117
    When communicating with Launchpad, some commands need to know your
118
    Launchpad user ID.  This command can be used to set or show the
119
    user ID that Bazaar will use for such communication.
120
121
    :Examples:
122
      Show the Launchpad ID of the current user::
123
124
          bzr launchpad-login
125
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
126
      Set the Launchpad ID of the current user to 'bob'::
2898.3.3 by James Henstridge
Add launchpad-login command.
127
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
128
          bzr launchpad-login bob
2898.3.3 by James Henstridge
Add launchpad-login command.
129
    """
130
    aliases = ['lp-login']
131
    takes_args = ['name?']
132
    takes_options = [
2898.3.4 by James Henstridge
Cleanups from mini-review by Tim.
133
        Option('no-check',
134
               "Don't check that the user name is valid."),
2898.3.3 by James Henstridge
Add launchpad-login command.
135
        ]
136
2898.3.7 by James Henstridge
* Add tests for account.py exception messages.
137
    def run(self, name=None, no_check=False):
2898.3.8 by James Henstridge
Get rid of relative imports in Launchpad plugin.
138
        from bzrlib.plugins.launchpad import account
2898.3.3 by James Henstridge
Add launchpad-login command.
139
        check_account = not no_check
140
141
        if name is None:
142
            username = account.get_lp_login()
143
            if username:
2898.3.4 by James Henstridge
Cleanups from mini-review by Tim.
144
                if check_account:
145
                    account.check_lp_login(username)
2898.3.3 by James Henstridge
Add launchpad-login command.
146
                self.outf.write(username + '\n')
147
            else:
148
                self.outf.write('No Launchpad user ID configured.\n')
2898.3.9 by James Henstridge
* Add a simple NEWS item for the command.
149
                return 1
2898.3.3 by James Henstridge
Add launchpad-login command.
150
        else:
151
            if check_account:
152
                account.check_lp_login(name)
153
            account.set_lp_login(name)
154
155
register_command(cmd_launchpad_login)
156
157
2245.8.3 by Martin Pool
Start adding indirection transport
158
register_lazy_transport(
2245.8.5 by Martin Pool
Add short-form lp:PRODUCT url form
159
    'lp:',
160
    'bzrlib.plugins.launchpad.lp_indirect',
2898.4.8 by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets
161
    'LaunchpadTransport')
2245.8.5 by Martin Pool
Add short-form lp:PRODUCT url form
162
163
register_lazy_transport(
2245.8.3 by Martin Pool
Start adding indirection transport
164
    'lp://',
165
    'bzrlib.plugins.launchpad.lp_indirect',
2898.4.8 by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets
166
    'LaunchpadTransport')
0.4.1 by Martin Pool
Start lp-register command
167
168
def test_suite():
169
    """Called by bzrlib to fetch tests for this plugin"""
170
    from unittest import TestSuite, TestLoader
2898.3.8 by James Henstridge
Get rid of relative imports in Launchpad plugin.
171
    from bzrlib.plugins.launchpad import (
172
        test_register, test_lp_indirect, test_account)
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
173
174
    loader = TestLoader()
175
    suite = TestSuite()
2898.3.3 by James Henstridge
Add launchpad-login command.
176
    for m in [test_register, test_lp_indirect, test_account]:
2245.8.1 by Martin Pool
Start adding tests for launchpad indirection
177
        suite.addTests(loader.loadTestsFromModule(m))
178
    return suite
2245.8.6 by Martin Pool
Documentation under 'help launchpad'
179
180
_launchpad_help = """Integration with Launchpad.net
181
182
Launchpad.net provides free Bazaar branch hosting with integrated bug and
183
specification tracking.
184
3031.1.1 by jml at canonical
Expand the documentation on lp:// URLs and mention the launchpad-login command.
185
The bzr client (through the plugin called 'launchpad') has special
2245.8.6 by Martin Pool
Documentation under 'help launchpad'
186
features to communicate with Launchpad:
187
3031.1.1 by jml at canonical
Expand the documentation on lp:// URLs and mention the launchpad-login command.
188
    * The launchpad-login command tells Bazaar your Launchpad user name. This
189
      is then used by the 'lp:' transport to download your branches using
190
      bzr+ssh://.
191
192
    * The register-branch command tells Launchpad about the url of a
2245.8.6 by Martin Pool
Documentation under 'help launchpad'
193
      public branch.  Launchpad will then mirror the branch, display
3031.1.1 by jml at canonical
Expand the documentation on lp:// URLs and mention the launchpad-login command.
194
      its contents and allow it to be attached to bugs and other
2245.8.6 by Martin Pool
Documentation under 'help launchpad'
195
      objects.
196
3031.1.1 by jml at canonical
Expand the documentation on lp:// URLs and mention the launchpad-login command.
197
    * The 'lp:' transport uses Launchpad as a directory service: for example
198
      'lp:bzr' and 'lp:python' refer to the main branches of the relevant
199
      projects and may be branched, logged, etc. You can also use the 'lp:'
200
      transport to refer to specific branches, e.g. lp:///~bzr/bzr/trunk.
2245.8.6 by Martin Pool
Documentation under 'help launchpad'
201
202
For more information see http://help.launchpad.net/
203
"""
204
topic_registry.register('launchpad',
205
    _launchpad_help,
206
    'Using Bazaar with Launchpad.net')