/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: Vincent Ladeuil
  • Date: 2011-03-14 10:11:58 UTC
  • mfrom: (5609.24.1 2.3)
  • mto: (5609.24.2 2.3)
  • mto: This revision was merged to the branch mainline in revision 5723.
  • Revision ID: v.ladeuil+lp@free.fr-20110314101158-9ojis0ftsljg3c3t
Merge bzr/2.3

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
    )
74
74
            installed_version, installed_version)
75
75
 
76
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.
77
90
LAUNCHPAD_API_URLS = {
78
 
    'production': 'https://api.launchpad.net/beta/',
79
 
    'edge': EDGE_SERVICE_ROOT,
 
91
    'production': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
 
92
        'api.launchpad.net'),
80
93
    'staging': STAGING_SERVICE_ROOT,
81
 
    'dev': 'https://api.launchpad.dev/beta/',
 
94
    'dev': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
 
95
        'api.launchpad.dev'),
82
96
    }
83
97
 
84
98
 
85
99
def _get_api_url(service):
86
100
    """Return the root URL of the Launchpad API.
87
101
 
88
 
    e.g. For the 'edge' Launchpad service, this function returns
89
 
    launchpadlib.launchpad.EDGE_SERVICE_ROOT.
 
102
    e.g. For the 'staging' Launchpad service, this function returns
 
103
    launchpadlib.launchpad.STAGING_SERVICE_ROOT.
90
104
 
91
105
    :param service: A `LaunchpadService` object.
92
106
    :return: A URL as a string.
101
115
        raise InvalidLaunchpadInstance(lp_instance)
102
116
 
103
117
 
 
118
class NoLaunchpadBranch(errors.BzrError):
 
119
    _fmt = 'No launchpad branch could be found for branch "%(url)s".'
 
120
 
 
121
    def __init__(self, branch):
 
122
        errors.BzrError.__init__(self, branch=branch, url=branch.base)
 
123
 
 
124
 
104
125
def login(service, timeout=None, proxy_info=None):
105
126
    """Log in to the Launchpad API.
106
127
 
187
208
                           'bazaar.staging.launchpad.net')
188
209
 
189
210
    @classmethod
190
 
    def from_bzr(cls, launchpad, bzr_branch):
 
211
    def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
191
212
        """Find a Launchpad branch from a bzr branch."""
192
213
        check_update = True
193
214
        for url in cls.candidate_urls(bzr_branch):
198
219
            if lp_branch is not None:
199
220
                break
200
221
        else:
 
222
            if not create_missing:
 
223
                raise NoLaunchpadBranch(bzr_branch)
201
224
            lp_branch = cls.create_now(launchpad, bzr_branch)
202
225
            check_update = False
203
226
        return cls(lp_branch, bzr_branch.base, bzr_branch, check_update)
280
303
        if lp_branch:
281
304
            return lp_branch
282
305
    raise NotLaunchpadBranch(url)
 
306
 
 
307
 
 
308
def canonical_url(object):
 
309
    """Return the canonical URL for a branch."""
 
310
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(
 
311
        str(object.self_link))
 
312
    path = '/'.join(path.split('/')[2:])
 
313
    netloc = netloc.replace('api.', 'code.')
 
314
    return urlparse.urlunparse((scheme, netloc, path, params, query,
 
315
                                fragment))