~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2008-03-27 06:10:18 UTC
  • mfrom: (3309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3320.
  • Revision ID: andrew.bennetts@canonical.com-20080327061018-dxztpxyv6yoeg3am
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
export BZR_LP_XMLRPC_URL=http://xmlrpc.staging.launchpad.net/bazaar/
33
33
'''
34
34
 
 
35
class InvalidLaunchpadInstance(errors.BzrError):
 
36
 
 
37
    _fmt = "%(lp_instance)s is not a valid Launchpad instance."
 
38
 
 
39
    def __init__(self, lp_instance):
 
40
        errors.BzrError.__init__(self, lp_instance=lp_instance)
 
41
 
 
42
 
35
43
class LaunchpadService(object):
36
44
    """A service to talk to Launchpad via XMLRPC.
37
 
    
 
45
 
38
46
    See http://bazaar-vcs.org/Specs/LaunchpadRpc for the methods we can call.
39
47
    """
40
48
 
41
 
    # NB: this should always end in a slash to avoid xmlrpclib appending
 
49
    # NB: these should always end in a slash to avoid xmlrpclib appending
42
50
    # '/RPC2'
43
 
    DEFAULT_SERVICE_URL = 'https://xmlrpc.launchpad.net/bazaar/'
 
51
    # We use edge as the default because:
 
52
    # Beta users get redirected to it
 
53
    # All users can use it
 
54
    # There is a bug in the launchpad side where redirection causes an OOPS.
 
55
    LAUNCHPAD_INSTANCE = {
 
56
        'production': 'https://xmlrpc.launchpad.net/bazaar/',
 
57
        'edge': 'https://xmlrpc.edge.launchpad.net/bazaar/',
 
58
        'staging': 'https://xmlrpc.staging.launchpad.net/bazaar/',
 
59
        'demo': 'https://xmlrpc.demo.launchpad.net/bazaar/',
 
60
        'dev': 'http://xmlrpc.launchpad.dev/bazaar/',
 
61
        }
 
62
    DEFAULT_SERVICE_URL = LAUNCHPAD_INSTANCE['edge']
44
63
 
45
64
    transport = None
46
65
    registrant_email = None
47
66
    registrant_password = None
48
67
 
49
68
 
50
 
    def __init__(self, transport=None):
 
69
    def __init__(self, transport=None, lp_instance=None):
51
70
        """Construct a new service talking to the launchpad rpc server"""
 
71
        self._lp_instance = lp_instance
52
72
        if transport is None:
53
73
            uri_type = urllib.splittype(self.service_url)[0]
54
74
            if uri_type == 'https':
69
89
        key = 'BZR_LP_XMLRPC_URL'
70
90
        if key in os.environ:
71
91
            return os.environ[key]
 
92
        elif self._lp_instance is not None:
 
93
            try:
 
94
                return self.LAUNCHPAD_INSTANCE[self._lp_instance]
 
95
            except KeyError:
 
96
                raise InvalidLaunchpadInstance(self._lp_instance)
72
97
        else:
73
98
            return self.DEFAULT_SERVICE_URL
74
99
 
180
205
                 author_email='',
181
206
                 product_name='',
182
207
                 ):
183
 
        assert branch_url
 
208
        if not branch_url:
 
209
            raise errors.InvalidURL(branch_url, "You need to specify a non-empty branch URL.")
184
210
        self.branch_url = branch_url
185
211
        if branch_name:
186
212
            self.branch_name = branch_name
232
258
    _authenticated = False
233
259
 
234
260
    def __init__(self, path):
235
 
        assert path
 
261
        if not path:
 
262
            raise errors.InvalidURL(path=path,
 
263
                                    extra="You must specify a product.")
236
264
        self.path = path
237
265
 
238
266
    def _request_params(self):