1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2012 Canonical
7
# This program is free software; you can redistribute it and/or modify it under
8
# the terms of the GNU General Public License as published by the Free Software
9
# Foundation; version 3.
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
# You should have received a copy of the GNU General Public License along with
17
# this program; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
from __future__ import unicode_literals
22
from launchpadlib.launchpad import Launchpad
28
from .settings import ARCHS_TO_EVENTUALLY_IGNORE, ARCHS_TO_UNCONDITIONALLY_IGNORE, VIRTUALIZED_PPA_ARCH, CRED_FILE_PATH, COMMON_LAUNCHPAD_CACHE_DIR
31
def get_launchpad(use_staging=False, use_cred_file=os.path.expanduser(CRED_FILE_PATH)):
32
'''Get THE Launchpad'''
40
# as launchpadlib isn't multiproc, fiddling the cache dir if any
41
launchpadlib_dir = os.getenv("JOB_NAME")
43
launchpadlib_dir = os.path.join(COMMON_LAUNCHPAD_CACHE_DIR, launchpadlib_dir)
46
launchpad = Launchpad.login_with('cupstream2distro', server, allow_access_levels=["WRITE_PRIVATE"],
47
version='devel', # devel because copyPackage is only available there
48
credentials_file=use_cred_file,
49
launchpadlib_dir=launchpadlib_dir)
51
launchpad = Launchpad.login_with('cupstream2distro', server, allow_access_levels=["WRITE_PRIVATE"],
52
version='devel', # devel because copyPackage is only available there
53
launchpadlib_dir=launchpadlib_dir)
59
'''Get the ubuntu distro'''
61
return lp.distributions['ubuntu']
64
def get_ubuntu_archive():
65
'''Get the ubuntu main archive'''
66
return get_ubuntu().main_archive
69
def get_series(series_name):
70
'''Return the launchpad object for the requested series'''
71
return get_ubuntu().getSeries(name_or_version=series_name)
74
def get_bugs_titles(author_bugs):
76
author_bugs_with_title = author_bugs.copy()
77
for author in author_bugs:
78
bug_title_sets = set()
79
for bug in author_bugs[author]:
81
bug_title_sets.add("{} (LP: #{})".format(lp.bugs[bug].title, bug))
83
# still list non existing or if launchpad timeouts bugs
84
bug_title_sets.add(u"Fix LP: #{}".format(bug))
85
author_bugs_with_title[author] = bug_title_sets
87
return author_bugs_with_title
90
def open_bugs_for_source(bugs_list, source_name, series_name):
94
# don't nominate for current series
95
if ubuntu.current_series.name == series_name:
96
package = ubuntu.getSourcePackage(name=source_name)
98
series = get_series(series_name)
99
package = series.getSourcePackage(name=source_name)
101
for bug_num in bugs_list:
103
bug = lp.bugs[bug_num]
104
bug.addTask(target=package)
106
except (KeyError, lazr.restfulclient.errors.BadRequest, lazr.restfulclient.errors.ServerError):
107
# ignore non existing or available bugs
108
logging.info("Can't synchronize upstream/downstream bugs for bug #{}. Not blocking on that.".format(bug_num))
111
def get_available_all_and_ignored_archs(series, ppa=None):
112
'''Return a set of available archs, the all arch and finally the archs we can eventually ignored if nothing is published in dest'''
113
available_arch = set()
114
if ppa and ppa.require_virtualized:
115
available_arch = set(VIRTUALIZED_PPA_ARCH)
116
arch_all_arch = VIRTUALIZED_PPA_ARCH[0]
118
for arch in series.architectures:
119
# HACK: filters armel as it's still seen as available on raring: https://launchpad.net/bugs/1077257
120
if arch.architecture_tag == "armel":
122
available_arch.add(arch.architecture_tag)
123
if arch.is_nominated_arch_indep:
124
arch_all_arch = arch.architecture_tag
126
return (available_arch, arch_all_arch, ARCHS_TO_EVENTUALLY_IGNORE, ARCHS_TO_UNCONDITIONALLY_IGNORE)
129
def get_ppa(ppa_name):
130
'''Return a launchpad ppa'''
131
ppa_dispatch = ppa_name.split("/")
132
return get_launchpad().people[ppa_dispatch[0]].getPPAByName(name=ppa_dispatch[1])
134
def is_series_current(series_name):
135
'''Return if series_name is the edge development version'''
136
return get_ubuntu().current_series.name == series_name
138
def get_resource_from_url(url):
139
'''Return a lp resource from a launchpad url'''
141
url = lp.resource_type_link.replace("/#service-root", "") + url.split("launchpad.net")[1]
144
def get_resource_from_token(url):
145
'''Return a lp resource from a launchpad token'''
149
def is_dest_ubuntu_archive(series_link):
150
'''return if series_link is the ubuntu archive'''
151
return series_link == get_ubuntu_archive().self_link
153
def get_person(nickname):
154
'''Return a launchpad person'''
156
return lp.people[nickname]