~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2009-12-10 00:13:16 UTC
  • mto: This revision was merged to the branch mainline in revision 4884.
  • Revision ID: mbp@sourcefrog.net-20091210001316-w1l2jtek6v8iyg49
Mention GNU project in --version

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import urllib
22
22
import xmlrpclib
23
23
 
 
24
from bzrlib.lazy_import import lazy_import
 
25
lazy_import(globals(), """
 
26
from bzrlib import urlutils
 
27
""")
 
28
 
24
29
from bzrlib import (
25
30
    config,
26
31
    errors,
27
 
    urlutils,
28
32
    __version__ as _bzrlib_version,
29
33
    )
30
34
from bzrlib.transport.http import _urllib2_wrappers
31
35
 
32
 
 
33
36
# for testing, do
34
37
'''
35
38
export BZR_LP_XMLRPC_URL=http://xmlrpc.staging.launchpad.net/bazaar/
81
84
class LaunchpadService(object):
82
85
    """A service to talk to Launchpad via XMLRPC.
83
86
 
84
 
    See http://wiki.bazaar.canonical.com/Specs/LaunchpadRpc for the methods we can call.
 
87
    See http://bazaar-vcs.org/Specs/LaunchpadRpc for the methods we can call.
85
88
    """
86
89
 
87
90
    LAUNCHPAD_DOMAINS = {
120
123
                    % (_bzrlib_version, xmlrpclib.__version__)
121
124
        self.transport = transport
122
125
 
 
126
 
123
127
    @property
124
128
    def service_url(self):
125
129
        """Return the http or https url for the xmlrpc server.
137
141
        else:
138
142
            return self.DEFAULT_SERVICE_URL
139
143
 
140
 
    @classmethod
141
 
    def for_url(cls, url, **kwargs):
142
 
        """Return the Launchpad service corresponding to the given URL."""
143
 
        result = urlsplit(url)
144
 
        lp_instance = result[1]
145
 
        if lp_instance == '':
146
 
            lp_instance = None
147
 
        elif lp_instance not in cls.LAUNCHPAD_INSTANCE:
148
 
            raise errors.InvalidURL(path=url)
149
 
        return cls(lp_instance=lp_instance, **kwargs)
150
 
 
151
144
    def get_proxy(self, authenticated):
152
145
        """Return the proxy for XMLRPC requests."""
153
146
        if authenticated:
223
216
            instance = self._lp_instance
224
217
        return self.LAUNCHPAD_DOMAINS[instance]
225
218
 
226
 
    def _guess_branch_path(self, branch_url, _request_factory=None):
 
219
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
 
220
        """Get the Launchpad web URL for the given branch URL.
 
221
 
 
222
        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
 
223
            Launchpad branch URL.
 
224
        :return: The URL of the branch on Launchpad.
 
225
        """
227
226
        scheme, hostinfo, path = urlsplit(branch_url)[:3]
228
227
        if _request_factory is None:
229
228
            _request_factory = ResolveLaunchpadPathRequest
241
240
                for domain in self.LAUNCHPAD_DOMAINS.itervalues())
242
241
            if hostinfo not in domains:
243
242
                raise NotLaunchpadBranch(branch_url)
244
 
        return path.lstrip('/')
245
 
 
246
 
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
247
 
        """Get the Launchpad web URL for the given branch URL.
248
 
 
249
 
        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
250
 
            Launchpad branch URL.
251
 
        :return: The URL of the branch on Launchpad.
252
 
        """
253
 
        path = self._guess_branch_path(branch_url, _request_factory)
254
243
        return urlutils.join('https://code.%s' % self.domain, path)
255
244
 
256
245