bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5609.24.7
by John Arbash Meinel
Fix bug #397739. Avoid doing an XMLRPC lookup if a user |
1 |
# Copyright (C) 2007-2011 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, |
|
5609.9.1
by Martin
Blindly change all users of get_transport to address the function via the transport module |
27 |
transport, |
|
2245.8.4
by Martin Pool
lp:/// indirection works |
28 |
)
|
29 |
||
|
2898.4.7
by James Henstridge
Fix up tests. |
30 |
from bzrlib.plugins.launchpad.lp_registration import ( |
31 |
LaunchpadService, ResolveLaunchpadPathRequest) |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
32 |
from bzrlib.plugins.launchpad.account import get_lp_login |
33 |
||
34 |
||
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
35 |
# As bzrlib.transport.remote may not be loaded yet, make sure bzr+ssh
|
36 |
# is counted as a netloc protocol.
|
|
|
5609.9.1
by Martin
Blindly change all users of get_transport to address the function via the transport module |
37 |
transport.register_urlparse_netloc_protocol('bzr+ssh') |
38 |
transport.register_urlparse_netloc_protocol('lp') |
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
39 |
|
|
5462.4.5
by Barry Warsaw
We only need to include distroseries shortcuts. |
40 |
_ubuntu_series_shortcuts = { |
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
41 |
'n': 'natty', |
42 |
'm': 'maverick', |
|
43 |
'l': 'lucid', |
|
44 |
'k': 'karmic', |
|
45 |
'j': 'jaunty', |
|
46 |
'h': 'hardy', |
|
47 |
'd': 'dapper', |
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
48 |
}
|
49 |
||
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
50 |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
51 |
class LaunchpadDirectory(object): |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
52 |
|
|
3031.2.4
by jml at canonical
Only split the URL once. |
53 |
def _requires_launchpad_login(self, scheme, netloc, path, query, |
54 |
fragment): |
|
55 |
"""Does the URL require a Launchpad login in order to be reached? |
|
56 |
||
57 |
The URL is specified by its parsed components, as returned from
|
|
58 |
urlsplit.
|
|
59 |
"""
|
|
|
3031.2.3
by jml at canonical
Make the test pass -- don't include sftp URLs if there's no lp login. |
60 |
return (scheme in ('bzr+ssh', 'sftp') |
61 |
and (netloc.endswith('launchpad.net') |
|
62 |
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. |
63 |
|
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
64 |
def look_up(self, name, url): |
|
3251.4.5
by Aaron Bentley
Add docstring |
65 |
"""See DirectoryService.look_up""" |
|
3251.4.1
by Aaron Bentley
Convert LP transport into directory service |
66 |
return self._resolve(url) |
67 |
||
|
5609.24.7
by John Arbash Meinel
Fix bug #397739. Avoid doing an XMLRPC lookup if a user |
68 |
def _resolve_locally(self, path): |
69 |
# Launchpad is now capable of doing the short-name to long name
|
|
70 |
# resolution inside the bzr+ssh server. We aren't yet able to do so for
|
|
71 |
# HTTP urls. - jam 20110323
|
|
|
5609.24.8
by John Arbash Meinel
Fix the launchpad-login tests. And fix a bad commit typo. |
72 |
return {'urls': ['bzr+ssh://bazaar.launchpad.net/+branch/' + path]} |
|
5609.24.7
by John Arbash Meinel
Fix bug #397739. Avoid doing an XMLRPC lookup if a user |
73 |
|
74 |
def _resolve_via_xmlrpc(self, path, url, _request_factory): |
|
75 |
service = LaunchpadService.for_url(url) |
|
76 |
resolve = _request_factory(path) |
|
77 |
try: |
|
78 |
result = resolve.submit(service) |
|
79 |
except xmlrpclib.Fault, fault: |
|
80 |
raise errors.InvalidURL( |
|
81 |
path=url, extra=fault.faultString) |
|
82 |
return result |
|
83 |
||
84 |
def _update_url_scheme(self, url): |
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
85 |
# Do ubuntu: and debianlp: expansions.
|
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
86 |
scheme, netloc, path, query, fragment = urlsplit(url) |
87 |
if scheme in ('ubuntu', 'debianlp'): |
|
88 |
if scheme == 'ubuntu': |
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
89 |
distro = 'ubuntu' |
|
5462.4.5
by Barry Warsaw
We only need to include distroseries shortcuts. |
90 |
distro_series = _ubuntu_series_shortcuts |
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
91 |
elif scheme == 'debianlp': |
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
92 |
distro = 'debian' |
|
5462.4.5
by Barry Warsaw
We only need to include distroseries shortcuts. |
93 |
# No shortcuts for Debian distroseries.
|
94 |
distro_series = {} |
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
95 |
else: |
96 |
raise AssertionError('scheme should be ubuntu: or debianlp:') |
|
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
97 |
# Split the path. It's either going to be 'project' or
|
98 |
# 'series/project', but recognize that it may be a series we don't
|
|
99 |
# know about.
|
|
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
100 |
path_parts = path.split('/') |
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
101 |
if len(path_parts) == 1: |
102 |
# It's just a project name.
|
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
103 |
lp_url_template = 'lp:%(distro)s/%(project)s' |
104 |
project = path_parts[0] |
|
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
105 |
series = None |
106 |
elif len(path_parts) == 2: |
|
107 |
# It's a series and project.
|
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
108 |
lp_url_template = 'lp:%(distro)s/%(series)s/%(project)s' |
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
109 |
series, project = path_parts |
110 |
else: |
|
111 |
# There are either 0 or > 2 path parts, neither of which is
|
|
112 |
# supported for these schemes.
|
|
113 |
raise errors.InvalidURL('Bad path: %s' % result.path) |
|
114 |
# Expand any series shortcuts, but keep unknown series.
|
|
115 |
series = distro_series.get(series, series) |
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
116 |
# Hack the url and let the following do the final resolution.
|
117 |
url = lp_url_template % dict( |
|
118 |
distro=distro, |
|
119 |
series=series, |
|
120 |
project=project) |
|
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
121 |
scheme, netloc, path, query, fragment = urlsplit(url) |
|
5609.24.7
by John Arbash Meinel
Fix bug #397739. Avoid doing an XMLRPC lookup if a user |
122 |
return url, path |
123 |
||
|
5609.24.8
by John Arbash Meinel
Fix the launchpad-login tests. And fix a bad commit typo. |
124 |
def _expand_user(self, path, url, lp_login): |
|
5361.1.1
by John Arbash Meinel
Handle a simple ~ in lp: urls. |
125 |
if path.startswith('~/'): |
|
5609.24.7
by John Arbash Meinel
Fix bug #397739. Avoid doing an XMLRPC lookup if a user |
126 |
if lp_login is None: |
|
5361.1.1
by John Arbash Meinel
Handle a simple ~ in lp: urls. |
127 |
raise errors.InvalidURL(path=url, |
128 |
extra='Cannot resolve "~" to your username.' |
|
129 |
' See "bzr help launchpad-login"') |
|
|
5609.24.7
by John Arbash Meinel
Fix bug #397739. Avoid doing an XMLRPC lookup if a user |
130 |
path = '~' + lp_login + path[1:] |
131 |
return path |
|
132 |
||
133 |
def _resolve(self, url, |
|
134 |
_request_factory=ResolveLaunchpadPathRequest, |
|
135 |
_lp_login=None): |
|
136 |
"""Resolve the base URL for this transport.""" |
|
137 |
url, path = self._update_url_scheme(url) |
|
138 |
if _lp_login is None: |
|
139 |
_lp_login = get_lp_login() |
|
140 |
path = path.strip('/') |
|
|
5609.24.8
by John Arbash Meinel
Fix the launchpad-login tests. And fix a bad commit typo. |
141 |
path = self._expand_user(path, url, _lp_login) |
|
5609.24.7
by John Arbash Meinel
Fix bug #397739. Avoid doing an XMLRPC lookup if a user |
142 |
if _lp_login is not None: |
143 |
result = self._resolve_locally(path) |
|
144 |
else: |
|
145 |
result = self._resolve_via_xmlrpc(path, url, _request_factory) |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
146 |
|
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
147 |
if 'launchpad' in debug.debug_flags: |
|
4505.6.2
by Jonathan Lange
Extract a method that gets a service from a URL. |
148 |
trace.mutter("resolve_lp_path(%r) == %r", url, result) |
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
149 |
|
|
3270.4.1
by James Westby
Warn the user when resolving lp: URLs if they haven't set their login. |
150 |
_warned_login = False |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
151 |
for url in result['urls']: |
152 |
scheme, netloc, path, query, fragment = urlsplit(url) |
|
|
3031.2.4
by jml at canonical
Only split the URL once. |
153 |
if self._requires_launchpad_login(scheme, netloc, path, query, |
154 |
fragment): |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
155 |
# Only accept launchpad.net bzr+ssh URLs if we know
|
156 |
# the user's Launchpad login:
|
|
|
3777.1.21
by Aaron Bentley
Stop including usernames in resolved lp: urls |
157 |
if _lp_login is not None: |
158 |
break
|
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
159 |
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. |
160 |
if not _warned_login: |
|
3834.1.2
by Martin Pool
Better message when launchpad-login is needed |
161 |
trace.warning( |
|
3834.1.3
by Martin Pool
Shorter message about launchpad-login |
162 |
'You have not informed bzr of your Launchpad ID, and you must do this to\n' |
163 |
'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. |
164 |
_warned_login = True |
|
2898.4.15
by James Henstridge
Use get_transport() to decide whether Bazaar supports a given URL. |
165 |
else: |
166 |
# Use the URL if we can create a transport for it.
|
|
167 |
try: |
|
|
5609.9.1
by Martin
Blindly change all users of get_transport to address the function via the transport module |
168 |
transport.get_transport(url) |
|
2898.4.15
by James Henstridge
Use get_transport() to decide whether Bazaar supports a given URL. |
169 |
except (errors.PathError, errors.TransportError): |
170 |
pass
|
|
171 |
else: |
|
172 |
break
|
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
173 |
else: |
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
174 |
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 |
175 |
return url |
176 |
||
|
2245.8.3
by Martin Pool
Start adding indirection transport |
177 |
|
178 |
def get_test_permutations(): |
|
179 |
# Since this transport doesn't do anything once opened, it's not subjected
|
|
180 |
# to the usual transport tests.
|
|
181 |
return [] |