14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Launchpad.net branch registration plugin for bzr
19
This adds commands that tell launchpad about newly-created branches, etc.
21
To install this file, put the 'bzr_lp' directory, or a symlink to it,
22
in your ~/.bazaar/plugins/ directory.
17
"""Launchpad.net integration plugin for Bazaar."""
25
19
# The XMLRPC server address can be overridden by setting the environment
26
20
# variable $BZR_LP_XMLRPL_URL
28
22
# see http://bazaar-vcs.org/Specs/BranchRegistrationTool
24
from bzrlib.branch import Branch
30
25
from bzrlib.commands import Command, Option, register_command
26
from bzrlib.directory_service import directories
27
from bzrlib.errors import BzrCommandError, NoPublicBranch, NotBranchError
28
from bzrlib.help_topics import topic_registry
34
31
class cmd_register_branch(Command):
35
32
"""Register a branch with launchpad.net.
37
34
This command lists a bzr branch in the directory of branches on
38
launchpad.net. Registration allows the bug to be associated with
35
launchpad.net. Registration allows the branch to be associated with
39
36
bugs or specifications.
41
38
Before using this command you must register the product to which the
42
39
branch belongs, and create an account for yourself on launchpad.net.
45
branch_url: The publicly visible url for the branch.
46
This must be an http or https url, not a local file
42
public_url: The publicly visible url for the branch to register.
43
This must be an http or https url (which Launchpad can read
44
from to access the branch). Local file urls, SFTP urls, and
45
bzr+ssh urls will not work.
46
If no public_url is provided, bzr will use the configured
47
public_url if there is one for the current branch, and
50
51
bzr register-branch http://foo.com/bzr/fooproduct.mine \\
51
52
--product fooproduct
53
takes_args = ['branch_url']
56
'launchpad product short name to associate with the branch',
54
takes_args = ['public_url?']
57
'Launchpad product short name to associate with the branch.',
58
59
Option('branch-name',
59
'short name for the branch; '
60
'by default taken from the last component of the url',
60
'Short name for the branch; '
61
'by default taken from the last component of the url.',
62
63
Option('branch-title',
63
'one-sentence description of the branch',
64
'One-sentence description of the branch.',
65
66
Option('branch-description',
66
'longer description of the purpose or contents of the branch',
67
'Longer description of the purpose or contents of the branch.',
69
'email of the branch\'s author, if not yourself',
70
"Branch author's email address, if not yourself.",
72
'the bug this branch fixes',
73
'The bug this branch fixes.',
75
'prepare the request but don\'t actually send it')
76
'Prepare the request but don\'t actually send it.')
88
from lp_registration import (
89
from bzrlib.plugins.launchpad.lp_registration import (
89
90
LaunchpadService, BranchRegistrationRequest, BranchBugLinkRequest,
90
91
DryRunLaunchpadService)
91
rego = BranchRegistrationRequest(branch_url=branch_url,
92
if public_url is None:
94
b = Branch.open_containing('.')[0]
95
except NotBranchError:
96
raise BzrCommandError('register-branch requires a public '
97
'branch url - see bzr help register-branch.')
98
public_url = b.get_public_branch()
99
if public_url is None:
100
raise NoPublicBranch(b)
102
rego = BranchRegistrationRequest(branch_url=public_url,
92
103
branch_name=branch_name,
93
104
branch_title=branch_title,
94
105
branch_description=branch_description,
95
106
product_name=product,
96
107
author_email=author,
98
linko = BranchBugLinkRequest(branch_url=branch_url,
109
linko = BranchBugLinkRequest(branch_url=public_url,
101
112
service = LaunchpadService()
116
127
register_command(cmd_register_branch)
130
class cmd_launchpad_login(Command):
131
"""Show or set the Launchpad user ID.
133
When communicating with Launchpad, some commands need to know your
134
Launchpad user ID. This command can be used to set or show the
135
user ID that Bazaar will use for such communication.
138
Show the Launchpad ID of the current user::
142
Set the Launchpad ID of the current user to 'bob'::
144
bzr launchpad-login bob
146
aliases = ['lp-login']
147
takes_args = ['name?']
150
"Don't check that the user name is valid."),
153
def run(self, name=None, no_check=False):
154
from bzrlib.plugins.launchpad import account
155
check_account = not no_check
158
username = account.get_lp_login()
161
account.check_lp_login(username)
162
self.outf.write(username + '\n')
164
self.outf.write('No Launchpad user ID configured.\n')
168
account.check_lp_login(name)
169
account.set_lp_login(name)
171
register_command(cmd_launchpad_login)
174
def _register_directory():
175
directories.register_lazy('lp:', 'bzrlib.plugins.launchpad.lp_directory',
176
'LaunchpadDirectory',
177
'Launchpad-based directory service',)
178
_register_directory()
118
181
def test_suite():
119
182
"""Called by bzrlib to fetch tests for this plugin"""
120
183
from unittest import TestSuite, TestLoader
122
return TestLoader().loadTestsFromModule(test_register)
184
from bzrlib.plugins.launchpad import (
185
test_account, test_lp_directory, test_lp_service, test_register,
188
loader = TestLoader()
196
suite.addTests(loader.loadTestsFromModule(module))
199
_launchpad_help = """Integration with Launchpad.net
201
Launchpad.net provides free Bazaar branch hosting with integrated bug and
202
specification tracking.
204
The bzr client (through the plugin called 'launchpad') has special
205
features to communicate with Launchpad:
207
* The launchpad-login command tells Bazaar your Launchpad user name. This
208
is then used by the 'lp:' transport to download your branches using
211
* The register-branch command tells Launchpad about the url of a
212
public branch. Launchpad will then mirror the branch, display
213
its contents and allow it to be attached to bugs and other
216
* The 'lp:' transport uses Launchpad as a directory service: for example
217
'lp:bzr' and 'lp:python' refer to the main branches of the relevant
218
projects and may be branched, logged, etc. You can also use the 'lp:'
219
transport to refer to specific branches, e.g. lp:///~bzr/bzr/trunk.
221
For more information see http://help.launchpad.net/
223
topic_registry.register('launchpad',
225
'Using Bazaar with Launchpad.net')