~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Neil Martinsen-Burrell
  • Date: 2009-12-07 21:51:01 UTC
  • mto: This revision was merged to the branch mainline in revision 4910.
  • Revision ID: nmb@wartburg.edu-20091207215101-lv1fyi2blzer4h5j
tweaks based on JAMs review

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006 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
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 = {
88
91
        'production': 'launchpad.net',
 
92
        'edge': 'edge.launchpad.net',
89
93
        'staging': 'staging.launchpad.net',
90
 
        'qastaging': 'qastaging.launchpad.net',
91
94
        'demo': 'demo.launchpad.net',
92
95
        'dev': 'launchpad.dev',
93
96
        }
98
101
    for instance, domain in LAUNCHPAD_DOMAINS.iteritems():
99
102
        LAUNCHPAD_INSTANCE[instance] = 'https://xmlrpc.%s/bazaar/' % domain
100
103
 
101
 
    # We use production as the default because edge has been deprecated circa
102
 
    # 2010-11 (see bug https://bugs.launchpad.net/bzr/+bug/583667)
103
 
    DEFAULT_INSTANCE = 'production'
 
104
    # We use edge as the default because:
 
105
    # Beta users get redirected to it
 
106
    # All users can use it
 
107
    # There is a bug in the launchpad side where redirection causes an OOPS.
 
108
    DEFAULT_INSTANCE = 'edge'
104
109
    DEFAULT_SERVICE_URL = LAUNCHPAD_INSTANCE[DEFAULT_INSTANCE]
105
110
 
106
111
    transport = None
118
123
                    % (_bzrlib_version, xmlrpclib.__version__)
119
124
        self.transport = transport
120
125
 
 
126
 
121
127
    @property
122
128
    def service_url(self):
123
129
        """Return the http or https url for the xmlrpc server.
135
141
        else:
136
142
            return self.DEFAULT_SERVICE_URL
137
143
 
138
 
    @classmethod
139
 
    def for_url(cls, url, **kwargs):
140
 
        """Return the Launchpad service corresponding to the given URL."""
141
 
        result = urlsplit(url)
142
 
        lp_instance = result[1]
143
 
        if lp_instance == '':
144
 
            lp_instance = None
145
 
        elif lp_instance not in cls.LAUNCHPAD_INSTANCE:
146
 
            raise errors.InvalidURL(path=url)
147
 
        return cls(lp_instance=lp_instance, **kwargs)
148
 
 
149
144
    def get_proxy(self, authenticated):
150
145
        """Return the proxy for XMLRPC requests."""
151
146
        if authenticated:
221
216
            instance = self._lp_instance
222
217
        return self.LAUNCHPAD_DOMAINS[instance]
223
218
 
224
 
    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
        """
225
226
        scheme, hostinfo, path = urlsplit(branch_url)[:3]
226
227
        if _request_factory is None:
227
228
            _request_factory = ResolveLaunchpadPathRequest
239
240
                for domain in self.LAUNCHPAD_DOMAINS.itervalues())
240
241
            if hostinfo not in domains:
241
242
                raise NotLaunchpadBranch(branch_url)
242
 
        return path.lstrip('/')
243
 
 
244
 
    def get_web_url_from_branch_url(self, branch_url, _request_factory=None):
245
 
        """Get the Launchpad web URL for the given branch URL.
246
 
 
247
 
        :raise errors.InvalidURL: if 'branch_url' cannot be identified as a
248
 
            Launchpad branch URL.
249
 
        :return: The URL of the branch on Launchpad.
250
 
        """
251
 
        path = self._guess_branch_path(branch_url, _request_factory)
252
243
        return urlutils.join('https://code.%s' % self.domain, path)
253
244
 
254
245