/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/lp_indirect.py

  • Committer: Robert Collins
  • Date: 2007-07-15 15:40:37 UTC
  • mto: (2592.3.33 repository)
  • mto: This revision was merged to the branch mainline in revision 2624.
  • Revision ID: robertc@robertcollins.net-20070715154037-3ar8g89decddc9su
Make GraphIndex accept nodes as key, value, references, so that the method
signature is closer to what a simple key->value index delivers. Also
change the behaviour when the reference list count is zero to accept
key, value as nodes, and emit key, value to make it identical in that case
to a simple key->value index. This may not be a good idea, but for now it
seems ok.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
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
16
 
 
17
 
 
18
 
"""Directory lookup that uses Launchpad."""
19
 
 
20
 
from urlparse import urlsplit
21
 
import xmlrpclib
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
"""Transport indirection that uses Launchpad as a directory lookup.
 
19
 
 
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
 
22
again.
 
23
"""
22
24
 
23
25
from bzrlib import (
24
 
    debug,
25
26
    errors,
26
 
    trace,
27
27
    )
28
28
from bzrlib.transport import (
29
29
    get_transport,
30
 
    register_urlparse_netloc_protocol,
 
30
    Transport,
31
31
    )
32
32
 
33
 
from bzrlib.plugins.launchpad.lp_registration import (
34
 
    LaunchpadService, ResolveLaunchpadPathRequest)
35
 
from bzrlib.plugins.launchpad.account import get_lp_login
36
 
 
37
 
 
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')
42
 
 
43
 
 
44
 
class LaunchpadDirectory(object):
45
 
 
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
 
        """
53
 
        return (scheme in ('bzr+ssh', 'sftp')
54
 
                and (netloc.endswith('launchpad.net')
55
 
                     or netloc.endswith('launchpad.dev')))
56
 
 
57
 
    def look_up(self, name, url):
58
 
        """See DirectoryService.look_up"""
59
 
        return self._resolve(url)
60
 
 
61
 
    def _resolve(self, url,
62
 
                 _request_factory=ResolveLaunchpadPathRequest,
63
 
                 _lp_login=None):
64
 
        """Resolve the base URL for this transport."""
65
 
        service = LaunchpadService.for_url(url)
66
 
        result = urlsplit(url)
67
 
        resolve = _request_factory(result[2].strip('/'))
68
 
        try:
69
 
            result = resolve.submit(service)
70
 
        except xmlrpclib.Fault, fault:
71
 
            raise errors.InvalidURL(
72
 
                path=url, extra=fault.faultString)
73
 
 
74
 
        if 'launchpad' in debug.debug_flags:
75
 
            trace.mutter("resolve_lp_path(%r) == %r", url, result)
76
 
 
77
 
        if _lp_login is None:
78
 
            _lp_login = get_lp_login()
79
 
        _warned_login = False
80
 
        for url in result['urls']:
81
 
            scheme, netloc, path, query, fragment = urlsplit(url)
82
 
            if self._requires_launchpad_login(scheme, netloc, path, query,
83
 
                                              fragment):
84
 
                # Only accept launchpad.net bzr+ssh URLs if we know
85
 
                # the user's Launchpad login:
86
 
                if _lp_login is not None:
87
 
                    break
88
 
                if _lp_login is None:
89
 
                    if not _warned_login:
90
 
                        trace.warning(
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".')
93
 
                        _warned_login = True
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
102
 
        else:
103
 
            raise errors.InvalidURL(path=url, extra='no supported schemes')
104
 
        return url
 
33
 
 
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:]
 
40
    else:
 
41
        raise errors.InvalidURL(path=base_url)
 
42
    return get_transport(real_url)
105
43
 
106
44
 
107
45
def get_test_permutations():