bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2007-2010 Canonical Ltd
|
|
2245.8.3
by Martin Pool
Start adding indirection transport |
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
|
|
2245.8.3
by Martin Pool
Start adding indirection transport |
16 |
|
17 |
||
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
18 |
"""Directory lookup that uses Launchpad."""
|
|
2245.8.3
by Martin Pool
Start adding indirection transport |
19 |
|
|
5121.2.1
by Jelmer Vernooij
Remove unused imports in lp_directory. |
20 |
from urlparse import urlsplit |
|
2898.4.4
by James Henstridge
Changes to account for modifications to the XMLRPC API. |
21 |
import xmlrpclib |
22 |
||
|
2245.8.4
by Martin Pool
lp:/// indirection works |
23 |
from bzrlib import ( |
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
24 |
debug, |
|
2245.8.4
by Martin Pool
lp:/// indirection works |
25 |
errors, |
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
26 |
trace, |
|
2245.8.4
by Martin Pool
lp:/// indirection works |
27 |
)
|
28 |
from bzrlib.transport import ( |
|
29 |
get_transport, |
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
30 |
register_urlparse_netloc_protocol, |
|
2245.8.4
by Martin Pool
lp:/// indirection works |
31 |
)
|
32 |
||
|
2898.4.7
by James Henstridge
Fix up tests. |
33 |
from bzrlib.plugins.launchpad.lp_registration import ( |
34 |
LaunchpadService, ResolveLaunchpadPathRequest) |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
35 |
from bzrlib.plugins.launchpad.account import get_lp_login |
36 |
||
37 |
||
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
38 |
# As bzrlib.transport.remote may not be loaded yet, make sure bzr+ssh
|
39 |
# is counted as a netloc protocol.
|
|
40 |
register_urlparse_netloc_protocol('bzr+ssh') |
|
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
41 |
register_urlparse_netloc_protocol('lp') |
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
42 |
|
43 |
||
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
44 |
class LaunchpadDirectory(object): |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
45 |
|
|
3031.2.4
by jml at canonical
Only split the URL once. |
46 |
def _requires_launchpad_login(self, scheme, netloc, path, query, |
47 |
fragment): |
|
48 |
"""Does the URL require a Launchpad login in order to be reached? |
|
49 |
||
50 |
The URL is specified by its parsed components, as returned from
|
|
51 |
urlsplit.
|
|
52 |
"""
|
|
|
3031.2.3
by jml at canonical
Make the test pass -- don't include sftp URLs if there's no lp login. |
53 |
return (scheme in ('bzr+ssh', 'sftp') |
54 |
and (netloc.endswith('launchpad.net') |
|
55 |
or netloc.endswith('launchpad.dev'))) |
|
|
3031.2.1
by jml at canonical
Factor out the method that determines if a URL is a LP url. |
56 |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
57 |
def look_up(self, name, url): |
|
3251.4.5
by Aaron Bentley
Add docstring |
58 |
"""See DirectoryService.look_up""" |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
59 |
return self._resolve(url) |
60 |
||
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
61 |
def _resolve(self, url, |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
62 |
_request_factory=ResolveLaunchpadPathRequest, |
63 |
_lp_login=None): |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
64 |
"""Resolve the base URL for this transport.""" |
|
4505.6.2
by Jonathan Lange
Extract a method that gets a service from a URL. |
65 |
service = LaunchpadService.for_url(url) |
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
66 |
result = urlsplit(url) |
|
3251.4.7
by Daniel Watkins
Remove Python 2.5-isms |
67 |
resolve = _request_factory(result[2].strip('/')) |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
68 |
try: |
69 |
result = resolve.submit(service) |
|
70 |
except xmlrpclib.Fault, fault: |
|
71 |
raise errors.InvalidURL( |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
72 |
path=url, extra=fault.faultString) |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
73 |
|
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
74 |
if 'launchpad' in debug.debug_flags: |
|
4505.6.2
by Jonathan Lange
Extract a method that gets a service from a URL. |
75 |
trace.mutter("resolve_lp_path(%r) == %r", url, result) |
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
76 |
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
77 |
if _lp_login is None: |
78 |
_lp_login = get_lp_login() |
|
|
3270.4.1
by James Westby
Warn the user when resolving lp: URLs if they haven't set their login. |
79 |
_warned_login = False |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
80 |
for url in result['urls']: |
81 |
scheme, netloc, path, query, fragment = urlsplit(url) |
|
|
3031.2.4
by jml at canonical
Only split the URL once. |
82 |
if self._requires_launchpad_login(scheme, netloc, path, query, |
83 |
fragment): |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
84 |
# Only accept launchpad.net bzr+ssh URLs if we know
|
85 |
# the user's Launchpad login:
|
|
|
3777.1.21
by Aaron Bentley
Stop including usernames in resolved lp: urls |
86 |
if _lp_login is not None: |
87 |
break
|
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
88 |
if _lp_login is None: |
|
3270.4.1
by James Westby
Warn the user when resolving lp: URLs if they haven't set their login. |
89 |
if not _warned_login: |
|
3834.1.2
by Martin Pool
Better message when launchpad-login is needed |
90 |
trace.warning( |
|
3834.1.3
by Martin Pool
Shorter message about launchpad-login |
91 |
'You have not informed bzr of your Launchpad ID, and you must do this to\n' |
92 |
'write to Launchpad or access private data. See "bzr help launchpad-login".') |
|
|
3270.4.1
by James Westby
Warn the user when resolving lp: URLs if they haven't set their login. |
93 |
_warned_login = True |
|
2898.4.15
by James Henstridge
Use get_transport() to decide whether Bazaar supports a given URL. |
94 |
else: |
95 |
# Use the URL if we can create a transport for it.
|
|
96 |
try: |
|
97 |
get_transport(url) |
|
98 |
except (errors.PathError, errors.TransportError): |
|
99 |
pass
|
|
100 |
else: |
|
101 |
break
|
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
102 |
else: |
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
103 |
raise errors.InvalidURL(path=url, extra='no supported schemes') |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
104 |
return url |
105 |
||
|
2245.8.3
by Martin Pool
Start adding indirection transport |
106 |
|
107 |
def get_test_permutations(): |
|
108 |
# Since this transport doesn't do anything once opened, it's not subjected
|
|
109 |
# to the usual transport tests.
|
|
110 |
return [] |