-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunchpad.py
82 lines (72 loc) · 2.43 KB
/
launchpad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# launchpad.py -- Lookups via. launchpadlib
# Copyright (C) 2009 Canonical Ltd.
#
# This file is part of bzr-builddeb.
#
# bzr-builddeb is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# bzr-builddeb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bzr-builddeb; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
from ...trace import (
mutter,
)
try:
from launchpadlib.launchpad import Launchpad
from launchpadlib.uris import LPNET_SERVICE_ROOT
HAVE_LPLIB = True
except ImportError:
HAVE_LPLIB = False
def get_launchpad():
if not HAVE_LPLIB:
return None
return Launchpad.login_anonymously(
"breezy-debian", service_root=LPNET_SERVICE_ROOT)
def ubuntu_bugs_for_debian_bug(bug_id):
"""Find Ubuntu bugs linked to a particular Debian bug.
:param bug_id: Debian bug id
:return: Liust of Launchpad bug ids for Ubuntu bugs
"""
lp = get_launchpad()
if lp is None:
return []
try:
bug = lp.load(str(lp._root_uri) + "bugs/bugtrackers/debbugs/%s")
tasks = bug.bug_tasks
for task in tasks:
if task.bug_target_name.endswith("(Ubuntu)"):
return str(bug.id)
except Exception as e:
mutter(str(e))
return []
return []
def debian_bugs_for_ubuntu_bug(bug_id):
"""Find the Debian bugs linked to a particular Ubuntu bug.
:param bug_id: The Launchpad bug ID for the Ubuntu bug
:return: List of Debian bug URLs.
"""
lp = get_launchpad()
if lp is None:
return []
try:
bug = lp.bugs[int(bug_id)]
tasks = bug.bug_tasks
for task in tasks:
if task.bug_target_name.endswith("(Debian)"):
watch = task.bug_watch
if watch is None:
break
return watch.remote_bug.encode("utf-8")
except Exception as e:
mutter(str(e))
return []
return []