-
Notifications
You must be signed in to change notification settings - Fork 10
/
piuparts-report.py
1915 lines (1669 loc) · 77.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/python3
# -*- coding: utf-8 -*-
#
# Copyright 2005 Lars Wirzenius ([email protected])
# Copyright 2009-2019 Holger Levsen ([email protected])
# Copyright © 2011-2018 Andreas Beckmann ([email protected])
# Copyright 2013 David Steele ([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, see <https://www.gnu.org/licenses/>
"""Create HTML reports of piuparts log files
Lars Wirzenius <[email protected]>
"""
import os
import sys
import time
import logging
import shutil
import re
import string
import yaml
import hashlib
import pickle
import random
import fcntl
from collections import deque
# if python-rpy2 ain't installed, we don't draw fancy graphs
try:
from rpy2 import robjects
from rpy2.robjects.packages import importr
except:
pass
import piupartslib.conf
import piupartslib.packagesdb
from piupartslib.conf import MissingSection
from piupartslib.dwke import *
import piupartslib.pkgsummary as pkgsummary
from six.moves.urllib.error import HTTPError, URLError
CONFIG_FILE = "/etc/piuparts/piuparts.conf"
DISTRO_CONFIG_FILE = "/etc/piuparts/distros.conf"
KPR_DIRS = ('pass', 'bugged', 'affected', 'fail')
TPL_EXT = '.tpl'
PIUPARTS_VERSION = "__PIUPARTS_VERSION__"
HTML_HEADER = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- $content_md5 -->
<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="https://www.debian.org/">
<img src="$doc_root/images/openlogo-nd-50.png" border="0" hspace="0" vspace="0" alt=""></a>
<a href="https://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</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="$doc_root/news.html">News</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://wiki.debian.org/piuparts/FAQ" target="_blank">FAQ</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="mailto:[email protected]" target="_blank">Contact us</a>
</td>
</tr>
<tr class="titlerow">
<td class="titlecell">
Documentation
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="$doc_root/bug_howto.html">How to file bugs</a><br />
using <a href="$doc_root/templates/mail/">templates</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://www.debian.org/doc/debian-policy/" target="_blank">Debian policy</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
piuparts.d.o configuration:<br>
<a href="https://salsa.debian.org/debian/piuparts/tree/develop/instances" target="_blank">piuparts.conf</a>,<br>
<a href="https://salsa.debian.org/debian/piuparts/blob/develop/conf/distros.conf" target="_blank">distros.conf</a>,<br>
<a href="https://salsa.debian.org/debian/piuparts/tree/develop/custom-scripts" target="_blank">scripts</a> and
<a href="https://piuparts.debian.org/logs/" target="_blank">logs</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="$doc_root/doc/README.html" target="_blank">README</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="$doc_root/doc/README_server.html" target="_blank">README_server</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="titlerow">
<td class="alerttitlecell">
Summaries
</td>
</tr>
<tr>
<td class="contentcell">
<a href="https://bugs.debian.org/cgi-bin/pkgreport.cgi?tag=piuparts;[email protected]&archive=both" target="_blank">Bugs filed</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://piuparts.debian.org/overview.html" target="_blank">Suites overview</a>
</td>
</tr>
$section_navigation
<tr class="titlerow">
<td class="titlecell">
src: piuparts
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://salsa.debian.org/debian/piuparts.git" target="_blank">Source</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
piuparts.d.o <a href="https://bugs.debian.org/src:piuparts.debian.org" target="_blank">bugs</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
piuparts <a href="https://bugs.debian.org/src:piuparts" target="_blank">bugs</a> / <a href="https://salsa.debian.org/debian/piuparts/blob/develop/TODO" target="_blank">ToDo</a>
</td>
</tr>
<tr class="titlerow">
<td class="titlecell">
Other Debian QA efforts
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://wiki.debian.org/qa.debian.org" target="_blank">Debian QA Group</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://qa.debian.org/dose/" target="_blank">Dose tools (former: EDOS)</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://lintian.debian.org" target="_blank">Lintian</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://tracker.debian.org" target="_blank">Debian Package Tracker</a>
</td>
<tr class="normalrow">
<td class="contentcell">
<a href="https://udd.debian.org" target="_blank">Ultimate Debian Database</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="https://jenkins.debian.net" target="_blank">jenkins.debian.net</a>
</td>
</tr>
<tr class="normalrow">
<td class="contentcell">
<a href="http://ci.debian.net" target="_blank">ci.debian.net</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="https://tracker.debian.org/pkg/piuparts" target="_blank">piuparts</a>
is GPL2 <a href="https://packages.debian.org/changelogs/pool/main/p/piuparts/current/copyright" target="_blank">licenced</a>
and was originally written by <a href="mailto:[email protected]">Lars Wirzenius</a> and today is maintained by
<a href="mailto:[email protected]">Andreas Beckmann</a> and
<a href="mailto:[email protected]">Holger Levsen</a> and
<a href="mailto:[email protected]">others</a> using
<a href="https://salsa.debian.org/debian/piuparts.git" target="_blank">piuparts.git</a>.
Ditto for this website.
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.
</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>
"""
BASIC_BODY_TEMPLATE = """
<table class="righttable">
$rows
</table>
"""
PROB_TPL = \
"""<tr class="titlerow"><td class="titlecell">
$HEADER in $SECTION, sorted by reverse dependency count.
</td></tr><tr class="normalrow"><td class="contentcell2">
$HELPTEXT
<p>The commandline to find these logs is: <pre>
COMMAND='$COMMAND'
</pre></p>
</td></tr><tr class="titlerow"><td class="alerttitlecell">Please file bugs!</td></tr><tr class="normalrow"><td class="contentcell2" colspan="3">
<ul>
$PACKAGE_LIST</ul>
<p>Affected packages in $SECTION: $COUNT</p></td></tr>
"""
PKG_ERROR_TPL = \
"""<li>$RDEPS - <a href=\"$LOG\">$LOG</a>$ARCH
(<a href=\"https://piuparts.debian.org/$SECTION/source/$SSUBDIR/$SPKG.html\" target=\"_blank\">piuparts.d.o</a>)
(<a href=\"https://tracker.debian.org/pkg/$SPKG\" target=\"_blank\">tracker.d.o</a>)
(<a href=\"https://bugs.debian.org/$PACKAGE?dist=unstable\" target=\"_blank\">BTS</a>)
$BUG</li>
"""
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"),
("db_setup_issue.tpl", "but logfile contains failure to setup a database"),
("problems_and_no_force_issue.tpl", "but logfile reports that not enough force was used"),
("installs_over_symlink_issue.tpl", "but package installs something over existing symlinks"),
("broken_symlinks_issue.tpl", "but logfile contains 'broken symlinks'"),
("unknown_inadequate_issue.tpl", "but logfile contains unknown inadequate issues"),
("boring_obsolete_conffile_file_inadequate_issue.tpl", "...and logfile contains tag from adequate 'obsolete-conffile-file'"),
("boring_broken_symlink_file_inadequate_issue.tpl", "...and logfile contains tag from adequate 'broken-symlink-file'"),
("bin_or_sbin_binary_requires_usr_lib_library_inadequate_issue.tpl", "but adequate found a binary in /bin or /sbin that requires a /usr/lib library"),
("incompatible_licenses_inadequate_issue.tpl", "but adequate found a license incompatibility"),
("broken_binfmt_detector_inadequate_issue.tpl", "but adequate did not find the detector registered with update_binfmts"),
("broken_binfmt_interpreter_inadequate_issue.tpl", "but adequate did not find the interpreter registered with update_binfmts"),
("missing_alternative_inadequate_issue.tpl", "but adequate found a missing alternative"),
("missing_copyright_file_inadequate_issue.tpl", "but adequate couldn't find a copyright file"),
("missing_pkgconfig-dependency_issue.tpl", "but adequate found a missing pkgconfig dependency"),
("program_name_collision_inadequate_issue.tpl", "but adequate found a program name collision"),
("py_file_not_bytecompiled_inadequate_issue.tpl", "but adequate found a .py file that is not byte-compiled"),
("pyshared_file_not_bytecompiled_inadequate_issue.tpl", "but adequate found a .py file in /usr/share/pyshared that is not byte-compiled"),
("ldd_inadequate_issue.tpl", "but adequate failed to run ldd on a binary or library"),
("library_not_found_inadequate_issue.tpl", "but adequate couldn't find a required library"),
("undefined_symbol_inadequate_issue.tpl", "but adequate found an undefined symbol"),
("symbol-size-mismatch_inadequate_issue.tpl", "but adequate found that a symbol has changed size since the package was built"),
("missing-symbol-version-information_inadequate_issue.tpl", "but adequate found that a library is missing symbol version information"),
("unknown_inadequate_issue.tpl", "but an unknown adequate issue was found"),
("inadequate_exit_issue.tpl", "but adequate exited inadequately"),
("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"),
("module_build_error_issue.tpl", "but logfile contains dkms module build failures"),
("obsolete_conffiles_issue.tpl", "but logfile reports obsolete conffiles"),
("missing_md5sums_issue.tpl", "but logfile reports missing md5sums"),
("unowned_lib_symlink_issue.tpl", "but logfile reports unowned lib symlinks"),
("piuparts-depends-dummy_issue.tpl", "but logfile reports piuparts-depends-dummy.deb could not be installed"),
("used_exception_issue.tpl", "but package used a piuparts exception"),
("test_was_skipped_issue.tpl", "but package test was skipped"),
("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"),
("trigger_cycle_error.tpl", "due to dpkg encountered trigger problems"),
("immediate_configuration_error.tpl", "due to apt could not perform immediate configuration"),
("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'"),
("module_build_error_error.tpl", "...and logfile contains dkms module build failures"),
("obsolete_conffiles_error.tpl", "...and logfile reports obsolete conffiles"),
("missing_md5sums_error.tpl", "...and logfile reports missing md5sums"),
("unowned_lib_symlink_error.tpl", "...and logfile reports unowned lib symlinks"),
("piuparts-depends-dummy_error.tpl", "...and logfile reports piuparts-depends-dummy.deb could not be installed"),
("file_moved_usr_error,tpl", "...and logfile reports a file moved between /{bin|sbin|lib*} and /usr/{bin|sbin|lib*}"),
("file_moved_usr_issue,tpl", "but logfile reports a file moved between /{bin|sbin|lib*} and /usr/{bin|sbin|lib*}"),
("unclassified_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": "/",
"known-problem-directory": "@sharedir@/piuparts/known_problems",
"exclude-known-problems": None,
"json-sections": "default",
"precedence": 1,
"web-host": "piuparts.debian.org",
},
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 is_bad_state(state):
bad_states = [
#"successfully-tested",
"failed-testing",
"cannot-be-tested",
# "essential-required", # obsolete
#"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
"outdated",
#"foreign:*",
"does-not-exist",
]
return(state in bad_states)
def emphasize_reason(reason):
if is_bad_state(reason):
reason = "<em>" + reason + "</em>"
return reason
def source_subdir(source):
if source[:3] == "lib":
return source[:4]
else:
return source[:1]
def source_summary_url(web_host, doc_root, section, src_pkg):
return("https://%s%s/%s/source/%s/%s.html" %
(
web_host,
doc_root,
section,
source_subdir(src_pkg),
src_pkg,
)
)
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 xxx_todo_changeme:
(errno, strerror) = xxx_todo_changeme.args
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 create_file(filename, contents):
with open(filename, "w") as f:
f.write(contents)
def append_file(filename, contents):
with open(filename, "a") as f:
f.write(contents)
def read_file(filename):
with open(filename, "r") as f:
return f.read()
def readlines_file(filename):
with open(filename, "r") as f:
return f.readlines()
def fileage(filename):
mtime = os.path.getmtime(filename)
now = time.time()
return now - mtime
def write_template_html(filename, body, mapping={}, defer_if_unmodified=False, md5cache=None):
header = HTML_HEADER
footer = HTML_FOOTER
htmlpage = string.Template(header + body + footer)
mapping = mapping.copy()
mapping.update({
"content_md5": "",
"piuparts_version": "",
"time": "",
})
content_md5 = hashlib.md5(htmlpage.safe_substitute(mapping).encode()).hexdigest()
if md5cache is not None:
md5cache['new'][filename] = content_md5
if defer_if_unmodified:
if filename in md5cache['old'] and md5cache['old'][filename] == content_md5 and os.path.exists(filename):
md5cache['unmodified'] += 1
# defer updating the file between 1 and 4 weeks
minage = 1 * 7 * 86400
maxage = 4 * 7 * 86400
if fileage(filename) < random.randint(minage, maxage):
return
md5cache['refreshed'] += 1
if defer_if_unmodified and not filename in md5cache['old'] and os.path.exists(filename):
# read the first 10 lines of the old file and look for a matching md5sum
with open(filename, "r") as f:
lineno = 0
for x in range(10):
line = f.readline()
if not line:
break
if line.startswith("<!-- ") and line[5:5 + len(content_md5)] == content_md5:
md5cache['unmodified'] += 1
# defer updating the file between 1 and 4 weeks
minage = 1 * 7 * 86400
maxage = 4 * 7 * 86400
if fileage(filename) < random.randint(minage, maxage):
return
md5cache['refreshed'] += 1
break
mapping.update({
"content_md5": content_md5,
"piuparts_version": PIUPARTS_VERSION,
"time": time.strftime("%Y-%m-%d %H:%M %Z"),
})
create_file(filename, htmlpage.safe_substitute(mapping))
if md5cache is not None:
md5cache['written'] += 1
def create_section_navigation(section_names, current_section, doc_root):
tablerows = "<tr class=\"titlerow\"><td class=\"alerttitlecell\">Suite: <a href='%s/%s'>%s</a></td></tr>" \
% (doc_root, current_section, current_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)
tablerows += "<tr><td class=\"contentcell\">states <a href=\"%s/%s/states.png\">graph</a></td></tr>\n" \
% (doc_root, current_section)
tablerows += "<tr class=\"titlerow\"><td class=\"alerttitlecell\">all tested suites</td></tr>"
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))
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
def package2id(package_name):
# "+" is not a valid identifier char for id=... attributes
return package_name.replace("+", "_")
# return order preserving list of the first occurrence of an element
def unique(stuff):
# can't use set() because 'stuff' is a list of lists and list() is not hashable
vlist = []
previtem = stuff
for item in stuff:
if item != previtem:
vlist.append(item)
previtem = item
return vlist
class Busy(Exception):
def __init__(self):
self.args = "section is locked by another process",
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")
self._packagedb_cache = packagedb_cache
self._package_databases = {}
self._load_package_database(section, master_directory)
self._binary_db = self._package_databases[section]
self._source_db = piupartslib.packagesdb.PackagesDB(prefix=self._section_directory)
self._source_db.load_packages_urls(
self._distro_config.get_sources_urls(
self._config.get_distro(),
self._config.get_area()))
if self._config.get_distro() != self._config.get_final_distro():
# take version numbers (or None) from final distro
self._source_db.load_alternate_versions_from_packages_urls(
self._distro_config.get_sources_urls(
self._config.get_final_distro(),
self._config.get_area()))
self._log_name_cache = {}
self._md5cache = { 'old': {}, 'new': {}, 'written': 0, 'unmodified': 0, 'refreshed': 0 }
def _load_package_database(self, section, master_directory):
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()
sectiondir = os.path.join(master_directory, section)
db = piupartslib.packagesdb.PackagesDB(prefix=sectiondir)
self._package_databases[section] = db
if config["depends-sections"]:
deps = config["depends-sections"].split()
for dep in deps:
self._load_package_database(dep, master_directory)
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
db.load_packages_urls(
self._distro_config.get_packages_urls(
config.get_distro(),
config.get_area(),
config.get_arch()))
if config.get_distro() != config.get_final_distro():
# take version numbers (or None) from final distro
db.load_alternate_versions_from_packages_urls(
self._distro_config.get_packages_urls(
config.get_final_distro(),
config.get_area(),
config.get_arch()))
def _write_template_html(self, filename, body, mapping={}, defer_if_unmodified=False):
mapping = mapping.copy()
mapping.update({
"section_navigation": self._section_navigation,
"doc_root": self._doc_root,
"section": html_protect(self._config.section),
})
write_template_html(filename, body, mapping, defer_if_unmodified=defer_if_unmodified, md5cache=self._md5cache)
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 = sorted(packages.keys())
lines = []
for package in names:
versions = []
for pathname, version in packages[package]:
cruft = ""
bin_pkg = self._binary_db.get_package(package)
if self._source_db.has_package(bin_pkg.source()) and \
bin_pkg.source_version() != self._source_db.get_version(bin_pkg.source()):
cruft = " [cruft]"
versions.append("<a href=\"%s\">%s</a>%s" %
(html_protect(pathname),
html_protect(version),
cruft))
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"
self._write_template_html(
filename,
LOG_LIST_BODY_TEMPLATE,
{
"page_title": html_protect(title + " in " + self._config.section),
"title": html_protect(title),
"title_style": title_style,
"preface": preface,
"count": len(packages),
"logrows": "".join(lines),
})
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_package(package_name).source()