~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Haw Loeung (hloeung)
  • Date: 2012-07-24 12:53:36 UTC
  • mfrom: (6541 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6542.
  • Revision ID: haw.loeung@canonical.com-20120724125336-r3wzxm02lyec7jm6
[hloeung] Merged with upstream resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
49
49
    STAGING_SERVICE_ROOT,
50
50
    Launchpad,
51
51
    )
52
 
 
 
52
from launchpadlib import uris
53
53
 
54
54
# Declare the minimum version of launchpadlib that we need in order to work.
55
 
# 1.5.1 is the version of launchpadlib packaged in Ubuntu 9.10, the most
56
 
# recent Ubuntu release at the time of writing.
57
 
MINIMUM_LAUNCHPADLIB_VERSION = (1, 5, 1)
 
55
# 1.6.0 is the version of launchpadlib packaged in Ubuntu 10.04, the most
 
56
# recent Ubuntu LTS release supported on the desktop at the time of writing.
 
57
MINIMUM_LAUNCHPADLIB_VERSION = (1, 6, 0)
58
58
 
59
59
 
60
60
def get_cache_directory():
76
76
            installed_version, installed_version)
77
77
 
78
78
 
79
 
# The older versions of launchpadlib only provided service root constants for
80
 
# edge and staging, whilst newer versions drop edge. Therefore service root
81
 
# URIs for which we do not always have constants are derived from the staging
82
 
# one, which does always exist.
83
 
#
84
 
# It is necessary to derive, rather than use hardcoded URIs because
85
 
# launchpadlib <= 1.5.4 requires service root URIs that end in a path of
86
 
# /beta/, whilst launchpadlib >= 1.5.5 requires service root URIs with no path
87
 
# info.
88
 
#
89
 
# Once we have a hard dependency on launchpadlib >= 1.5.4 we can replace all of
90
 
# bzr's local knowledge of individual Launchpad instances with use of the
91
 
# launchpadlib.uris module.
92
 
LAUNCHPAD_API_URLS = {
93
 
    'production': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
94
 
        'api.launchpad.net'),
95
 
    'qastaging': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
96
 
        'api.qastaging.launchpad.net'),
97
 
    'staging': STAGING_SERVICE_ROOT,
98
 
    'dev': STAGING_SERVICE_ROOT.replace('api.staging.launchpad.net',
99
 
        'api.launchpad.dev'),
100
 
    }
 
79
def lookup_service_root(service_root):
 
80
    try:
 
81
        return uris.lookup_service_root(service_root)
 
82
    except ValueError:
 
83
        if service_root != 'qastaging':
 
84
            raise
 
85
        staging_root = uris.lookup_service_root('staging')
 
86
        return staging_root.replace('staging', 'qastaging')
101
87
 
102
88
 
103
89
def _get_api_url(service):
114
100
    else:
115
101
        lp_instance = service._lp_instance
116
102
    try:
117
 
        return LAUNCHPAD_API_URLS[lp_instance]
118
 
    except KeyError:
 
103
        return lookup_service_root(lp_instance)
 
104
    except ValueError:
119
105
        raise InvalidLaunchpadInstance(lp_instance)
120
106
 
121
107
 
126
112
        errors.BzrError.__init__(self, branch=branch, url=branch.base)
127
113
 
128
114
 
129
 
def login(service, timeout=None, proxy_info=None):
 
115
def login(service, timeout=None, proxy_info=None,
 
116
          version=Launchpad.DEFAULT_VERSION):
130
117
    """Log in to the Launchpad API.
131
118
 
132
119
    :return: The root `Launchpad` object from launchpadlib.
134
121
    cache_directory = get_cache_directory()
135
122
    launchpad = Launchpad.login_with(
136
123
        'bzr', _get_api_url(service), cache_directory, timeout=timeout,
137
 
        proxy_info=proxy_info)
138
 
    # XXX: Work-around a minor security bug in launchpadlib 1.5.1, which would
139
 
    # create this directory with default umask.
 
124
        proxy_info=proxy_info, version=version)
 
125
    # XXX: Work-around a minor security bug in launchpadlib < 1.6.3, which
 
126
    # would create this directory with default umask.
140
127
    osutils.chmod_if_possible(cache_directory, 0700)
141
128
    return launchpad
142
129
 
210
197
        if str(launchpad._root_uri) == STAGING_SERVICE_ROOT:
211
198
            return url.replace('bazaar.launchpad.net',
212
199
                               'bazaar.staging.launchpad.net')
213
 
        elif str(launchpad._root_uri) == LAUNCHPAD_API_URLS['qastaging']:
 
200
        elif str(launchpad._root_uri) == lookup_service_root('qastaging'):
214
201
            return url.replace('bazaar.launchpad.net',
215
202
                               'bazaar.qastaging.launchpad.net')
216
203
        return url