~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Gordon Tyler
  • Date: 2011-01-21 23:51:15 UTC
  • mto: This revision was merged to the branch mainline in revision 5632.
  • Revision ID: gordon@doxxx.net-20110121235115-9sdqamejot1h0481
Replace usage of format function from python 2.6 with our own very simple formatting function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    )
36
36
from bzrlib.plugins.launchpad.lp_registration import (
37
37
    InvalidLaunchpadInstance,
 
38
    NotLaunchpadBranch,
38
39
    )
39
40
 
40
41
try:
46
47
    STAGING_SERVICE_ROOT,
47
48
    Launchpad,
48
49
    )
 
50
from launchpadlib import uris
49
51
 
 
52
LPNET_SERVICE_ROOT = getattr(uris, 'LPNET_SERVICE_ROOT',
 
53
                             'https://api.launchpad.net/beta/')
 
54
QASTAGING_SERVICE_ROOT = getattr(uris, 'QASTAGING_SERVICE_ROOT',
 
55
                                 'https://api.qastaging.launchpad.net/')
50
56
 
51
57
# Declare the minimum version of launchpadlib that we need in order to work.
52
58
# 1.5.1 is the version of launchpadlib packaged in Ubuntu 9.10, the most
73
79
            installed_version, installed_version)
74
80
 
75
81
 
76
 
# The older versions of launchpadlib only provided service root constants for
77
 
# edge and staging, whilst newer versions drop edge. Therefore service root
78
 
# URIs for which we do not always have constants are derived from the staging
79
 
# one, which does always exist.
80
 
#
81
 
# It is necessary to derive, rather than use hardcoded URIs because
82
 
# launchpadlib <= 1.5.4 requires service root URIs that end in a path of
83
 
# /beta/, whilst launchpadlib >= 1.5.5 requires service root URIs with no path
84
 
# info.
85
 
#
86
 
# Once we have a hard dependency on launchpadlib >= 1.5.4 we can replace all of
87
 
# bzr's local knowledge of individual Launchpad instances with use of the
88
 
# launchpadlib.uris module.
89
82
LAUNCHPAD_API_URLS = {
90
 
    'production': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
91
 
        'api.launchpad.net'),
92
 
    'qastaging': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
93
 
        'api.qastaging.launchpad.net'),
 
83
    'production': LPNET_SERVICE_ROOT,
 
84
    'qastaging': QASTAGING_SERVICE_ROOT,
94
85
    'staging': STAGING_SERVICE_ROOT,
95
 
    'dev': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
96
 
        'api.launchpad.dev'),
 
86
    'dev': 'https://api.launchpad.dev/beta/',
97
87
    }
98
88
 
99
89
 
196
186
        url = bzr_branch.get_push_location()
197
187
        if url is not None:
198
188
            yield url
199
 
        url = bzr_branch.get_parent()
200
 
        if url is not None:
201
 
            yield url
202
189
        yield bzr_branch.base
203
190
 
204
191
    @staticmethod
207
194
        if str(launchpad._root_uri) == STAGING_SERVICE_ROOT:
208
195
            return url.replace('bazaar.launchpad.net',
209
196
                               'bazaar.staging.launchpad.net')
210
 
        elif str(launchpad._root_uri) == LAUNCHPAD_API_URLS['qastaging']:
 
197
        elif str(launchpad._root_uri) == QASTAGING_SERVICE_ROOT:
211
198
            return url.replace('bazaar.launchpad.net',
212
199
                               'bazaar.qastaging.launchpad.net')
213
200
        return url
247
234
        """Return the 'LaunchpadBranch' for the target of this one."""
248
235
        lp_branch = self.lp
249
236
        if lp_branch.project is not None:
250
 
            dev_focus = lp_branch.project.development_focus
 
237
            dev_focus = lp_branch.project.development_focus.branch
251
238
            if dev_focus is None:
252
239
                raise errors.BzrError('%s has no development focus.' %
253
240
                                  lp_branch.bzr_identity)
296
283
        return self.bzr.repository.revision_tree(lca)
297
284
 
298
285
 
 
286
def load_branch(launchpad, branch):
 
287
    """Return the launchpadlib Branch object corresponding to 'branch'.
 
288
 
 
289
    :param launchpad: The root `Launchpad` object from launchpadlib.
 
290
    :param branch: A `bzrlib.branch.Branch`.
 
291
    :raise NotLaunchpadBranch: If we cannot determine the Launchpad URL of
 
292
        `branch`.
 
293
    :return: A launchpadlib Branch object.
 
294
    """
 
295
    # XXX: This duplicates the "What are possible URLs for the branch that
 
296
    # Launchpad might recognize" logic found in cmd_lp_open.
 
297
 
 
298
    # XXX: This makes multiple roundtrips to Launchpad for what is
 
299
    # conceptually a single operation -- get me the branches that match these
 
300
    # URLs. Unfortunately, Launchpad's support for such operations is poor, so
 
301
    # we have to allow multiple roundtrips.
 
302
    for url in branch.get_public_branch(), branch.get_push_location():
 
303
        lp_branch = launchpad.branches.getByUrl(url=url)
 
304
        if lp_branch:
 
305
            return lp_branch
 
306
    raise NotLaunchpadBranch(url)
 
307
 
 
308
 
299
309
def canonical_url(object):
300
310
    """Return the canonical URL for a branch."""
301
311
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(