745.2.1
by Brian Murray
add a tool to check for source packages in main or restricted in active distro series without a team subscribed |
1 |
#! /usr/bin/python
|
2 |
||
3 |
from __future__ import print_function |
|
4 |
||
5 |
import atexit |
|
6 |
import bz2 |
|
7 |
from contextlib import closing |
|
8 |
from optparse import OptionParser |
|
9 |
import shutil |
|
10 |
import sys |
|
11 |
import tempfile |
|
12 |
try: |
|
13 |
from urllib.request import urlretrieve |
|
14 |
except ImportError: |
|
15 |
from urllib import urlretrieve |
|
16 |
||
17 |
import apt_pkg |
|
18 |
from launchpadlib.launchpad import Launchpad |
|
19 |
||
20 |
import lputils |
|
21 |
||
22 |
||
23 |
tempdir = None |
|
24 |
||
25 |
||
26 |
def ensure_tempdir(): |
|
27 |
global tempdir |
|
28 |
if not tempdir: |
|
29 |
tempdir = tempfile.mkdtemp(prefix="unsubscribed-packages") |
|
30 |
atexit.register(shutil.rmtree, tempdir) |
|
31 |
||
32 |
||
33 |
def decompress_open(tagfile): |
|
34 |
if tagfile.startswith("http:") or tagfile.startswith("ftp:"): |
|
35 |
url = tagfile |
|
36 |
tagfile = urlretrieve(url)[0] |
|
37 |
||
38 |
if tagfile.endswith(".bz2"): |
|
39 |
ensure_tempdir() |
|
40 |
decompressed = tempfile.mktemp(dir=tempdir) |
|
41 |
with closing(bz2.BZ2File(tagfile)) as fin: |
|
42 |
with open(decompressed, "wb") as fout: |
|
43 |
fout.write(fin.read()) |
|
44 |
return open(decompressed, "r") |
|
45 |
else: |
|
46 |
return open(tagfile, "r") |
|
47 |
||
48 |
||
49 |
def archive_base(archtag): |
|
50 |
if archtag in ("amd64", "i386", "src"): |
|
51 |
return "http://archive.ubuntu.com/ubuntu" |
|
52 |
else: |
|
53 |
return "http://ports.ubuntu.com/ubuntu-ports" |
|
54 |
||
55 |
||
56 |
def source_names(options): |
|
57 |
sources = set() |
|
58 |
for suite in options.suites: |
|
59 |
for component in ["main", "restricted"]: |
|
60 |
url = "%s/dists/%s/%s/source/Sources.bz2" % ( |
|
61 |
archive_base("src"), suite, component) |
|
62 |
print("Reading %s ..." % url, file=sys.stderr) |
|
63 |
for section in apt_pkg.TagFile(decompress_open(url)): |
|
64 |
sources.add(section["Package"]) |
|
65 |
return sorted(sources) |
|
66 |
||
67 |
||
68 |
def main(): |
|
69 |
parser = OptionParser( |
|
745.2.2
by Brian Murray
fix typo |
70 |
description="Check for source packages in main or restricted in " |
745.2.1
by Brian Murray
add a tool to check for source packages in main or restricted in active distro series without a team subscribed |
71 |
"active distro series without a team subscribed.") |
72 |
parser.add_option( |
|
73 |
"-l", "--launchpad", dest="launchpad_instance", default="production") |
|
74 |
options, _ = parser.parse_args() |
|
75 |
options.suite = None |
|
76 |
options.distribution = "ubuntu" |
|
77 |
options.launchpad = Launchpad.login_with( |
|
78 |
"unsubscribed-packages", options.launchpad_instance) |
|
79 |
launchpad = options.launchpad |
|
80 |
ubuntu = launchpad.distributions[options.distribution] |
|
81 |
options.suites = [] |
|
82 |
for series in ubuntu.series: |
|
745.2.4
by Brian Murray
do not consider lucid packages |
83 |
# very few lucid packages are supported
|
84 |
if series.name == 'lucid': |
|
85 |
continue
|
|
745.2.1
by Brian Murray
add a tool to check for source packages in main or restricted in active distro series without a team subscribed |
86 |
if series.active: |
87 |
options.suites.append(series.name) |
|
88 |
lputils.setup_location(options) |
|
89 |
||
760
by Colin Watson
unsubscribed-packages: one team per line, and re-alphabetise |
90 |
team_names = [ |
91 |
'checkbox-bugs', |
|
92 |
'desktop-packages', |
|
93 |
'documentation-packages', |
|
94 |
'dx-packages', |
|
95 |
'edubuntu-bugs', |
|
96 |
'foundations-bugs', |
|
97 |
'kernel-packages', |
|
98 |
'kubuntu-bugs', |
|
99 |
'lubuntu-packaging', |
|
100 |
'translators-packages', |
|
101 |
'ubuntu-apps-bugs', |
|
102 |
'ubuntu-phonedations-bugs', |
|
103 |
'ubuntu-sdk-bugs', |
|
761
by Steve Langasek
Switch to ubuntu-security-bugs, per Jamie |
104 |
'ubuntu-security-bugs', |
760
by Colin Watson
unsubscribed-packages: one team per line, and re-alphabetise |
105 |
'ubuntu-server', |
106 |
'ubuntuone-hackers', |
|
107 |
'unity-api-bugs', |
|
108 |
'unity-ui-bugs', |
|
109 |
'xubuntu-bugs', |
|
110 |
]
|
|
745.2.1
by Brian Murray
add a tool to check for source packages in main or restricted in active distro series without a team subscribed |
111 |
|
112 |
subscriptions = set() |
|
113 |
for team_name in team_names: |
|
114 |
team = launchpad.people[team_name] |
|
115 |
team_subs = team.getBugSubscriberPackages() |
|
116 |
for src_pkg in team_subs: |
|
117 |
subscriptions.add(src_pkg.name) |
|
118 |
||
119 |
source_packages = source_names(options) |
|
120 |
||
121 |
for source_package in source_packages: |
|
122 |
if source_package not in subscriptions: |
|
123 |
print("No team is subscribed to: %s" % source_package) |
|
124 |
||
125 |
if __name__ == '__main__': |
|
126 |
main() |