~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2010-11-24 16:01:57 UTC
  • mfrom: (4597.13.7 cleanup)
  • mto: This revision was merged to the branch mainline in revision 5558.
  • Revision ID: v.ladeuil+lp@free.fr-20101124160157-kieuslo7wj9abdmb
Merge cleanup into 638451-malformed

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,
47
48
    STAGING_SERVICE_ROOT,
48
49
    Launchpad,
49
50
    )
 
51
try:
 
52
    from launchpadlib.uris import LPNET_SERVICE_ROOT
 
53
except ImportError:
 
54
    LPNET_SERVICE_ROOT = 'https://api.launchpad.net/beta/'
50
55
 
51
56
 
52
57
# Declare the minimum version of launchpadlib that we need in order to work.
75
80
 
76
81
 
77
82
LAUNCHPAD_API_URLS = {
78
 
    'production': 'https://api.launchpad.net/beta/',
 
83
    'production': LPNET_SERVICE_ROOT,
79
84
    'edge': EDGE_SERVICE_ROOT,
80
85
    'staging': STAGING_SERVICE_ROOT,
81
86
    'dev': 'https://api.launchpad.dev/beta/',
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
 
187
199
                           'bazaar.staging.launchpad.net')
188
200
 
189
201
    @classmethod
190
 
    def from_bzr(cls, launchpad, bzr_branch):
 
202
    def from_bzr(cls, launchpad, bzr_branch, create_missing=True):
191
203
        """Find a Launchpad branch from a bzr branch."""
192
204
        check_update = True
193
205
        for url in cls.candidate_urls(bzr_branch):
198
210
            if lp_branch is not None:
199
211
                break
200
212
        else:
 
213
            if not create_missing:
 
214
                raise NoLaunchpadBranch(bzr_branch)
201
215
            lp_branch = cls.create_now(launchpad, bzr_branch)
202
216
            check_update = False
203
217
        return cls(lp_branch, bzr_branch.base, bzr_branch, check_update)
280
294
        if lp_branch:
281
295
            return lp_branch
282
296
    raise NotLaunchpadBranch(url)
 
297
 
 
298
 
 
299
def canonical_url(object):
 
300
    """Return the canonical URL for a branch."""
 
301
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(
 
302
        str(object.self_link))
 
303
    path = '/'.join(path.split('/')[2:])
 
304
    netloc = netloc.replace('api.', 'code.')
 
305
    return urlparse.urlunparse((scheme, netloc, path, params, query,
 
306
                                fragment))