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, urlunsplit
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 (
29
28
from bzrlib.transport import (
31
register_urlparse_netloc_protocol,
34
from bzrlib.plugins.launchpad.lp_registration import (
35
LaunchpadService, ResolveLaunchpadPathRequest)
36
from bzrlib.plugins.launchpad.account import get_lp_login
39
# As bzrlib.transport.remote may not be loaded yet, make sure bzr+ssh
40
# is counted as a netloc protocol.
41
register_urlparse_netloc_protocol('bzr+ssh')
42
register_urlparse_netloc_protocol('lp')
45
class LaunchpadDirectory(object):
47
def _requires_launchpad_login(self, scheme, netloc, path, query,
49
"""Does the URL require a Launchpad login in order to be reached?
51
The URL is specified by its parsed components, as returned from
54
return (scheme in ('bzr+ssh', 'sftp')
55
and (netloc.endswith('launchpad.net')
56
or netloc.endswith('launchpad.dev')))
58
def look_up(self, name, url):
59
"""See DirectoryService.look_up"""
60
return self._resolve(url)
62
def _resolve(self, url,
63
_request_factory=ResolveLaunchpadPathRequest,
65
"""Resolve the base URL for this transport."""
66
service = LaunchpadService.for_url(url)
67
result = urlsplit(url)
68
resolve = _request_factory(result[2].strip('/'))
70
result = resolve.submit(service)
71
except xmlrpclib.Fault, fault:
72
raise errors.InvalidURL(
73
path=url, extra=fault.faultString)
75
if 'launchpad' in debug.debug_flags:
76
trace.mutter("resolve_lp_path(%r) == %r", url, result)
79
_lp_login = get_lp_login()
81
for url in result['urls']:
82
scheme, netloc, path, query, fragment = urlsplit(url)
83
if self._requires_launchpad_login(scheme, netloc, path, query,
85
# Only accept launchpad.net bzr+ssh URLs if we know
86
# the user's Launchpad login:
87
if _lp_login is not None:
92
'You have not informed bzr of your Launchpad ID, and you must do this to\n'
93
'write to Launchpad or access private data. See "bzr help launchpad-login".')
96
# Use the URL if we can create a transport for it.
99
except (errors.PathError, errors.TransportError):
104
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)
108
45
def get_test_permutations():