74
74
installed_version, installed_version)
77
# The older versions of launchpadlib only provided service root constants for
78
# edge and staging, whilst newer versions drop edge. Therefore service root
79
# URIs for which we do not always have constants are derived from the staging
80
# one, which does always exist.
82
# It is necessary to derive, rather than use hardcoded URIs because
83
# launchpadlib <= 1.5.4 requires service root URIs that end in a path of
84
# /beta/, whilst launchpadlib >= 1.5.5 requires service root URIs with no path
87
# Once we have a hard dependency on launchpadlib >= 1.5.4 we can replace all of
88
# bzr's local knowledge of individual Launchpad instances with use of the
89
# launchpadlib.uris module.
77
90
LAUNCHPAD_API_URLS = {
78
'production': 'https://api.launchpad.net/beta/',
79
'edge': EDGE_SERVICE_ROOT,
91
'production': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
80
93
'staging': STAGING_SERVICE_ROOT,
81
'dev': 'https://api.launchpad.dev/beta/',
94
'dev': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
85
99
def _get_api_url(service):
86
100
"""Return the root URL of the Launchpad API.
88
e.g. For the 'edge' Launchpad service, this function returns
89
launchpadlib.launchpad.EDGE_SERVICE_ROOT.
102
e.g. For the 'staging' Launchpad service, this function returns
103
launchpadlib.launchpad.STAGING_SERVICE_ROOT.
91
105
:param service: A `LaunchpadService` object.
92
106
:return: A URL as a string.
101
115
raise InvalidLaunchpadInstance(lp_instance)
118
class NoLaunchpadBranch(errors.BzrError):
119
_fmt = 'No launchpad branch could be found for branch "%(url)s".'
121
def __init__(self, branch):
122
errors.BzrError.__init__(self, branch=branch, url=branch.base)
104
125
def login(service, timeout=None, proxy_info=None):
105
126
"""Log in to the Launchpad API.
187
208
'bazaar.staging.launchpad.net')
190
def from_bzr(cls, launchpad, bzr_branch):
211
def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
191
212
"""Find a Launchpad branch from a bzr branch."""
192
213
check_update = True
193
214
for url in cls.candidate_urls(bzr_branch):
198
219
if lp_branch is not None:
222
if not create_missing:
223
raise NoLaunchpadBranch(bzr_branch)
201
224
lp_branch = cls.create_now(launchpad, bzr_branch)
202
225
check_update = False
203
226
return cls(lp_branch, bzr_branch.base, bzr_branch, check_update)
282
305
raise NotLaunchpadBranch(url)
308
def canonical_url(object):
309
"""Return the canonical URL for a branch."""
310
scheme, netloc, path, params, query, fragment = urlparse.urlparse(
311
str(object.self_link))
312
path = '/'.join(path.split('/')[2:])
313
netloc = netloc.replace('api.', 'code.')
314
return urlparse.urlunparse((scheme, netloc, path, params, query,