bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3251.4.2
by Aaron Bentley
Clean up Launchpad directory service code |
1 |
# Copyright (C) 2006 - 2008 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
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
0.4.1
by Martin Pool
Start lp-register command |
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 |
||
|
4031.2.11
by John Arbash Meinel
Turn a bunch of imports into lazy imports. |
24 |
from bzrlib.lazy_import import lazy_import |
25 |
lazy_import(globals(), """ |
|
|
4031.2.7
by Jonathan Lange
Move the imports to the top of the module. |
26 |
import webbrowser
|
27 |
||
|
4031.2.11
by John Arbash Meinel
Turn a bunch of imports into lazy imports. |
28 |
from bzrlib import (
|
29 |
branch as _mod_branch,
|
|
30 |
trace,
|
|
31 |
)
|
|
32 |
""") |
|
33 |
||
|
0.4.1
by Martin Pool
Start lp-register command |
34 |
from bzrlib.commands import Command, Option, register_command |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
35 |
from bzrlib.directory_service import directories |
|
4031.2.5
by Jonathan Lange
Refactor the code so we don't do too many remote requests. |
36 |
from bzrlib.errors import ( |
37 |
BzrCommandError, |
|
38 |
InvalidURL, |
|
39 |
NoPublicBranch, |
|
40 |
NotBranchError, |
|
41 |
)
|
|
|
2245.8.6
by Martin Pool
Documentation under 'help launchpad' |
42 |
from bzrlib.help_topics import topic_registry |
|
4031.2.7
by Jonathan Lange
Move the imports to the top of the module. |
43 |
from bzrlib.plugins.launchpad.lp_registration import ( |
44 |
LaunchpadService, |
|
45 |
NotLaunchpadBranch, |
|
46 |
)
|
|
|
0.4.4
by Martin Pool
Start forming xmlrpc requests |
47 |
|
48 |
||
|
0.4.2
by Martin Pool
Rename command to 'register-branch' |
49 |
class cmd_register_branch(Command): |
50 |
"""Register a branch with launchpad.net. |
|
|
0.4.1
by Martin Pool
Start lp-register command |
51 |
|
52 |
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) |
53 |
launchpad.net. Registration allows the branch to be associated with
|
|
0.4.1
by Martin Pool
Start lp-register command |
54 |
bugs or specifications.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
55 |
|
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
56 |
Before using this command you must register the product to which the
|
|
0.4.1
by Martin Pool
Start lp-register command |
57 |
branch belongs, and create an account for yourself on launchpad.net.
|
|
0.4.3
by Martin Pool
More command line processing |
58 |
|
59 |
arguments:
|
|
|
3200.2.3
by Robert Collins
Tweak wording. |
60 |
public_url: The publicly visible url for the branch to register.
|
|
3200.2.1
by Robert Collins
* The ``register-branch`` command will now use the public url of the branch |
61 |
This must be an http or https url (which Launchpad can read
|
62 |
from to access the branch). Local file urls, SFTP urls, and
|
|
63 |
bzr+ssh urls will not work.
|
|
64 |
If no public_url is provided, bzr will use the configured
|
|
|
3200.2.3
by Robert Collins
Tweak wording. |
65 |
public_url if there is one for the current branch, and
|
66 |
otherwise error.
|
|
|
0.4.3
by Martin Pool
More command line processing |
67 |
|
68 |
example:
|
|
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
69 |
bzr register-branch http://foo.com/bzr/fooproduct.mine \\
|
70 |
--product fooproduct
|
|
|
0.4.1
by Martin Pool
Start lp-register command |
71 |
"""
|
|
3200.2.1
by Robert Collins
* The ``register-branch`` command will now use the public url of the branch |
72 |
takes_args = ['public_url?'] |
|
2598.1.1
by Martin Pool
Add test for and documentation of option style, fix up existing options to comply |
73 |
takes_options = [ |
74 |
Option('product', |
|
75 |
'Launchpad product short name to associate with the branch.', |
|
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
76 |
unicode), |
77 |
Option('branch-name', |
|
|
2598.1.1
by Martin Pool
Add test for and documentation of option style, fix up existing options to comply |
78 |
'Short name for the branch; '
|
79 |
'by default taken from the last component of the url.', |
|
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
80 |
unicode), |
81 |
Option('branch-title', |
|
|
2598.1.1
by Martin Pool
Add test for and documentation of option style, fix up existing options to comply |
82 |
'One-sentence description of the branch.', |
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
83 |
unicode), |
84 |
Option('branch-description', |
|
|
2598.1.5
by Martin Pool
Fix one more option message. |
85 |
'Longer description of the purpose or contents of the branch.', |
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
86 |
unicode), |
|
2598.1.1
by Martin Pool
Add test for and documentation of option style, fix up existing options to comply |
87 |
Option('author', |
88 |
"Branch author's email address, if not yourself.", |
|
|
0.4.16
by Martin Pool
(register-branch) Add --author option and respect --dry-run |
89 |
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. |
90 |
Option('link-bug', |
|
2598.1.1
by Martin Pool
Add test for and documentation of option style, fix up existing options to comply |
91 |
'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. |
92 |
int), |
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
93 |
Option('dry-run', |
|
2598.1.1
by Martin Pool
Add test for and documentation of option style, fix up existing options to comply |
94 |
'Prepare the request but don\'t actually send it.') |
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
95 |
]
|
96 |
||
97 |
||
|
3200.2.1
by Robert Collins
* The ``register-branch`` command will now use the public url of the branch |
98 |
def run(self, |
99 |
public_url=None, |
|
|
1668.1.12
by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service. |
100 |
product='', |
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
101 |
branch_name='', |
102 |
branch_title='', |
|
103 |
branch_description='', |
|
|
0.4.16
by Martin Pool
(register-branch) Add --author option and respect --dry-run |
104 |
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. |
105 |
link_bug=None, |
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
106 |
dry_run=False): |
|
2898.3.8
by James Henstridge
Get rid of relative imports in Launchpad plugin. |
107 |
from bzrlib.plugins.launchpad.lp_registration import ( |
|
1668.1.12
by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service. |
108 |
LaunchpadService, BranchRegistrationRequest, BranchBugLinkRequest, |
109 |
DryRunLaunchpadService) |
|
|
3200.2.1
by Robert Collins
* The ``register-branch`` command will now use the public url of the branch |
110 |
if public_url is None: |
111 |
try: |
|
|
4031.2.11
by John Arbash Meinel
Turn a bunch of imports into lazy imports. |
112 |
b = _mod_branch.Branch.open_containing('.')[0] |
|
3200.2.1
by Robert Collins
* The ``register-branch`` command will now use the public url of the branch |
113 |
except NotBranchError: |
114 |
raise BzrCommandError('register-branch requires a public ' |
|
115 |
'branch url - see bzr help register-branch.') |
|
116 |
public_url = b.get_public_branch() |
|
117 |
if public_url is None: |
|
118 |
raise NoPublicBranch(b) |
|
119 |
||
120 |
rego = BranchRegistrationRequest(branch_url=public_url, |
|
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
121 |
branch_name=branch_name, |
122 |
branch_title=branch_title, |
|
123 |
branch_description=branch_description, |
|
124 |
product_name=product, |
|
|
0.4.16
by Martin Pool
(register-branch) Add --author option and respect --dry-run |
125 |
author_email=author, |
|
0.4.15
by Martin Pool
(register-branch) Add command-line options |
126 |
)
|
|
3200.2.1
by Robert Collins
* The ``register-branch`` command will now use the public url of the branch |
127 |
linko = BranchBugLinkRequest(branch_url=public_url, |
|
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. |
128 |
bug_id=link_bug) |
|
1668.1.12
by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service. |
129 |
if not dry_run: |
130 |
service = LaunchpadService() |
|
131 |
# This gives back the xmlrpc url that can be used for future
|
|
132 |
# operations on the branch. It's not so useful to print to the
|
|
133 |
# user since they can't do anything with it from a web browser; it
|
|
134 |
# might be nice for the server to tell us about an html url as
|
|
135 |
# well.
|
|
136 |
else: |
|
137 |
# Run on service entirely in memory
|
|
138 |
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. |
139 |
service.gather_user_credentials() |
|
1668.1.12
by Martin Pool
(launchpad plugin) Improved --dry-run that uses a dummy xmlrpc service. |
140 |
branch_object_url = rego.submit(service) |
141 |
if link_bug: |
|
142 |
link_bug_url = linko.submit(service) |
|
143 |
print 'Branch registered.' |
|
|
0.4.1
by Martin Pool
Start lp-register command |
144 |
|
|
0.4.2
by Martin Pool
Rename command to 'register-branch' |
145 |
register_command(cmd_register_branch) |
|
2245.8.4
by Martin Pool
lp:/// indirection works |
146 |
|
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
147 |
|
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
148 |
class cmd_launchpad_open(Command): |
149 |
"""Open a Launchpad branch page in your web browser.""" |
|
150 |
||
151 |
aliases = ['lp-open'] |
|
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
152 |
takes_options = [ |
153 |
Option('dry-run', |
|
154 |
'Do not actually open the browser. Just say the URL we would '
|
|
155 |
'use.'), |
|
156 |
]
|
|
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
157 |
takes_args = ['location?'] |
158 |
||
|
4031.2.5
by Jonathan Lange
Refactor the code so we don't do too many remote requests. |
159 |
def _possible_locations(self, location): |
160 |
"""Yield possible external locations for the branch at 'location'.""" |
|
161 |
yield location |
|
162 |
try: |
|
|
4031.2.11
by John Arbash Meinel
Turn a bunch of imports into lazy imports. |
163 |
branch = _mod_branch.Branch.open(location) |
|
4031.2.5
by Jonathan Lange
Refactor the code so we don't do too many remote requests. |
164 |
except NotBranchError: |
165 |
return
|
|
166 |
branch_url = branch.get_public_branch() |
|
167 |
if branch_url is not None: |
|
168 |
yield branch_url |
|
169 |
branch_url = branch.get_push_location() |
|
170 |
if branch_url is not None: |
|
171 |
yield branch_url |
|
172 |
||
173 |
def _get_web_url(self, service, location): |
|
174 |
for branch_url in self._possible_locations(location): |
|
175 |
try: |
|
176 |
return service.get_web_url_from_branch_url(branch_url) |
|
177 |
except (NotLaunchpadBranch, InvalidURL): |
|
178 |
pass
|
|
179 |
raise NotLaunchpadBranch(branch_url) |
|
180 |
||
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
181 |
def run(self, location=None, dry_run=False): |
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
182 |
if location is None: |
183 |
location = u'.' |
|
|
4031.2.5
by Jonathan Lange
Refactor the code so we don't do too many remote requests. |
184 |
web_url = self._get_web_url(LaunchpadService(), location) |
|
4031.2.11
by John Arbash Meinel
Turn a bunch of imports into lazy imports. |
185 |
trace.note('Opening %s in web browser' % web_url) |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
186 |
if not dry_run: |
187 |
webbrowser.open(web_url) |
|
|
3955.3.5
by Jonathan Lange
Add an untested plugin, make the error handling a little nicer. |
188 |
|
189 |
register_command(cmd_launchpad_open) |
|
190 |
||
191 |
||
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
192 |
class cmd_launchpad_login(Command): |
|
2934.1.1
by Ian Clatworthy
(James Henstridge) add a command for managing the Launchpad user ID |
193 |
"""Show or set the Launchpad user ID. |
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
194 |
|
195 |
When communicating with Launchpad, some commands need to know your
|
|
196 |
Launchpad user ID. This command can be used to set or show the
|
|
197 |
user ID that Bazaar will use for such communication.
|
|
198 |
||
199 |
:Examples:
|
|
200 |
Show the Launchpad ID of the current user::
|
|
201 |
||
202 |
bzr launchpad-login
|
|
203 |
||
|
2898.3.9
by James Henstridge
* Add a simple NEWS item for the command. |
204 |
Set the Launchpad ID of the current user to 'bob'::
|
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
205 |
|
|
2898.3.9
by James Henstridge
* Add a simple NEWS item for the command. |
206 |
bzr launchpad-login bob
|
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
207 |
"""
|
208 |
aliases = ['lp-login'] |
|
209 |
takes_args = ['name?'] |
|
210 |
takes_options = [ |
|
|
2898.3.4
by James Henstridge
Cleanups from mini-review by Tim. |
211 |
Option('no-check', |
212 |
"Don't check that the user name is valid."), |
|
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
213 |
]
|
214 |
||
|
2898.3.7
by James Henstridge
* Add tests for account.py exception messages. |
215 |
def run(self, name=None, no_check=False): |
|
2898.3.8
by James Henstridge
Get rid of relative imports in Launchpad plugin. |
216 |
from bzrlib.plugins.launchpad import account |
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
217 |
check_account = not no_check |
218 |
||
219 |
if name is None: |
|
220 |
username = account.get_lp_login() |
|
221 |
if username: |
|
|
2898.3.4
by James Henstridge
Cleanups from mini-review by Tim. |
222 |
if check_account: |
223 |
account.check_lp_login(username) |
|
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
224 |
self.outf.write(username + '\n') |
225 |
else: |
|
226 |
self.outf.write('No Launchpad user ID configured.\n') |
|
|
2898.3.9
by James Henstridge
* Add a simple NEWS item for the command. |
227 |
return 1 |
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
228 |
else: |
|
4216.2.1
by Michael Hudson
well this is it |
229 |
name = name.lower() |
|
2898.3.3
by James Henstridge
Add launchpad-login command. |
230 |
if check_account: |
231 |
account.check_lp_login(name) |
|
232 |
account.set_lp_login(name) |
|
233 |
||
234 |
register_command(cmd_launchpad_login) |
|
235 |
||
236 |
||
|
3251.4.2
by Aaron Bentley
Clean up Launchpad directory service code |
237 |
def _register_directory(): |
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
238 |
directories.register_lazy('lp:', 'bzrlib.plugins.launchpad.lp_directory', |
|
3251.4.2
by Aaron Bentley
Clean up Launchpad directory service code |
239 |
'LaunchpadDirectory', |
240 |
'Launchpad-based directory service',) |
|
241 |
_register_directory() |
|
|
2245.8.5
by Martin Pool
Add short-form lp:PRODUCT url form |
242 |
|
|
0.4.1
by Martin Pool
Start lp-register command |
243 |
|
244 |
def test_suite(): |
|
245 |
"""Called by bzrlib to fetch tests for this plugin""" |
|
246 |
from unittest import TestSuite, TestLoader |
|
|
2898.3.8
by James Henstridge
Get rid of relative imports in Launchpad plugin. |
247 |
from bzrlib.plugins.launchpad import ( |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
248 |
test_account, |
249 |
test_lp_directory, |
|
250 |
test_lp_open, |
|
251 |
test_lp_service, |
|
252 |
test_register, |
|
253 |
)
|
|
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
254 |
|
255 |
loader = TestLoader() |
|
256 |
suite = TestSuite() |
|
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
257 |
for module in [ |
|
3221.4.5
by Martin Pool
Tweak indents |
258 |
test_account, |
259 |
test_register, |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
260 |
test_lp_directory, |
|
3955.3.7
by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs. |
261 |
test_lp_open, |
|
3221.4.5
by Martin Pool
Tweak indents |
262 |
test_lp_service, |
|
3193.5.3
by Tim Penhey
Tweaks following review. |
263 |
]:
|
|
3221.4.2
by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance |
264 |
suite.addTests(loader.loadTestsFromModule(module)) |
|
2245.8.1
by Martin Pool
Start adding tests for launchpad indirection |
265 |
return suite |
|
2245.8.6
by Martin Pool
Documentation under 'help launchpad' |
266 |
|
267 |
_launchpad_help = """Integration with Launchpad.net |
|
268 |
||
269 |
Launchpad.net provides free Bazaar branch hosting with integrated bug and
|
|
270 |
specification tracking.
|
|
271 |
||
|
3031.1.1
by jml at canonical
Expand the documentation on lp:// URLs and mention the launchpad-login command. |
272 |
The bzr client (through the plugin called 'launchpad') has special
|
|
2245.8.6
by Martin Pool
Documentation under 'help launchpad' |
273 |
features to communicate with Launchpad:
|
274 |
||
|
3031.1.1
by jml at canonical
Expand the documentation on lp:// URLs and mention the launchpad-login command. |
275 |
* The launchpad-login command tells Bazaar your Launchpad user name. This
|
276 |
is then used by the 'lp:' transport to download your branches using
|
|
277 |
bzr+ssh://.
|
|
278 |
||
279 |
* The register-branch command tells Launchpad about the url of a
|
|
|
2245.8.6
by Martin Pool
Documentation under 'help launchpad' |
280 |
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. |
281 |
its contents and allow it to be attached to bugs and other
|
|
2245.8.6
by Martin Pool
Documentation under 'help launchpad' |
282 |
objects.
|
283 |
||
|
3031.1.1
by jml at canonical
Expand the documentation on lp:// URLs and mention the launchpad-login command. |
284 |
* The 'lp:' transport uses Launchpad as a directory service: for example
|
285 |
'lp:bzr' and 'lp:python' refer to the main branches of the relevant
|
|
286 |
projects and may be branched, logged, etc. You can also use the 'lp:'
|
|
287 |
transport to refer to specific branches, e.g. lp:///~bzr/bzr/trunk.
|
|
|
2245.8.6
by Martin Pool
Documentation under 'help launchpad' |
288 |
|
289 |
For more information see http://help.launchpad.net/
|
|
290 |
"""
|
|
291 |
topic_registry.register('launchpad', |
|
292 |
_launchpad_help, |
|
293 |
'Using Bazaar with Launchpad.net') |