/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

MergeĀ lp:bzr.

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/'
54
50
 
55
51
 
56
52
# Declare the minimum version of launchpadlib that we need in order to work.
78
74
            installed_version, installed_version)
79
75
 
80
76
 
 
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.
 
81
#
 
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
 
85
# info.
 
86
#
 
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.
81
90
LAUNCHPAD_API_URLS = {
82
 
    'production': LPNET_SERVICE_ROOT,
 
91
    'production': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
 
92
        'api.launchpad.net'),
 
93
    'qastaging': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
 
94
        'api.qastaging.launchpad.net'),
83
95
    'staging': STAGING_SERVICE_ROOT,
84
 
    'dev': 'https://api.launchpad.dev/beta/',
 
96
    'dev': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
 
97
        'api.launchpad.dev'),
85
98
    }
86
99
 
87
100
 
189
202
    @staticmethod
190
203
    def tweak_url(url, launchpad):
191
204
        """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')
 
205
        if str(launchpad._root_uri) == STAGING_SERVICE_ROOT:
 
206
            return url.replace('bazaar.launchpad.net',
 
207
                               'bazaar.staging.launchpad.net')
 
208
        elif str(launchpad._root_uri) == LAUNCHPAD_API_URLS['qastaging']:
 
209
            return url.replace('bazaar.launchpad.net',
 
210
                               'bazaar.qastaging.launchpad.net')
 
211
        return url
198
212
 
199
213
    @classmethod
200
214
    def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
227
241
            raise errors.BzrError('%s is not registered on Launchpad' % url)
228
242
        return lp_branch
229
243
 
230
 
    def get_dev_focus(self):
231
 
        """Return the 'LaunchpadBranch' for the dev focus of this one."""
 
244
    def get_target(self):
 
245
        """Return the 'LaunchpadBranch' for the target of this one."""
232
246
        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)
 
247
        if lp_branch.project is not None:
 
248
            dev_focus = lp_branch.project.development_focus
 
249
            if dev_focus is None:
 
250
                raise errors.BzrError('%s has no development focus.' %
 
251
                                  lp_branch.bzr_identity)
 
252
            target = dev_focus.branch
 
253
            if target is None:
 
254
                raise errors.BzrError('development focus %s has no branch.' % dev_focus)
 
255
        elif lp_branch.sourcepackage is not None:
 
256
            target = lp_branch.sourcepackage.getBranch(pocket="Release")
 
257
            if target is None:
 
258
                raise errors.BzrError('source package %s has no branch.' %
 
259
                                      lp_branch.sourcepackage)
 
260
        else:
 
261
            raise errors.BzrError('%s has no associated product or source package.' %
 
262
                                  lp_branch.bzr_identity)
 
263
        return LaunchpadBranch(target, target.bzr_identity)
241
264
 
242
265
    def update_lp(self):
243
266
        """Update the Launchpad copy of this branch."""