~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2011-01-11 18:10:55 UTC
  • mto: This revision was merged to the branch mainline in revision 5596.
  • Revision ID: john@arbash-meinel.com-20110111181055-d79p02kioxcg4f7l
Change tuned_gzip.GzipFile to be deprecated

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
try:
 
51
    from launchpadlib.uris import LPNET_SERVICE_ROOT
 
52
except ImportError:
 
53
    LPNET_SERVICE_ROOT = 'https://api.launchpad.net/beta/'
49
54
 
50
55
 
51
56
# Declare the minimum version of launchpadlib that we need in order to work.
73
78
            installed_version, installed_version)
74
79
 
75
80
 
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
81
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'),
 
82
    'production': LPNET_SERVICE_ROOT,
94
83
    'staging': STAGING_SERVICE_ROOT,
95
 
    'dev': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
96
 
        'api.launchpad.dev'),
 
84
    'dev': 'https://api.launchpad.dev/beta/',
97
85
    }
98
86
 
99
87
 
196
184
        url = bzr_branch.get_push_location()
197
185
        if url is not None:
198
186
            yield url
199
 
        url = bzr_branch.get_parent()
200
 
        if url is not None:
201
 
            yield url
202
187
        yield bzr_branch.base
203
188
 
204
189
    @staticmethod
205
190
    def tweak_url(url, launchpad):
206
191
        """Adjust a URL to work with staging, if needed."""
207
 
        if str(launchpad._root_uri) == STAGING_SERVICE_ROOT:
208
 
            return url.replace('bazaar.launchpad.net',
209
 
                               'bazaar.staging.launchpad.net')
210
 
        elif str(launchpad._root_uri) == LAUNCHPAD_API_URLS['qastaging']:
211
 
            return url.replace('bazaar.launchpad.net',
212
 
                               'bazaar.qastaging.launchpad.net')
213
 
        return url
 
192
        if str(launchpad._root_uri) != STAGING_SERVICE_ROOT:
 
193
            return url
 
194
        if url is None:
 
195
            return None
 
196
        return url.replace('bazaar.launchpad.net',
 
197
                           'bazaar.staging.launchpad.net')
214
198
 
215
199
    @classmethod
216
200
    def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
243
227
            raise errors.BzrError('%s is not registered on Launchpad' % url)
244
228
        return lp_branch
245
229
 
246
 
    def get_target(self):
247
 
        """Return the 'LaunchpadBranch' for the target of this one."""
 
230
    def get_dev_focus(self):
 
231
        """Return the 'LaunchpadBranch' for the dev focus of this one."""
248
232
        lp_branch = self.lp
249
 
        if lp_branch.project is not None:
250
 
            dev_focus = lp_branch.project.development_focus
251
 
            if dev_focus is None:
252
 
                raise errors.BzrError('%s has no development focus.' %
253
 
                                  lp_branch.bzr_identity)
254
 
            target = dev_focus.branch
255
 
            if target is None:
256
 
                raise errors.BzrError('development focus %s has no branch.' % dev_focus)
257
 
        elif lp_branch.sourcepackage is not None:
258
 
            target = lp_branch.sourcepackage.getBranch(pocket="Release")
259
 
            if target is None:
260
 
                raise errors.BzrError('source package %s has no branch.' %
261
 
                                      lp_branch.sourcepackage)
262
 
        else:
263
 
            raise errors.BzrError('%s has no associated product or source package.' %
264
 
                                  lp_branch.bzr_identity)
265
 
        return LaunchpadBranch(target, target.bzr_identity)
 
233
        if lp_branch.project is None:
 
234
            raise errors.BzrError('%s has no product.' %
 
235
                                  lp_branch.bzr_identity)
 
236
        dev_focus = lp_branch.project.development_focus.branch
 
237
        if dev_focus is None:
 
238
            raise errors.BzrError('%s has no development focus.' %
 
239
                                  lp_branch.bzr_identity)
 
240
        return LaunchpadBranch(dev_focus, dev_focus.bzr_identity)
266
241
 
267
242
    def update_lp(self):
268
243
        """Update the Launchpad copy of this branch."""
296
271
        return self.bzr.repository.revision_tree(lca)
297
272
 
298
273
 
 
274
def load_branch(launchpad, branch):
 
275
    """Return the launchpadlib Branch object corresponding to 'branch'.
 
276
 
 
277
    :param launchpad: The root `Launchpad` object from launchpadlib.
 
278
    :param branch: A `bzrlib.branch.Branch`.
 
279
    :raise NotLaunchpadBranch: If we cannot determine the Launchpad URL of
 
280
        `branch`.
 
281
    :return: A launchpadlib Branch object.
 
282
    """
 
283
    # XXX: This duplicates the "What are possible URLs for the branch that
 
284
    # Launchpad might recognize" logic found in cmd_lp_open.
 
285
 
 
286
    # XXX: This makes multiple roundtrips to Launchpad for what is
 
287
    # conceptually a single operation -- get me the branches that match these
 
288
    # URLs. Unfortunately, Launchpad's support for such operations is poor, so
 
289
    # we have to allow multiple roundtrips.
 
290
    for url in branch.get_public_branch(), branch.get_push_location():
 
291
        lp_branch = launchpad.branches.getByUrl(url=url)
 
292
        if lp_branch:
 
293
            return lp_branch
 
294
    raise NotLaunchpadBranch(url)
 
295
 
 
296
 
299
297
def canonical_url(object):
300
298
    """Return the canonical URL for a branch."""
301
299
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(