-
Notifications
You must be signed in to change notification settings - Fork 2
/
piuparts-report.py
1377 lines (1206 loc) · 54.9 KB
/
piuparts-report.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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
#
# Copyright 2005 Lars Wirzenius ([email protected])
# Copyright 2009-2012 Holger Levsen ([email protected])
#
# This program 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.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""Create HTML reports of piuparts log files
Lars Wirzenius <[email protected]>
"""
import os
import sys
import time
import logging
import ConfigParser
import urllib
import shutil
import re
import string
# if python-rpy ain't installed, we don't draw fancy graphs
try:
from rpy import *
except:
pass
import piupartslib
CONFIG_FILE = "/etc/piuparts/piuparts.conf"
DISTRO_CONFIG_FILE = "/etc/piuparts/distros.conf"
HTML_HEADER = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Generated by piuparts-report __PIUPARTS_VERSION__ -->
<title>
$page_title
</title>
<link type="text/css" rel="stylesheet" href="$doc_root/style.css">
<link rel="shortcut icon" href="$doc_root/favicon.ico">
</head>
<body>
<div id="header">
<h1 class="header">
<a href="http://www.debian.org/">
<img src="$doc_root/images/openlogo-nd-50.png" border="0" hspace="0" vspace="0" alt=""></a>
<a href="http://www.debian.org/">
<img src="$doc_root/images/debian.png" border="0" hspace="0" vspace="0" alt="Debian Project"></a>
Quality Assurance
</h1>
<div id="obeytoyourfriend">Policy is your friend. Trust the Policy. Love the Policy. Obey the Policy.</div>
</div>
<hr>
<div id="main">
<table class="containertable">
<tr class="containerrow" valign="top">
<td class="containercell">
<table class="lefttable">
<tr class="titlerow">
<td class="titlecell">
General information
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="$doc_root/">About + News</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="http://wiki.debian.org/piuparts" target="_blank">Overview</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="http://wiki.debian.org/piuparts/FAQ" target="_blank">FAQ</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="http://bugs.debian.org/src:piuparts" target="_blank">Bugs</a> / <a href="http://anonscm.debian.org/gitweb/?p=piuparts/piuparts.git;a=blob;f=TODO" target="_blank">ToDo</a>
</td>
</tr>
<tr class="titlerow">
<td class="titlecell">
Documentation
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="$doc_root/doc/README.html" target="_blank">piuparts README</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="$doc_root/doc/piuparts.1.html" target="_blank">piuparts manpage</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
piuparts.d.o configuration:<br>
<a href="http://anonscm.debian.org/gitweb/?p=piuparts/piuparts.git;hb=piatti;a=blob_plain;f=instances/piuparts.conf.piatti" target="_blank">piuparts.conf.piatti</a><br>
<a href="http://anonscm.debian.org/gitweb/?p=piuparts/piuparts.git;hb=piatti;a=tree;f=custom-scripts" target="_blank">scripts</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="$doc_root/bug_howto.html">How to file bugs</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="http://www.debian.org/doc/debian-policy/" target="_blank">Debian policy</a>
</td>
</tr>
<tr class="titlerow">
<td class="alerttitlecell">
Available reports
</td>
</tr>
<tr>
<td class="contentcell">
<a href="http://bugs.debian.org/cgi-bin/pkgreport.cgi?tag=piuparts;[email protected]&archive=both" target="_blank">Bugs filed</a>
</td>
</tr>
$section_navigation
<tr class="titlerow">
<td class="titlecell">
Other Debian QA efforts
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="http://edos.debian.net" target="_blank">EDOS tools</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="http://lintian.debian.org" target="_blank">Lintian</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="http://packages.qa.debian.org" target="_blank">Package Tracking System</a>
</td>
<tr class="normalrow">
<td class="contentcell">
<a href="http://udd.debian.org" target="_blank">Ultimate Debian Database</a>
</td>
</tr>
<tr class="titlerow">
<td class="titlecell">
Last update
</td>
</tr>
<tr class="normalrow">
<td class="lastcell">
$time
</td>
</tr>
</table>
</td>
<td class="containercell">
"""
HTML_FOOTER = """
</td>
</tr>
</table>
</div>
<hr>
<div id="footer">
<div>
<a href="http://packages.qa.debian.org/piuparts" target="_blank">piuparts</a>
is GPL2 <a href="http://packages.debian.org/changelogs/pool/main/p/piuparts/current/copyright" target="_blank">licenced</a>
and was written by <a href="mailto:[email protected]">Lars Wirzenius</a> and is now maintained by
<a href="mailto:[email protected]">Holger Levsen</a> and
<a href="mailto:[email protected]">others</a> using
<a href="http://anonscm.debian.org/gitweb/?p=piuparts/piuparts.git" target="_blank">piuparts.git</a>.
Weather icons are from the <a href="http://tango.freedesktop.org/Tango_Icon_Library" target="_blank">Tango Icon Library</a>.
<a href="http://validator.w3.org/check?uri=referer">
<img border="0" src="$doc_root/images/valid-html401.png" alt="Valid HTML 4.01!" height="15" width="80" align="middle">
</a>
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img border="0" src="$doc_root/images/w3c-valid-css.png" alt="Valid CSS!" height="15" width="80" align="middle">
</a>
</div>
</div>
</body>
</html>
"""
LOG_LIST_BODY_TEMPLATE = """
<table class="righttable">
<tr class="titlerow">
<td class="$title_style" colspan="2">
$title in $section
</td>
</tr>
<tr class="normalrow">
<td class="contentcell2" colspan="2">
$preface
The list has $count packages, with $versioncount total versions.
</td>
</tr>
$logrows
</table>
"""
STATE_BODY_TEMPLATE = """
<table class="righttable">
<tr class="titlerow">
<td class="alerttitlecell">
Packages in state "$state" in $section $aside
</td>
</tr>
<tr class="normalrow">
<td class="contentcell2">
<ul>
$list
</ul>
</td>
</tr>
</table>
"""
SECTION_INDEX_BODY_TEMPLATE = """
<table class="righttable">
<tr class="titlerow">
<td class="titlecell" colspan="3">
$section statistics
</td>
</tr>
<tr class="normalrow">
<td class="contentcell2" colspan="3">
$description
</td>
</tr>
<tr class="titlerow">
<td class="alerttitlecell" colspan="3">
Binary packages per state
</td>
</tr>
$tablerows
<tr class="titlerow">
<td class="titlecell" colspan="3">
URL to Packages file
</td>
</tr>
<tr class="normalrow">
<td class="contentcell2" colspan="3">
<code>$packagesurl</code>
</td>
</tr>
</table>
"""
MAINTAINER_BODY_TEMPLATE = """
<table class="righttable">
<tr class="titlerow">
<td class="titlecell" colspan="6">
$maintainer
</td>
</tr>
$distrolinks
$rows
</table>
"""
SOURCE_PACKAGE_BODY_TEMPLATE = """
<table class="righttable">
$rows
</table>
"""
ANALYSIS_BODY_TEMPLATE = """
<table class="righttable">
$rows
</table>
"""
title_by_dir = {
"pass": "PASSED piuparts logs",
"fail": "Failed UNREPORTED piuparts logs",
"bugged": "Failed REPORTED piuparts logs",
"affected": "Failed AFFECTED piuparts logs",
"reserved": "RESERVED packages",
"untestable": "UNTESTABLE packages",
}
desc_by_dir = {
"pass": "Log files for packages that have PASSED testing.",
"fail": "Log files for packages that have FAILED testing. " +
"Bugs have not yet been reported.",
"bugged": "Log files for packages that have FAILED testing. " +
"Bugs have been reported, but not yet fixed.",
"affected": "Log files for packages that have dependencies FAILED testing. " +
"Bugs have been reported, but not yet fixed.",
"reserved": "Packages that are RESERVED for testing on a node in a " +
"distributed piuparts network.",
"untestable": "Log files for packages that have are UNTESTABLE with " +
"piuparts at the current time.",
}
state_by_dir = {
"pass": "successfully-tested",
"fail": "failed-testing",
"bugged": "failed-testing",
"affected": "failed-testing",
"reserved": "waiting-to-be-tested",
"untestable": "cannot-be-tested",
}
# better use XX_name.tpl and get the linktarget from the template
# (its a substring of the <title> of the that template
# maintaining this list is errorprone and tiresome
linktarget_by_template = [
("initdscript_lsb_header_issue.tpl", "but logfile contains update-rc.d issues"),
("command_not_found_issue.tpl", "but logfile contains 'command not found'"),
("debsums_mismatch_issue.tpl", "but logfile contains modified conffiles or other shipped files"),
("alternatives_after_purge_issue.tpl", "but logfile contains forgotten alternatives"),
("owned_files_after_purge_issue.tpl", "but logfile contains owned files existing after purge"),
("unowned_files_after_purge_issue.tpl", "but logfile contains unowned files after purge"),
("maintainer_script_issue.tpl", "but logfile contains maintainer script failures"),
("installs_over_symlink_issue.tpl", "but package installs something over existing symlinks"),
("broken_symlinks_issue.tpl", "but logfile contains 'broken symlinks'"),
("packages_have_been_kept_back_issue.tpl", "but logfile contains 'packages have been kept back'"),
("needs_rebuild_issue.tpl", "but logfile recommends to rebuild some packages"),
("obsolete_conffiles_issue.tpl", "but logfile reports obsolete conffiles"),
("dependency_error.tpl", "due to unsatisfied dependencies"),
("packages_have_been_kept_back_error.tpl", "...and logfile also contains 'packages have been kept back'"),
("command_not_found_error.tpl", "due to a 'command not found' error"),
("files_in_usr_local_error.tpl", "due to files in /usr/local"),
("overwrite_other_packages_files_error.tpl", "due to overwriting other packages files"),
("debsums_mismatch_error.tpl", "due to modifying conffiles or other shipped files"),
("alternatives_after_purge_error.tpl", "due to forgotten alternatives after purge"),
("owned_files_by_many_packages_error.tpl", "due to owned files by many packages"),
("owned_files_after_purge_error.tpl", "due to owned files existing after purge"),
("unowned_files_after_purge_error.tpl", "due to unowned files after purge"),
("modified_files_after_purge_error.tpl", "due to files having been modified after purge"),
("disappeared_files_after_purge_error.tpl", "due to files having disappeared after purge"),
("diversion_error.tpl", "due to diversions being modified after purge"),
("processes_running_error.tpl", "due to leaving processes running behind"),
("resource_violation_error.tpl", "due to resource violation"),
("conffile_prompt_error.tpl", "due to prompting due to modified conffiles"),
("db_setup_error.tpl", "due to failing to setup a database"),
("insserv_error.tpl", "due to a problem with insserv"),
("problems_and_no_force_error.tpl", "due to not enough force being used"),
("pre_depends_error.tpl", "due to a problem with pre-depends"),
("pre_installation_script_error.tpl", "due to pre-installation maintainer script failed"),
("post_installation_script_error.tpl", "due to post-installation maintainer script failed"),
("pre_removal_script_error.tpl", "due to pre-removal maintainer script failed"),
("post_removal_script_error.tpl", "due to post-removal maintainer script failed"),
("unknown_purge_error.tpl", "due to purge failed due to an unknown reason"),
("cron_error_after_removal_error.tpl", "due to errors from cronjob after removal"),
("logrotate_error_after_removal_error.tpl", "due to errors from logrotate after removal"),
("installs_over_symlink_error.tpl", "...and package installs something over existing symlinks"),
("broken_symlinks_error.tpl", "...and logfile also contains 'broken symlinks'"),
("obsolete_conffiles_error.tpl", "...and logfile reports obsolete conffiles"),
("unknown_failures.tpl", "due to unclassified failures"),
]
class Config(piupartslib.conf.Config):
def __init__(self, section="report", defaults_section=None):
self.section = section
piupartslib.conf.Config.__init__(self, section,
{
"sections": "report",
"output-directory": "html",
"master-directory": ".",
"depends-sections": None,
"description": "",
"proxy": None,
"mirror": None,
"distro": None,
"area": None,
"arch": None,
"upgrade-test-distros": None,
"max-reserved": 1,
"doc-root": "/",
},
defaults_section=defaults_section)
def setup_logging(log_level, log_file_name):
logger = logging.getLogger()
logger.setLevel(log_level)
formatter = logging.Formatter(fmt="%(asctime)s %(message)s",
datefmt="%H:%M:%S")
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(formatter)
logger.addHandler(handler)
if log_file_name:
handler = logging.FileHandler(log_file_name)
logger.addHandler(handler)
def html_protect(vstr):
vstr = "&".join(vstr.split("&"))
vstr = "<".join(vstr.split("<"))
vstr = ">".join(vstr.split(">"))
vstr = """.join(vstr.split('"'))
vstr = "'".join(vstr.split("'"))
return vstr
def emphasize_reason(reason):
bad_states = [
#"successfully-tested",
"failed-testing",
"cannot-be-tested",
#"essential-required",
#"waiting-to-be-tested",
#"waiting-for-dependency-to-be-tested",
"dependency-failed-testing",
"dependency-cannot-be-tested",
"dependency-does-not-exist",
"circular-dependency", # obsolete
"unknown",
"unknown-preferred-alternative", # obsolete
"no-dependency-from-alternatives-exists", # obsolete
"does-not-exist",
]
if reason in bad_states:
reason = "<em>"+reason+"</em>"
return reason
def source_subdir(source):
if source[:3] == "lib":
return source[:4]
else:
return source[:1]
def maintainer_subdir(maintainer):
return maintainer.lower()[:1]
def find_files_with_suffix(vdir, suffix):
pairs = [] # (mtime, name)
for name in os.listdir(vdir):
if name.endswith(suffix):
try:
if os.path.isfile(os.path.join(vdir, name)):
mtime = os.path.getmtime(os.path.join(vdir, name))
pairs.append((mtime, name))
except OSError:
pass
# sort by mtime
return [x[1] for x in sorted(pairs)]
def update_file(source, target):
if os.path.exists(target):
try:
aa = os.stat(source)
bb = os.stat(target)
except OSError:
pass
else:
if aa.st_size == bb.st_size and aa.st_mtime <= bb.st_mtime:
return
try:
os.remove(target)
except:
pass
try:
os.link(source, target)
except OSError:
try:
shutil.copyfile(source, target)
except IOError as (errno, strerror):
logging.error("failed to copy %s to %s: I/O error(%d): %s" \
% (source, target, errno, strerror))
def copy_logs(logs_by_dir, output_dir):
for vdir in logs_by_dir:
fulldir = os.path.join(output_dir, vdir)
if not os.path.exists(fulldir):
os.makedirs(fulldir)
for basename in logs_by_dir[vdir]:
source = os.path.join(vdir, basename)
target = os.path.join(fulldir, basename)
update_file(source, target)
def remove_old_logs(logs_by_dir, output_dir):
for vdir in logs_by_dir:
fulldir = os.path.join(output_dir, vdir)
# convert logs_by_dir array to a dict to avoid linear search
logs_dict = {}
for log in logs_by_dir[vdir]:
logs_dict[log] = 1
if os.path.exists(fulldir):
for basename in os.listdir(fulldir):
if not basename in logs_dict:
os.remove(os.path.join(fulldir, basename))
def write_file(filename, contents):
f = file(filename, "w")
f.write(contents)
f.close()
def append_file(filename, contents):
f = file(filename, "a")
f.write(contents)
f.close()
def read_file(filename):
f = file(filename, "r")
l = f.readlines()
f.close()
return l
def create_section_navigation(section_names,current_section, doc_root):
tablerows = ""
for section in section_names:
tablerows += ("<tr class=\"normalrow\"><td class=\"contentcell\"><a href='%s/%s'>%s</a></td></tr>\n") % \
(doc_root, html_protect(section), html_protect(section))
tablerows += "<tr><td class=\"contentcell\"><a href=\"%s/%s/maintainer/\">by maintainer / uploader</a></td></tr>\n" \
% (doc_root, current_section)
tablerows += "<tr><td class=\"contentcell\"><a href=\"%s/%s/source/\">by source package</a></td></tr>\n" \
% (doc_root, current_section)
return tablerows;
def get_email_address(maintainer):
email = "INVALID maintainer address: %s" % (maintainer)
try:
m = re.match(r"(.+)(<)(.+@.+)(>)", maintainer)
email = m.group(3)
except:
pass
return email
class Section:
def __init__(self, section, master_directory, doc_root, packagedb_cache={}):
self._config = Config(section=section, defaults_section="global")
self._config.read(CONFIG_FILE)
self._distro_config = piupartslib.conf.DistroConfig(
DISTRO_CONFIG_FILE, self._config["mirror"])
logging.debug("-------------------------------------------")
logging.debug("Running section " + self._config.section)
self._section_directory = os.path.abspath(os.path.join(master_directory, \
self._config.section))
if not os.path.exists(self._section_directory):
logging.debug("Warning: %s did not exist, now created. Did you ever let the slave work?"
% self._section_directory)
os.makedirs(self._section_directory)
self._doc_root = doc_root
logging.debug("Loading and parsing Packages file")
oldcwd = os.getcwd()
os.chdir(master_directory)
self._packagedb_cache = packagedb_cache
self._package_databases = {}
self._load_package_database(section)
self._binary_db = self._package_databases[section]
self._binary_db.calc_rrdep_counts()
os.chdir(oldcwd)
sources_url = self._distro_config.get_sources_url(
self._config.get_distro(), self._config.get_area())
logging.info("Fetching %s" % sources_url)
sources_file = piupartslib.open_packages_url(sources_url)
self._source_db = piupartslib.packagesdb.PackagesDB()
self._source_db.read_packages_file(sources_file)
sources_file.close()
self._log_name_cache = {}
def _load_package_database(self, section):
if section in self._package_databases:
return
elif section in self._packagedb_cache:
self._package_databases[section] = self._packagedb_cache[section]
return
config = Config(section=section, defaults_section="global")
config.read(CONFIG_FILE)
if not config["depends-sections"]:
# this is a base database eligible for caching
# only cache the most recent base database
self._packagedb_cache.clear()
db = piupartslib.packagesdb.PackagesDB(prefix=section)
self._package_databases[section] = db
if config["depends-sections"]:
deps = config["depends-sections"].split()
for dep in deps:
self._load_package_database(dep)
db.set_dependency_databases([self._package_databases[dep] for dep in deps])
else:
# only cache the big base databases that don't have additional dependencies
self._packagedb_cache[section] = db
packages_url = self._distro_config.get_packages_url(
config.get_distro(), config.get_area(), config.get_arch())
logging.info("Fetching %s" % packages_url)
packages_file = piupartslib.open_packages_url(packages_url)
db.read_packages_file(packages_file)
packages_file.close()
if config.get_distro() != config.get_final_distro():
# take version numbers (or None) from final distro
packages_url = self._distro_config.get_packages_url(
config.get_final_distro(), config.get_area(), config.get_arch())
logging.info("Fetching %s" % packages_url)
packages_file = piupartslib.open_packages_url(packages_url)
db2 = piupartslib.packagesdb.PackagesFile(packages_file)
packages_file.close()
for package in db.get_all_packages().values():
if package["Package"] in db2:
package["Version"] = db2[package["Package"]]["Version"]
else:
package["Version"] = "None"
def write_log_list_page(self, filename, title, preface, logs):
packages = {}
for pathname, package, version in logs:
packages[package] = packages.get(package, []) + [(pathname, version)]
names = packages.keys()
names.sort()
lines = []
version_count = 0
for package in names:
versions = []
for pathname, version in packages[package]:
version_count += 1
versions.append("<a href=\"%s\">%s</a>" %
(html_protect(pathname),
html_protect(version)))
line = "<tr class=\"normalrow\"><td class=\"contentcell2\">%s</td><td class=\"contentcell2\">%s</td></tr>" % \
(html_protect(package),
", ".join(versions))
lines.append(line)
if "FAIL" in preface:
title_style="alerttitlecell"
else:
title_style="titlecell"
htmlpage = string.Template(HTML_HEADER + LOG_LIST_BODY_TEMPLATE + HTML_FOOTER)
f = file(filename, "w")
f.write(htmlpage.safe_substitute( {
"page_title": html_protect(title+" in "+self._config.section),
"section_navigation":
create_section_navigation(self._section_names,
self._config.section,
self._doc_root),
"time": time.strftime("%Y-%m-%d %H:%M %Z"),
"title": html_protect(title),
"section": html_protect(self._config.section),
"title_style": title_style,
"preface": preface,
"count": len(packages),
"versioncount": version_count,
"logrows": "".join(lines),
"doc_root": self._doc_root,
}))
f.close()
def print_by_dir(self, output_directory, logs_by_dir):
for vdir in logs_by_dir:
vlist = []
for basename in logs_by_dir[vdir]:
assert basename.endswith(".log")
assert "_" in basename
package, version = basename[:-len(".log")].split("_")
vlist.append((os.path.join(vdir, basename), package, version))
self.write_log_list_page(os.path.join(output_directory, vdir + ".html"),
title_by_dir[vdir],
desc_by_dir[vdir], vlist)
def find_links_to_logs(self, package_name, dirs, logs_by_dir):
links = []
for vdir in dirs:
# avoid linear search against log file names by caching in a dict
#
# this cache was added to avoid a very expensive linear search
# against the arrays in logs_by_dir. Note that the use of this cache
# assumes that the contents of logs_by_dir is invarient across calls
# to find_links_to_logs()
#
if vdir not in self._log_name_cache:
self._log_name_cache[vdir] = {}
for basename in logs_by_dir[vdir]:
if basename.endswith(".log"):
package, version = basename[:-len(".log")].split("_")
self._log_name_cache[vdir][package] = version
if vdir == "fail":
style = " class=\"needs-bugging\""
else:
style = ""
if package_name in self._log_name_cache[vdir]:
basename = package_name \
+ "_" \
+ self._log_name_cache[vdir][package_name] \
+ ".log"
links.append("<a href=\"%s/%s\"%s>%s</a>" % (
self._doc_root,
os.path.join(self._config.section, vdir, basename),
style,
html_protect(self._log_name_cache[vdir][package_name]),
))
return links
def link_to_maintainer_summary(self, maintainer):
email = get_email_address(maintainer)
return "<a href=\"%s/%s/maintainer/%s/%s.html\">%s</a>" \
% (self._doc_root,self._config.section,maintainer_subdir(email),
email,html_protect(maintainer))
def link_to_uploaders(self, uploaders):
link = ""
for uploader in uploaders.split(","):
link += self.link_to_maintainer_summary(uploader.strip()) + ", "
return link[:-2]
def link_to_source_summary(self, package_name):
source_name = self._binary_db.get_control_header(package_name, "Source")
link = "<a href=\"%s/%s/source/%s\">%s</a>" % (
self._doc_root,
self._config.section,
source_subdir(source_name)+"/"+source_name+".html",
html_protect(package_name))
return link
def link_to_state_page(self, section, package_name, link_target):
if self._binary_db.has_package(package_name):
state = self._binary_db.get_package_state(package_name)
link = "<a href=\"%s/%s/%s\">%s</a>" % (
self._doc_root,
section,
"state-"+state+".html"+"#"+package_name,
link_target)
else:
if link_target == package_name:
link = html_protect(package_name)
else:
link = "unknown-package"
return link
def links_to_logs(self, package_name, state, logs_by_dir):
link = "N/A"
dirs = ""
if state == "successfully-tested":
dirs = ["pass"]
elif state == "failed-testing":
dirs = ["fail", "bugged", "affected"]
elif state == "cannot-be-tested":
dirs = ["untestable"]
if dirs != "":
links = self.find_links_to_logs (package_name, dirs, logs_by_dir)
link = ", ".join(links)
if "/bugged/" in link or "/affected/" in link:
link += " - <a href=\"http://bugs.debian.org/cgi-bin/pkgreport.cgi?package=" \
+ package_name \
+ "\" target=\"_blank\" class=\"bugged\"> bug filed </a>\n"
return link
def write_counts_summary(self):
logging.debug("Writing counts.txt")
header = "date"
current_day = "%s" % time.strftime("%Y%m%d")
counts = current_day
total = 0
for state in self._binary_db.get_states():
count = len(self._binary_db.get_pkg_names_in_state(state))
header += ", %s" % state
counts += ", %s" % count
logging.debug("%s: %s" % (state, count))
total += count
logging.debug("total: %s" % total)
logging.debug("source: %s" % len(self._source_db.get_all_packages()))
header += "\n"
counts += "\n"
countsfile = os.path.join(self._output_directory, "counts.txt")
if not os.path.isfile(countsfile):
logging.debug("writing new file: %s" % countsfile)
write_file(countsfile, header)
last_line = ""
else:
last_line = read_file(countsfile)[-1]
if not current_day in last_line:
append_file(countsfile, counts)
logging.debug("appending line: %s" % counts.strip())
return total
def create_maintainer_summaries(self, maintainers, source_data):
logging.debug("Writing %d maintainer summaries in %s" % (len(maintainers), self._output_directory))
maintainer_dir = os.path.join(self._output_directory, "maintainer")
if not os.path.exists(maintainer_dir):
os.mkdir(maintainer_dir)
states = ["fail", "unknown", "pass"]
for maintainer in maintainers.keys():
sources = maintainers[maintainer]
maintainer_subdir_path = os.path.join(maintainer_dir, maintainer_subdir(maintainer))
if not os.path.exists(maintainer_subdir_path):
os.mkdir(maintainer_subdir_path)
rows = ""
package_rows = ""
packages = {}
for state in states:
packages[state] = []
for source in sorted(sources):
(state, sourcerows, binaryrows) = source_data[source]
packages[state].append(source)
package_rows += sourcerows + binaryrows
for state in states:
if len(packages[state]) > 0:
links = ""
for package in packages[state]:
links += "<a href=\"#%s\">%s</a> " % (package, package)
else:
links = " "
rows += "<tr class=\"normalrow\">" \
+ "<td class=\"labelcell\">%s:</td>" % state \
+ "<td class=\"contentcell2\">%s</td>" % len(packages[state]) \
+ "<td class=\"contentcell2\" colspan=\"4\">%s</td>" % links \
+ "</tr>\n"
distrolinks = "<tr class=\"normalrow\">" \
+ "<td class=\"labelcell\">other distributions: </td>" \
+ "<td class=\"contentcell2\" colspan=\"5\">"
for section in self._section_names:
if section != self._config.section:
distrolinks += "<a href=\"" \
+ self._doc_root \
+ "/" \
+ section \
+ "/maintainer/" \
+ maintainer_subdir(maintainer) \
+ "/" \
+ maintainer \
+ ".html\">" \
+ html_protect(section) \
+ "</a> "
distrolinks += "</td></tr>"
htmlpage = string.Template(HTML_HEADER + MAINTAINER_BODY_TEMPLATE + HTML_FOOTER)
filename = os.path.join(maintainer_subdir_path, maintainer + ".html")
f = file(filename, "w")
f.write(htmlpage.safe_substitute( {
"page_title": html_protect( "Status of " \
+ maintainer \
+ " packages in " \
+ self._config.section),
"maintainer": html_protect(maintainer+" in "+self._config.section),
"distrolinks": distrolinks,
"section_navigation": create_section_navigation(self._section_names,
self._config.section,
self._doc_root),
"time": time.strftime("%Y-%m-%d %H:%M %Z"),
"rows": rows + package_rows,
"doc_root": self._doc_root,
}))
f.close()
def create_source_summary (self, source, logs_by_dir):
source_version = self._source_db.get_control_header(source, "Version")
binaries = self._source_db.get_control_header(source, "Binary")
maintainer = self._source_db.get_control_header(source, "Maintainer")
uploaders = self._source_db.get_control_header(source, "Uploaders")
current_version = self._source_db.get_control_header(source, "Version")
success = True
failed = False
binaryrows = ""
for binary in sorted([x.strip() for x in binaries.split(",") if x.strip()]):
state = self._binary_db.get_package_state(binary)
if state == "unknown":
# Don't track udebs and binary packages on other archs.
# The latter is a FIXME which needs parsing the Packages files from other archs too
continue
if not "waiting" in state and "dependency" in state:
state_style="lightalertlabelcell"
elif state == "failed-testing":
state_style="lightlabelcell"
else:
state_style="labelcell"
binaryrows += "<tr class=\"normalrow\">" \
+ "<td class=\"labelcell\">Binary:</td>" \
+ "<td class=\"contentcell2\">%s</td>" \
% binary\
+ "<td class=\"%s\">piuparts-result:</td>" \
% state_style \
+ "<td class=\"contentcell2\">%s %s</td>" \
% ( self.link_to_state_page(self._config.section,binary,state),
self.links_to_logs(binary, state, logs_by_dir) ) \
+ "<td class=\"labelcell\">Version:</td>" \
+ "<td class=\"contentcell2\">%s</td>" \
% html_protect(current_version) \
+ "</tr>\n"
if state not in ("successfully-tested", "essential-required"):
success = False
if state in ("failed-testing", "dependency-does-not-exist", "cannot-be-tested"):
failed = True
if binaryrows != "":
source_state="unknown"
if success: source_state="<img src=\"%s/images/sunny.png\">" % self._doc_root
if failed: source_state="<img src=\"%s/images/weather-severe-alert.png\">" % self._doc_root
sourcerows = "<tr class=\"titlerow\">" \
+ "<td class=\"titlecell\" colspan=\"6\" id=\"%s\">%s in %s</td>" \
% (source, source, self._config.section) \
+ "</tr>\n"
sourcerows += "<tr class=\"normalrow\">" \
+ "<td class=\"labelcell\">Source:</td>" \
+ "<td class=\"contentcell2\">" \
+ "<a href=\"http://packages.qa.debian.org/%s\" target=\"_blank\">%s</a>" \
% ( source, html_protect(source) ) \
+ "</td>" \
+ "<td class=\"labelcell\">piuparts summary:</td>" \
+ "<td class=\"contentcell2\">%s</td>" \
% source_state \
+ "<td class=\"labelcell\">Version:</td>" \
+ "<td class=\"contentcell2\">%s</td>" \
% html_protect(source_version) \
+ "</tr>\n"
sourcerows += "<tr class=\"normalrow\">" \
+ "<td class=\"labelcell\">Maintainer:</td>" \
+ "<td class=\"contentcell2\" colspan=\"5\">%s</td>" \
% self.link_to_maintainer_summary(maintainer) \
+ "</tr>\n"
if uploaders:
sourcerows += "<tr class=\"normalrow\">" \
+ "<td class=\"labelcell\">Uploaders:</td>" \
+ "<td class=\"contentcell2\" colspan=\"5\">%s</td>" \
% self.link_to_uploaders(uploaders) \
+ "</tr>\n"
source_summary_page_path = os.path.join( self._output_directory,
"source",
source_subdir(source))
if not os.path.exists(source_summary_page_path):
os.makedirs(source_summary_page_path)