~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-11 04:33:12 UTC
  • mto: (5582.12.2 weave-plugin)
  • mto: This revision was merged to the branch mainline in revision 5718.
  • Revision ID: jelmer@samba.org-20110111043312-g4wx6iuf9662f36d
Move weave formats into bzrlib.plugins.weave_fmt.

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
try:
 
51
    from launchpadlib.uris import LPNET_SERVICE_ROOT
 
52
except ImportError:
 
53
    LPNET_SERVICE_ROOT = 'https://api.launchpad.net/beta/'
50
54
 
51
55
 
52
56
# Declare the minimum version of launchpadlib that we need in order to work.
75
79
 
76
80
 
77
81
LAUNCHPAD_API_URLS = {
78
 
    'production': 'https://api.launchpad.net/beta/',
79
 
    'edge': EDGE_SERVICE_ROOT,
 
82
    'production': LPNET_SERVICE_ROOT,
80
83
    'staging': STAGING_SERVICE_ROOT,
81
84
    'dev': 'https://api.launchpad.dev/beta/',
82
85
    }
85
88
def _get_api_url(service):
86
89
    """Return the root URL of the Launchpad API.
87
90
 
88
 
    e.g. For the 'edge' Launchpad service, this function returns
89
 
    launchpadlib.launchpad.EDGE_SERVICE_ROOT.
 
91
    e.g. For the 'staging' Launchpad service, this function returns
 
92
    launchpadlib.launchpad.STAGING_SERVICE_ROOT.
90
93
 
91
94
    :param service: A `LaunchpadService` object.
92
95
    :return: A URL as a string.
101
104
        raise InvalidLaunchpadInstance(lp_instance)
102
105
 
103
106
 
 
107
class NoLaunchpadBranch(errors.BzrError):
 
108
    _fmt = 'No launchpad branch could be found for branch "%(url)s".'
 
109
 
 
110
    def __init__(self, branch):
 
111
        errors.BzrError.__init__(self, branch=branch, url=branch.base)
 
112
 
 
113
 
104
114
def login(service, timeout=None, proxy_info=None):
105
115
    """Log in to the Launchpad API.
106
116
 
187
197
                           'bazaar.staging.launchpad.net')
188
198
 
189
199
    @classmethod
190
 
    def from_bzr(cls, launchpad, bzr_branch):
 
200
    def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
191
201
        """Find a Launchpad branch from a bzr branch."""
192
202
        check_update = True
193
203
        for url in cls.candidate_urls(bzr_branch):
198
208
            if lp_branch is not None:
199
209
                break
200
210
        else:
 
211
            if not create_missing:
 
212
                raise NoLaunchpadBranch(bzr_branch)
201
213
            lp_branch = cls.create_now(launchpad, bzr_branch)
202
214
            check_update = False
203
215
        return cls(lp_branch, bzr_branch.base, bzr_branch, check_update)
280
292
        if lp_branch:
281
293
            return lp_branch
282
294
    raise NotLaunchpadBranch(url)
 
295
 
 
296
 
 
297
def canonical_url(object):
 
298
    """Return the canonical URL for a branch."""
 
299
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(
 
300
        str(object.self_link))
 
301
    path = '/'.join(path.split('/')[2:])
 
302
    netloc = netloc.replace('api.', 'code.')
 
303
    return urlparse.urlunparse((scheme, netloc, path, params, query,
 
304
                                fragment))