13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Directory lookup that uses Launchpad."""
20
from urlparse import urlsplit
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""Transport indirection that uses Launchpad as a directory lookup.
20
When the transport is opened, it immediately redirects to a url
21
on Launchpad, which can then either serve the branch itself or redirect
23
25
from bzrlib import (
28
28
from bzrlib.transport import (
30
register_urlparse_netloc_protocol,
33
from bzrlib.plugins.launchpad.lp_registration import (
34
LaunchpadService, ResolveLaunchpadPathRequest)
35
from bzrlib.plugins.launchpad.account import get_lp_login
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')
41
register_urlparse_netloc_protocol('lp')
44
class LaunchpadDirectory(object):
46
def _requires_launchpad_login(self, scheme, netloc, path, query,
48
"""Does the URL require a Launchpad login in order to be reached?
50
The URL is specified by its parsed components, as returned from
53
return (scheme in ('bzr+ssh', 'sftp')
54
and (netloc.endswith('launchpad.net')
55
or netloc.endswith('launchpad.dev')))
57
def look_up(self, name, url):
58
"""See DirectoryService.look_up"""
59
return self._resolve(url)
61
def _resolve(self, url,
62
_request_factory=ResolveLaunchpadPathRequest,
64
"""Resolve the base URL for this transport."""
65
service = LaunchpadService.for_url(url)
66
result = urlsplit(url)
68
_lp_login = get_lp_login()
69
path = result[2].strip('/')
70
if path.startswith('~/'):
72
raise errors.InvalidURL(path=url,
73
extra='Cannot resolve "~" to your username.'
74
' See "bzr help launchpad-login"')
75
path = '~' + _lp_login + path[1:]
76
resolve = _request_factory(path)
78
result = resolve.submit(service)
79
except xmlrpclib.Fault, fault:
80
raise errors.InvalidURL(
81
path=url, extra=fault.faultString)
83
if 'launchpad' in debug.debug_flags:
84
trace.mutter("resolve_lp_path(%r) == %r", url, result)
87
for url in result['urls']:
88
scheme, netloc, path, query, fragment = urlsplit(url)
89
if self._requires_launchpad_login(scheme, netloc, path, query,
91
# Only accept launchpad.net bzr+ssh URLs if we know
92
# the user's Launchpad login:
93
if _lp_login is not None:
98
'You have not informed bzr of your Launchpad ID, and you must do this to\n'
99
'write to Launchpad or access private data. See "bzr help launchpad-login".')
102
# Use the URL if we can create a transport for it.
105
except (errors.PathError, errors.TransportError):
110
raise errors.InvalidURL(path=url, extra='no supported schemes')
34
def launchpad_transport_indirect(base_url):
35
"""Uses Launchpad.net as a directory of open source software"""
36
if base_url.startswith('lp:///'):
37
real_url = 'http://code.launchpad.net/' + base_url[6:]
38
elif base_url.startswith('lp:') and base_url[3] != '/':
39
real_url = 'http://code.launchpad.net/' + base_url[3:]
41
raise errors.InvalidURL(path=base_url)
42
return get_transport(real_url)
114
45
def get_test_permutations():