~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-01-19 18:40:15 UTC
  • mfrom: (5622 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5624.
  • Revision ID: jelmer@samba.org-20110119184015-ahycpz0yduideif0
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    STAGING_SERVICE_ROOT,
48
48
    Launchpad,
49
49
    )
50
 
try:
51
 
    from launchpadlib.uris import LPNET_SERVICE_ROOT
52
 
except ImportError:
53
 
    LPNET_SERVICE_ROOT = 'https://api.launchpad.net/beta/'
 
50
from launchpadlib import uris
54
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/')
55
56
 
56
57
# Declare the minimum version of launchpadlib that we need in order to work.
57
58
# 1.5.1 is the version of launchpadlib packaged in Ubuntu 9.10, the most
80
81
 
81
82
LAUNCHPAD_API_URLS = {
82
83
    'production': LPNET_SERVICE_ROOT,
 
84
    'qastaging': QASTAGING_SERVICE_ROOT,
83
85
    'staging': STAGING_SERVICE_ROOT,
84
86
    'dev': 'https://api.launchpad.dev/beta/',
85
87
    }
189
191
    @staticmethod
190
192
    def tweak_url(url, launchpad):
191
193
        """Adjust a URL to work with staging, if needed."""
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')
 
194
        if str(launchpad._root_uri) == STAGING_SERVICE_ROOT:
 
195
            return url.replace('bazaar.launchpad.net',
 
196
                               'bazaar.staging.launchpad.net')
 
197
        elif str(launchpad._root_uri) == QASTAGING_SERVICE_ROOT:
 
198
            return url.replace('bazaar.launchpad.net',
 
199
                               'bazaar.qastaging.launchpad.net')
 
200
        return url
198
201
 
199
202
    @classmethod
200
203
    def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
227
230
            raise errors.BzrError('%s is not registered on Launchpad' % url)
228
231
        return lp_branch
229
232
 
230
 
    def get_dev_focus(self):
231
 
        """Return the 'LaunchpadBranch' for the dev focus of this one."""
 
233
    def get_target(self):
 
234
        """Return the 'LaunchpadBranch' for the target of this one."""
232
235
        lp_branch = self.lp
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)
 
236
        if lp_branch.project is not None:
 
237
            dev_focus = lp_branch.project.development_focus.branch
 
238
            if dev_focus is None:
 
239
                raise errors.BzrError('%s has no development focus.' %
 
240
                                  lp_branch.bzr_identity)
 
241
            target = dev_focus.branch
 
242
            if target is None:
 
243
                raise errors.BzrError('development focus %s has no branch.' % dev_focus)
 
244
        elif lp_branch.sourcepackage is not None:
 
245
            target = lp_branch.sourcepackage.getBranch(pocket="Release")
 
246
            if target is None:
 
247
                raise errors.BzrError('source package %s has no branch.' %
 
248
                                      lp_branch.sourcepackage)
 
249
        else:
 
250
            raise errors.BzrError('%s has no associated product or source package.' %
 
251
                                  lp_branch.bzr_identity)
 
252
        return LaunchpadBranch(target, target.bzr_identity)
241
253
 
242
254
    def update_lp(self):
243
255
        """Update the Launchpad copy of this branch."""