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, |
|
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 |
||
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
68 |
def _resolve(self, url, |
|
2898.4.11
by James Henstridge
Switch back to RedirectRequested based implementation. |
69 |
_request_factory=ResolveLaunchpadPathRequest, |
70 |
_lp_login=None): |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
71 |
"""Resolve the base URL for this transport.""" |
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
72 |
# Do ubuntu: and debianlp: expansions.
|
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
73 |
scheme, netloc, path, query, fragment = urlsplit(url) |
74 |
if scheme in ('ubuntu', 'debianlp'): |
|
75 |
if scheme == 'ubuntu': |
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
76 |
distro = 'ubuntu' |
|
5462.4.5
by Barry Warsaw
We only need to include distroseries shortcuts. |
77 |
distro_series = _ubuntu_series_shortcuts |
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
78 |
elif scheme == 'debianlp': |
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
79 |
distro = 'debian' |
|
5462.4.5
by Barry Warsaw
We only need to include distroseries shortcuts. |
80 |
# No shortcuts for Debian distroseries.
|
81 |
distro_series = {} |
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
82 |
else: |
83 |
raise AssertionError('scheme should be ubuntu: or debianlp:') |
|
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
84 |
# Split the path. It's either going to be 'project' or
|
85 |
# 'series/project', but recognize that it may be a series we don't
|
|
86 |
# know about.
|
|
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
87 |
path_parts = path.split('/') |
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
88 |
if len(path_parts) == 1: |
89 |
# It's just a project name.
|
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
90 |
lp_url_template = 'lp:%(distro)s/%(project)s' |
91 |
project = path_parts[0] |
|
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
92 |
series = None |
93 |
elif len(path_parts) == 2: |
|
94 |
# It's a series and project.
|
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
95 |
lp_url_template = 'lp:%(distro)s/%(series)s/%(project)s' |
|
5462.4.3
by Barry Warsaw
* Add back Ubuntu distroseries shortcuts. |
96 |
series, project = path_parts |
97 |
else: |
|
98 |
# There are either 0 or > 2 path parts, neither of which is
|
|
99 |
# supported for these schemes.
|
|
100 |
raise errors.InvalidURL('Bad path: %s' % result.path) |
|
101 |
# Expand any series shortcuts, but keep unknown series.
|
|
102 |
series = distro_series.get(series, series) |
|
|
5462.4.1
by Barry Warsaw
Added support for ubuntu: and debianlp: schemes, accessing the relevant |
103 |
# Hack the url and let the following do the final resolution.
|
104 |
url = lp_url_template % dict( |
|
105 |
distro=distro, |
|
106 |
series=series, |
|
107 |
project=project) |
|
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
108 |
scheme, netloc, path, query, fragment = urlsplit(url) |
|
4505.6.2
by Jonathan Lange
Extract a method that gets a service from a URL. |
109 |
service = LaunchpadService.for_url(url) |
|
5361.1.1
by John Arbash Meinel
Handle a simple ~ in lp: urls. |
110 |
if _lp_login is None: |
111 |
_lp_login = get_lp_login() |
|
|
5462.4.10
by Vincent Ladeuil
Fix python2.4 compatibility. |
112 |
path = path.strip('/') |
|
5361.1.1
by John Arbash Meinel
Handle a simple ~ in lp: urls. |
113 |
if path.startswith('~/'): |
114 |
if _lp_login is None: |
|
115 |
raise errors.InvalidURL(path=url, |
|
116 |
extra='Cannot resolve "~" to your username.' |
|
117 |
' See "bzr help launchpad-login"') |
|
118 |
path = '~' + _lp_login + path[1:] |
|
119 |
resolve = _request_factory(path) |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
120 |
try: |
121 |
result = resolve.submit(service) |
|
122 |
except xmlrpclib.Fault, fault: |
|
123 |
raise errors.InvalidURL( |
|
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
124 |
path=url, extra=fault.faultString) |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
125 |
|
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
126 |
if 'launchpad' in debug.debug_flags: |
|
4505.6.2
by Jonathan Lange
Extract a method that gets a service from a URL. |
127 |
trace.mutter("resolve_lp_path(%r) == %r", url, result) |
|
2898.4.14
by James Henstridge
* Use urlsplit() to process URLs. |
128 |
|
|
3270.4.1
by James Westby
Warn the user when resolving lp: URLs if they haven't set their login. |
129 |
_warned_login = False |
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
130 |
for url in result['urls']: |
131 |
scheme, netloc, path, query, fragment = urlsplit(url) |
|
|
3031.2.4
by jml at canonical
Only split the URL once. |
132 |
if self._requires_launchpad_login(scheme, netloc, path, query, |
133 |
fragment): |
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
134 |
# Only accept launchpad.net bzr+ssh URLs if we know
|
135 |
# the user's Launchpad login:
|
|
|
3777.1.21
by Aaron Bentley
Stop including usernames in resolved lp: urls |
136 |
if _lp_login is not None: |
137 |
break
|
|
|
2898.4.9
by James Henstridge
Add some more tests for the bzr+ssh://bazaar.launchpad.net URL |
138 |
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. |
139 |
if not _warned_login: |
|
3834.1.2
by Martin Pool
Better message when launchpad-login is needed |
140 |
trace.warning( |
|
3834.1.3
by Martin Pool
Shorter message about launchpad-login |
141 |
'You have not informed bzr of your Launchpad ID, and you must do this to\n' |
142 |
'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. |
143 |
_warned_login = True |
|
2898.4.15
by James Henstridge
Use get_transport() to decide whether Bazaar supports a given URL. |
144 |
else: |
145 |
# Use the URL if we can create a transport for it.
|
|
146 |
try: |
|
|
5609.9.1
by Martin
Blindly change all users of get_transport to address the function via the transport module |
147 |
transport.get_transport(url) |
|
2898.4.15
by James Henstridge
Use get_transport() to decide whether Bazaar supports a given URL. |
148 |
except (errors.PathError, errors.TransportError): |
149 |
pass
|
|
150 |
else: |
|
151 |
break
|
|
|
2898.4.8
by James Henstridge
Switch lp: over to a pass-through transport, so that the XMLRPC gets |
152 |
else: |
|
3251.4.3
by Aaron Bentley
More renames and cleanups |
153 |
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 |
154 |
return url |
155 |
||
|
2245.8.3
by Martin Pool
Start adding indirection transport |
156 |
|
157 |
def get_test_permutations(): |
|
158 |
# Since this transport doesn't do anything once opened, it's not subjected
|
|
159 |
# to the usual transport tests.
|
|
160 |
return [] |