/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

  • Committer: John Arbash Meinel
  • Date: 2011-01-25 22:54:08 UTC
  • mto: This revision was merged to the branch mainline in revision 5636.
  • Revision ID: john@arbash-meinel.com-20110125225408-w5b5mmh117q4jjz1
Implement a reset-to-known-state ability for DirState.

Use this in reset_state(). Allow it to use header information if it can
be parsed, otherwise allow us to pass in the information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import os
25
25
import re
 
26
import urlparse
26
27
 
27
28
from bzrlib import (
28
29
    branch,
43
44
    raise errors.DependencyNotPresent('launchpadlib', e)
44
45
 
45
46
from launchpadlib.launchpad import (
46
 
    EDGE_SERVICE_ROOT,
47
47
    STAGING_SERVICE_ROOT,
48
48
    Launchpad,
49
49
    )
 
50
from launchpadlib import uris
50
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/')
51
56
 
52
57
# Declare the minimum version of launchpadlib that we need in order to work.
53
58
# 1.5.1 is the version of launchpadlib packaged in Ubuntu 9.10, the most
75
80
 
76
81
 
77
82
LAUNCHPAD_API_URLS = {
78
 
    'production': 'https://api.launchpad.net/beta/',
79
 
    'edge': EDGE_SERVICE_ROOT,
 
83
    'production': LPNET_SERVICE_ROOT,
 
84
    'qastaging': QASTAGING_SERVICE_ROOT,
80
85
    'staging': STAGING_SERVICE_ROOT,
81
86
    'dev': 'https://api.launchpad.dev/beta/',
82
87
    }
85
90
def _get_api_url(service):
86
91
    """Return the root URL of the Launchpad API.
87
92
 
88
 
    e.g. For the 'edge' Launchpad service, this function returns
89
 
    launchpadlib.launchpad.EDGE_SERVICE_ROOT.
 
93
    e.g. For the 'staging' Launchpad service, this function returns
 
94
    launchpadlib.launchpad.STAGING_SERVICE_ROOT.
90
95
 
91
96
    :param service: A `LaunchpadService` object.
92
97
    :return: A URL as a string.
101
106
        raise InvalidLaunchpadInstance(lp_instance)
102
107
 
103
108
 
 
109
class NoLaunchpadBranch(errors.BzrError):
 
110
    _fmt = 'No launchpad branch could be found for branch "%(url)s".'
 
111
 
 
112
    def __init__(self, branch):
 
113
        errors.BzrError.__init__(self, branch=branch, url=branch.base)
 
114
 
 
115
 
104
116
def login(service, timeout=None, proxy_info=None):
105
117
    """Log in to the Launchpad API.
106
118
 
179
191
    @staticmethod
180
192
    def tweak_url(url, launchpad):
181
193
        """Adjust a URL to work with staging, if needed."""
182
 
        if str(launchpad._root_uri) != STAGING_SERVICE_ROOT:
183
 
            return url
184
 
        if url is None:
185
 
            return None
186
 
        return url.replace('bazaar.launchpad.net',
187
 
                           '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
188
201
 
189
202
    @classmethod
190
 
    def from_bzr(cls, launchpad, bzr_branch):
 
203
    def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
191
204
        """Find a Launchpad branch from a bzr branch."""
192
205
        check_update = True
193
206
        for url in cls.candidate_urls(bzr_branch):
198
211
            if lp_branch is not None:
199
212
                break
200
213
        else:
 
214
            if not create_missing:
 
215
                raise NoLaunchpadBranch(bzr_branch)
201
216
            lp_branch = cls.create_now(launchpad, bzr_branch)
202
217
            check_update = False
203
218
        return cls(lp_branch, bzr_branch.base, bzr_branch, check_update)
215
230
            raise errors.BzrError('%s is not registered on Launchpad' % url)
216
231
        return lp_branch
217
232
 
218
 
    def get_dev_focus(self):
219
 
        """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."""
220
235
        lp_branch = self.lp
221
 
        if lp_branch.project is None:
222
 
            raise errors.BzrError('%s has no product.' %
223
 
                                  lp_branch.bzr_identity)
224
 
        dev_focus = lp_branch.project.development_focus.branch
225
 
        if dev_focus is None:
226
 
            raise errors.BzrError('%s has no development focus.' %
227
 
                                  lp_branch.bzr_identity)
228
 
        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)
229
253
 
230
254
    def update_lp(self):
231
255
        """Update the Launchpad copy of this branch."""
280
304
        if lp_branch:
281
305
            return lp_branch
282
306
    raise NotLaunchpadBranch(url)
 
307
 
 
308
 
 
309
def canonical_url(object):
 
310
    """Return the canonical URL for a branch."""
 
311
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(
 
312
        str(object.self_link))
 
313
    path = '/'.join(path.split('/')[2:])
 
314
    netloc = netloc.replace('api.', 'code.')
 
315
    return urlparse.urlunparse((scheme, netloc, path, params, query,
 
316
                                fragment))