~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

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,
39
38
    )
40
39
 
41
40
try:
90
89
LAUNCHPAD_API_URLS = {
91
90
    'production': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
92
91
        'api.launchpad.net'),
 
92
    'qastaging': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
 
93
        'api.qastaging.launchpad.net'),
93
94
    'staging': STAGING_SERVICE_ROOT,
94
95
    'dev': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
95
96
        'api.launchpad.dev'),
195
196
        url = bzr_branch.get_push_location()
196
197
        if url is not None:
197
198
            yield url
 
199
        url = bzr_branch.get_parent()
 
200
        if url is not None:
 
201
            yield url
198
202
        yield bzr_branch.base
199
203
 
200
204
    @staticmethod
201
205
    def tweak_url(url, launchpad):
202
206
        """Adjust a URL to work with staging, if needed."""
203
 
        if str(launchpad._root_uri) != STAGING_SERVICE_ROOT:
204
 
            return url
205
 
        if url is None:
206
 
            return None
207
 
        return url.replace('bazaar.launchpad.net',
208
 
                           'bazaar.staging.launchpad.net')
 
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
209
214
 
210
215
    @classmethod
211
216
    def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
238
243
            raise errors.BzrError('%s is not registered on Launchpad' % url)
239
244
        return lp_branch
240
245
 
241
 
    def get_dev_focus(self):
242
 
        """Return the 'LaunchpadBranch' for the dev focus of this one."""
 
246
    def get_target(self):
 
247
        """Return the 'LaunchpadBranch' for the target of this one."""
243
248
        lp_branch = self.lp
244
 
        if lp_branch.project is None:
245
 
            raise errors.BzrError('%s has no product.' %
246
 
                                  lp_branch.bzr_identity)
247
 
        dev_focus = lp_branch.project.development_focus.branch
248
 
        if dev_focus is None:
249
 
            raise errors.BzrError('%s has no development focus.' %
250
 
                                  lp_branch.bzr_identity)
251
 
        return LaunchpadBranch(dev_focus, dev_focus.bzr_identity)
 
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)
252
266
 
253
267
    def update_lp(self):
254
268
        """Update the Launchpad copy of this branch."""
282
296
        return self.bzr.repository.revision_tree(lca)
283
297
 
284
298
 
285
 
def load_branch(launchpad, branch):
286
 
    """Return the launchpadlib Branch object corresponding to 'branch'.
287
 
 
288
 
    :param launchpad: The root `Launchpad` object from launchpadlib.
289
 
    :param branch: A `bzrlib.branch.Branch`.
290
 
    :raise NotLaunchpadBranch: If we cannot determine the Launchpad URL of
291
 
        `branch`.
292
 
    :return: A launchpadlib Branch object.
293
 
    """
294
 
    # XXX: This duplicates the "What are possible URLs for the branch that
295
 
    # Launchpad might recognize" logic found in cmd_lp_open.
296
 
 
297
 
    # XXX: This makes multiple roundtrips to Launchpad for what is
298
 
    # conceptually a single operation -- get me the branches that match these
299
 
    # URLs. Unfortunately, Launchpad's support for such operations is poor, so
300
 
    # we have to allow multiple roundtrips.
301
 
    for url in branch.get_public_branch(), branch.get_push_location():
302
 
        lp_branch = launchpad.branches.getByUrl(url=url)
303
 
        if lp_branch:
304
 
            return lp_branch
305
 
    raise NotLaunchpadBranch(url)
306
 
 
307
 
 
308
299
def canonical_url(object):
309
300
    """Return the canonical URL for a branch."""
310
301
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(