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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
#! /usr/bin/python
try:
from html.parser import HTMLParser
except ImportError:
from HTMLParser import HTMLParser
from optparse import OptionParser
import os
import sys
sys.path.insert(0, os.path.join(sys.path[0], os.pardir, "lib"))
from cdimage.config import Config
from cdimage.mail import get_notify_addresses, send_mail
from cdimage.tree import Publisher, Tree
warnings = {}
mailer = None
mailer_stdin = None
class BritneyParser(HTMLParser):
STATE_BEGIN = 0
STATE_SEEN_INTRO_P = 1
STATE_SEEN_INTRO_TEXT = 2
STATE_UNINST_LIST = 3
STATE_UNINST_LIST_ITEM = 4
STATE_UNINST_LIST_ARCH_LIST = 5
STATE_UNINST_LIST_ARCH_ITEM = 6
STATE_DONE = 7
def __init__(self):
parser_kwargs = {}
if sys.version >= "3.4":
parser_kwargs["convert_charrefs"] = True
HTMLParser.__init__(self, **parser_kwargs)
self.state = self.STATE_BEGIN
self.formatted = ''
def handle_starttag(self, tag, attrs):
if self.state == self.STATE_BEGIN:
if tag == 'p':
self.state = self.STATE_SEEN_INTRO_P
elif self.state == self.STATE_SEEN_INTRO_TEXT:
if tag == 'ul':
self.state = self.STATE_UNINST_LIST
elif self.state == self.STATE_UNINST_LIST:
if tag == 'li':
self.state = self.STATE_UNINST_LIST_ITEM
elif self.state == self.STATE_UNINST_LIST_ITEM:
if tag == 'ul':
self.state = self.STATE_UNINST_LIST_ARCH_LIST
elif self.state == self.STATE_UNINST_LIST_ARCH_LIST:
if tag == 'li':
self.state = self.STATE_UNINST_LIST_ARCH_ITEM
def handle_endtag(self, tag):
if self.state in (self.STATE_UNINST_LIST, self.STATE_UNINST_LIST_ITEM):
if tag == 'ul':
self.state = self.STATE_DONE
elif self.state in (self.STATE_UNINST_LIST_ARCH_LIST,
self.STATE_UNINST_LIST_ARCH_ITEM):
if tag == 'ul':
self.state = self.STATE_UNINST_LIST_ITEM
def handle_data(self, data):
if self.state == self.STATE_SEEN_INTRO_P:
if data.startswith('First, uninstallable packages:'):
self.state = self.STATE_SEEN_INTRO_TEXT
elif self.state == self.STATE_UNINST_LIST_ITEM:
if data:
self.formatted += data.rstrip() + '\n'
elif self.state == self.STATE_UNINST_LIST_ARCH_ITEM:
if data:
self.formatted += ' * ' + data.rstrip() + '\n'
def warn(project, image, message):
if project not in warnings:
warnings[project] = {}
if image not in warnings[project]:
warnings[project][image] = []
warnings[project][image].append(message)
def project_title(project):
if project == 'ubuntu-server':
return 'Ubuntu Server'
elif project == 'jeos':
return 'Ubuntu JeOS'
elif project == 'ubuntustudio':
return 'Ubuntu Studio'
elif project == 'ubuntu-netbook':
return 'Ubuntu Netbook'
elif project == 'ubuntu-headless':
return 'Ubuntu Headless'
elif project == 'kubuntu-active':
return 'Kubuntu Active'
elif project == 'kubuntu-plasma5':
return 'Kubuntu Plasma 5'
elif project == 'ubuntu-moblin-remix':
return 'Ubuntu Moblin Remix'
else:
return project.title()
def check_image(config, project, series, image):
config["PROJECT"] = project
config["DIST"] = series
tree = Tree.get_daily(config)
publisher = Publisher.get_daily(tree, image)
curdir = os.path.join(publisher.publish_base, 'current')
if not os.path.exists(curdir):
return
files = sorted(os.listdir(curdir))
sizelimit = publisher.size_limit
for oversized in filter(lambda x: x.endswith('.OVERSIZED'), files):
base = oversized[:-10]
iso = "%s.iso" % base
try:
size = os.stat(os.path.join(curdir, iso)).st_size
except OSError:
continue
arch = base.split("-")[-1]
sizelimit = publisher.size_limit(arch)
if size > sizelimit:
warn(project, image, "%s oversized by %d bytes (%d)" %
(iso, size - sizelimit, size))
if project == 'xubuntu':
for manifest in filter(
lambda x: x.endswith('.list') or x.endswith('.manifest'),
files):
if manifest.endswith('.list'):
iso = manifest[:-5]
else:
iso = manifest[:-9]
with open(os.path.join(curdir, manifest)) as manifest_file:
if 'openoffice.org-core' in manifest_file.read():
warn(project, image,
"%s contains openoffice.org-core" % iso)
def check_uninstallables(config, project, series, image):
config["PROJECT"] = project
config["DIST"] = series
tree = Tree.get_daily(config)
publisher = Publisher.get_daily(tree, image)
curdir = os.path.join(publisher.publish_base, 'current')
report_path = os.path.join(curdir, 'report.html')
if not os.path.exists(report_path):
return
with open(report_path) as report:
parser = BritneyParser()
parser.feed(report.read())
if parser.formatted != '':
warn(project, image, "Uninstallable packages:\n\n%s" %
parser.formatted.rstrip('\n'))
def get_warnings(project):
global warnings
lines = []
if project in warnings:
for image in warnings[project]:
if lines and warnings[project][image]:
lines.append('')
for message in warnings[project][image]:
lines.append("%s/%s: %s" % (project, image, message))
return '\n'.join(lines)
def get_all_warnings(projects):
texts = []
for project in projects:
text = get_warnings(project)
if text:
texts.append(text)
return '\n\n\n'.join(texts)
def send_warnings(config, options, projects):
releasers = get_notify_addresses(config)
all_warnings = get_all_warnings(projects)
if all_warnings == '':
all_warnings = 'No problems found!'
body = """\
This is a daily health check report on all CD images.
If you have any questions, contact Colin Watson <cjwatson@ubuntu.com>.
%s
""" % all_warnings
send_mail(
"Daily CD health checks", "daily-checks", releasers, body,
dry_run=options.stdout)
for project in projects:
owners = [
owner for owner in get_notify_addresses(config, project)
if owner not in releasers]
if owners:
these_warnings = get_warnings(project)
if these_warnings == '':
continue
body = """\
This is a daily health check report on the %s CD images.
If you have any questions, contact Colin Watson <cjwatson@ubuntu.com>.
%s
""" % (project_title(project), these_warnings)
send_mail(
"%s daily CD health check" % project_title(project),
"daily-checks", owners, body, dry_run=options.stdout)
def main():
parser = OptionParser("%prog [options]")
parser.add_option(
"--stdout", default=False, action="store_true",
help="write to standard output rather than sending mail")
parser.add_option(
"--series", action="append", help="restrict checks to this series")
options, _ = parser.parse_args()
config = Config()
projects = (
'ubuntu',
'ubuntu-desktop-next',
'ubuntu-server',
'kubuntu',
'edubuntu',
'xubuntu',
'ubuntustudio',
'ubuntu-netbook',
'kubuntu-netbook',
'ubuntu-moblin-remix',
'kubuntu-active',
'kubuntu-plasma5',
'mythbuntu',
'lubuntu',
'ubuntu-gnome',
'ubuntu-mate',
'ubuntukylin',
)
if not options.series:
options.series = ('precise', 'trusty', 'vivid')
for project in projects:
for series in options.series:
for image in 'daily-live', 'daily', 'dvd':
check_image(config, project, series, image)
for image in 'daily-live', 'daily', 'dvd':
check_uninstallables(config, project, series, image)
send_warnings(config, options, projects)
if __name__ == "__main__":
main()
|