32
32
export BZR_LP_XMLRPC_URL=http://xmlrpc.staging.launchpad.net/bazaar/
35
class InvalidLaunchpadInstance(errors.BzrError):
37
_fmt = "%(lp_instance)s is not a valid Launchpad instance."
39
def __init__(self, lp_instance):
40
errors.BzrError.__init__(self, lp_instance=lp_instance)
35
43
class LaunchpadService(object):
36
44
"""A service to talk to Launchpad via XMLRPC.
38
46
See http://bazaar-vcs.org/Specs/LaunchpadRpc for the methods we can call.
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
43
# We use edge because:
51
# We use edge as the default because:
44
52
# Beta users get redirected to it
45
53
# All users can use it
46
54
# There is a bug in the launchpad side where redirection causes an OOPS.
47
DEFAULT_SERVICE_URL = 'https://xmlrpc.edge.launchpad.net/bazaar/'
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/',
62
DEFAULT_SERVICE_URL = LAUNCHPAD_INSTANCE['edge']
50
65
registrant_email = None
51
66
registrant_password = None
54
def __init__(self, transport=None):
69
def __init__(self, transport=None, lp_instance=None):
55
70
"""Construct a new service talking to the launchpad rpc server"""
71
self._lp_instance = lp_instance
56
72
if transport is None:
57
73
uri_type = urllib.splittype(self.service_url)[0]
58
74
if uri_type == 'https':
73
89
key = 'BZR_LP_XMLRPC_URL'
74
90
if key in os.environ:
75
91
return os.environ[key]
92
elif self._lp_instance is not None:
94
return self.LAUNCHPAD_INSTANCE[self._lp_instance]
96
raise InvalidLaunchpadInstance(self._lp_instance)
77
98
return self.DEFAULT_SERVICE_URL