2 # $Id: db2html.in,v 1.7 2001/08/16 17:47:31 doogie Exp $
3 # usage: db2html [-diff] [-stampfile=<stampfile>] [-lastrun=<days>] <wwwbase>
5 #load the necessary libraries/configuration
6 $config_path = '/org/bugs.debian.org/etc';
7 $lib_path = '/org/bugs.debian.org/scripts';
9 require("$config_path/config");
10 require("$config_path/text");
11 require("$lib_path/errorlib");
12 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
14 #set current working directory
15 chdir("$gSpoolDir") || die "chdir spool: $!\n";
19 $stampfile = 'stamp.html';
20 $tail_html = $gHTMLTail;
21 $expirynote_html = $gHTMLExpireNote;
22 $shorthead = ' Ref * Package Keywords/Subject Submitter';
26 %displayshowpendings = ('pending','outstanding',
28 'forwarded','forwarded to upstream software authors');
30 #set timestamp for html files
31 chop($dtime=`date -u '+%H:%M:%S GMT %a %d %h'`); $? and die $?;
32 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
34 #check for commandline switches
35 while (@ARGV && $ARGV[0] =~ m/^-/)
36 { if ($ARGV[0] eq '-diff') { $diff=1; }
37 elsif ($ARGV[0] =~ m/^-lastrun\=([0-9.]+)$/) { $lastrun= $1; undef $stampfile; }
38 elsif ($ARGV[0] =~ m/^-full$/) { undef $lastrun; undef $stampfile; }
39 elsif ($ARGV[0] =~ m/^-stampfile\=(\S+)$/) { $stampfile= $1; }
40 else { &quit("bad usage"); }
44 #check for remaing argument, only one...
46 $wwwbase= shift(@ARGV);
49 defined($startdate= time) || &quit("failed to get time: $!");
53 #if stamp file was given,
54 if (defined($stampfile))
55 { if (open(X,"< $stampfile"))
58 printf "progress last run %.7f days\n",$lastrun;
59 } else { print "progress stamp file $stampfile: $! - full\n"; }
62 #only process file if greater than last run...
63 if (defined($lastrun) && -M "db" > $lastrun)
65 s/SUBSTITUTE_DTIME/$dtime/o;
66 s/\<\!\-\-updateupdate\-\-\>.*\<\!\-\-\/updateupdate\-\-\>/check/;
67 &file('ix/zstamp.html','non',$_."</body></html>\n");
69 # print "db2html: no changes since last run\n";
73 #parse maintainer file
74 open(MM,"$gMaintainerFile") || &quit("open $gMaintainerFile: $!");
76 { m/^(\S+)\s+(\S.*\S)\s*$/ || &quit("$gMaintainerFile: \`$_'");
83 #load all database files
84 opendir(D,'db') || &quit("opendir db: $!");
85 @files= sort { $a <=> $b } readdir(D);
88 for $pending (qw(pending done forwarded))
89 { for $severity (@showseverities)
90 { eval "\$index${pending}${severity}= \$iiindex${pending}${severity}= ''; 1;"
91 or &quit("reset \$index${pending}${severity}: $@");
96 { next unless $f =~ m/^(-?\d+)\.log$/;
98 #((print STDERR "$ref\n"),
101 # unless $ref =~ m/^-/ || $ref =~ m/^124/;
102 &filelock("lock/$ref");
103 $preserveonly= defined($lastrun) && -M "db/$ref.log" > $lastrun;
104 if ($ref =~ m/^-\d$/)
105 { $week= $ref eq '-1' ? 'this week' :
106 $ref eq '-2' ? 'last week' :
107 $ref eq '-3' ? 'two weeks ago' :
108 ($ref-1)." weeks ago";
109 $linkto= "ju/unmatched$ref";
110 $short= "junk, $week";
112 "This includes messages sent to <code>done\@$gEmailDomain</code>\n".
113 "which did not have a $gBug reference number in the Subject line\n".
114 "or which contained an\n".
115 "unknown or out of date $gBug report number (these cause a warning\n".
116 "to be sent to the sender) and details about the messages\n".
117 "sent to <code>request@$gEmailDomain</code> (all of which".
118 "produce replies).\n";
119 $indexlink= "Messages not matched to a specific $gBug report - $week";
125 $tpackfile= "pnone.html";
126 $indexpart= 'unmatched';
128 { open(S,"db/$ref.status") || &quit("open db/$ref.status: $!");
129 chomp($s_originator= <S>);
131 chomp($s_subject= <S>);
132 chomp($s_msgid= <S>);
133 chomp($s_package= <S>);
134 chomp($s_keywords= <S>);
136 chomp($s_forwarded= <S>);
137 chomp($s_mergedwith= <S>);
138 chomp($s_severity= <S>);
139 $_= $s_package; y/A-Z/a-z/; $_= $` if m/[^-+._a-z0-9()]/;
141 if ($s_severity eq '' || $s_severity eq 'normal')
143 $addseverity= $gDefaultSeverity;
144 } elsif (grep($s_severity eq $_, @strongseverities))
145 { $showseverity= "<strong>Severity: $s_severity</strong>;\n";
146 $addseverity= $s_severity;
148 { $showseverity= "Severity: <em>$s_severity</em>;\n";
149 $addseverity= $s_severity;
151 $days= int(($startdate - $s_date)/86400); close(S);
152 $indexlink= "#$ref: ".&sani($s_subject);
154 $packfile= length($tpack) ? "pa/l$tpack.html" : "pa/none.html";
155 $indexentry .= "Package: <A href=\"../$packfile\"><strong>".
156 &sani($s_package)."</strong></A>;\n"
157 if length($s_package);
158 $indexentry .= $showseverity;
159 $indexentry .= "Reported by: ".&sani($s_originator);
160 $indexentry .= ";\nKeywords: ".&sani($s_keywords)
161 if length($s_keywords);
162 $linkto= $ref; $linkto =~ s,^..,$&/$&,;
163 @merged= split(/ /,$s_mergedwith);
165 { $mseparator= ";\nmerged with ";
167 { $mfile= $m; $mfile =~ s,^..,$&/$&,;
168 $indexentry .= $mseparator."<A href=\"../$mfile.html\">#$m</A>";
172 $daysold=$submitted='';
174 { $indexentry .= ";\n<strong>Done:</strong> ".&sani($s_done);
175 $indexpart= "done$addseverity";
176 } elsif (length($s_forwarded))
177 { $indexentry .= ";\n<strong>Forwarded</strong> to ".&sani($s_forwarded);
178 $indexpart= "forwarded$addseverity";
180 { $cmonths= int($days/30);
181 if ($cmonths != $amonths)
182 { $msg= $cmonths == 0 ? "Submitted in the last month" :
183 $cmonths == 1 ? "Over one month old" :
184 $cmonths == 2 ? "Over two months old - attention is required" :
185 "OVER $cmonths MONTHS OLD - ATTENTION IS REQUIRED";
186 $shortindex .= "</pre><h2>$msg:</h2><pre>\n$shorthead\n";
189 $pad= 6-length(sprintf("%d",$f));
191 ($pad>0 ? ' 'x$pad : '').
192 sprintf("<A href=\"../%s.html\">%d</A>",$linkto,$ref).
193 &sani(sprintf(" %-1.1s %-10.10s %-35.35s %-.25s\n",
196 (length($s_keywords) ? $s_keywords.'/' : '').
197 $s_subject, $s_originator));
198 $shortindex.= $thissient;
199 $sient{"$ref $s_package"}= $thissient;
201 { $font= $days <= 30 ? '' :
204 $efont= length($font) ? "</$font>" : '';
205 $font= length($font) ? "<$font>" : '';
206 $daysold= "; $font$days days old$efont";
208 if ($preserveonly) { $submitted= 'THIS IS A BUG IN THE BUG PROCESSOR'; }
210 { $submitted= `TZ=GMT LANG=C \\
211 date -d '1 Jan 1970 00:00:00 + $s_date seconds' \\
212 '+ %a, %d %b %Y %T %Z'`;
215 $submitted =~ s/\n$//; $submitted =~ s/, 0/, /g;
216 $submitted= "; dated $submitted";
217 $indexpart= "pending$addseverity";
220 $short= $ref; $short =~ s/^\d+/#$&/;
221 $tmaint= defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
222 $qpackage= &sani($_);
223 $descriptivehead= $indexentry.$submitted.";\nMaintainer for $qpackage is\n".
224 '<A href="../ma/l'.&maintencoded($tmaint).'.html">'.&sani($tmaint).'</A>.';
225 $indexentry .= $daysold;
229 $indexadd .= "<!--iid $iiref-->" if defined($iiref);
230 $indexadd .= "<li><A href=\"../$linkto.html\">".$indexlink."</A>";
231 $indexadd .= "<br>\n".$indexentry if length($indexentry);
232 $indexadd .= "<!--/iid-->" if defined($iiref);
234 $estr= "\$index$indexpart = \$indexadd.\$index$indexpart; 1;";
235 eval($estr) || &quit("eval add to \$index$indexpart ($estr) failed: $@");
236 #print STDERR ">$estr|$indexadd<\n";
237 $indexadd= "<!--ii $iiref-->\n" if defined($iiref);
238 eval("\$iiindex$indexpart = \$indexadd.\$iiindex$indexpart; 1;") ||
239 &quit("eval add to \$iiindex$indexpart failed: $@");
240 if (defined($tmaint))
241 { $countpermaint{$tmaint} += length($s_done) ? 0 : length($s_forwarded) ? 0 : 1;
242 eval("\$permaint${indexpart}{\$tmaint} .= \$indexadd; 1;") ||
243 &quit("eval add to \$permaint${indexpart}{\$tmaint} failed: $@");
246 { $countperpack{$tpack} += length($s_done) ? 0 : length($s_forwarded) ? 0 : 1;
247 eval("\$perpack${indexpart}{\$tpack} .= \$indexadd; 1;") ||
248 &quit("eval add to \$perpack${indexpart}{\$tpack} failed: $@");
250 if ($preserveonly) { &preserve("$linkto.html"); &preserve("$linkto-b.html"); &unfilelock; next; }
251 open(L,"db/$ref.log") || &quit("open db/$ref.log: $!");
253 $boring=''; $xmessage= 0;
254 $normstate= 'kill-init';
258 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
259 &quit("$ref ^G in state $normstate");
260 $normstate= 'incoming-recv';
262 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
263 &quit("$ref ^A in state $normstate");
264 $normstate= 'autocheck';
266 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
267 &quit("$ref ^B in state $normstate");
268 $normstate= 'recips';
270 $normstate eq 'go' || $normstate eq 'go-nox' || $normstate eq 'html' ||
271 &quit("$ref ^C in state $normstate");
272 $this .= "</pre>\n" if $normstate eq 'go' || $normstate eq 'go-nox';
273 if ($normstate eq 'html') {
275 $this .= " <em><A href=\"../$linkto-b.html#m$xmessage\">Full text</A>".
278 if ($suppressnext && $normstate ne 'html') {
279 $ntis= $this; $ntis =~ s:\<pre\>:</A><pre>:i;
280 $boring .= "<hr><A name=\"m$xmessage\">\n$ntis\n";
282 $log = $this. "<hr>\n". $log;
284 $suppressnext= $normstate eq 'html';
285 $normstate= 'kill-end';
287 $normstate eq 'kill-body' || &quit("^E in state $normstate");
291 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
292 &quit("$ref ^F in state $normstate");
293 $normstate= 'html'; $this= '';
294 } elsif ($normstate eq 'incoming-recv') {
295 $pl= $_; $pl =~ s/\n+$//;
296 m/^Received: \(at (\S+)\) by (\S+)\;/ ||
297 &quit("bad line \`$pl' in state incoming-recv");
298 $this = "<h2>Message received at ".&sani("$1\@$2").":</h2><br>\n".
302 } elsif ($normstate eq 'html') {
304 } elsif ($normstate eq 'go') {
306 } elsif ($normstate eq 'go-nox') {
309 } elsif ($normstate eq 'recips') {
311 $this = "<h2>Message sent:</h2><br>\n";
314 $this = "<h2>Message sent to ".&sani($_).":</h2><br>\n";
316 $normstate= 'kill-body';
317 } elsif ($normstate eq 'autocheck') {
318 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
319 $normstate= 'autowait';
320 $this = "<h2>Message received at $2:</h2><br>\n";
321 } elsif ($normstate eq 'autowait') {
323 $normstate= 'go-nox';
326 &quit("$ref state $normstate line \`$_'");
329 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
331 if (length($boring)) {
332 &file("$linkto-b.html",'non',
333 "<html><head><title>$gProject $gBug report logs - ".
334 "$short, boring messages</title>\n".
335 "<link rev=\"made\" href=\"mailto:$gMaintainerEmail)\">\n".
336 "</head>$gHTMLStart<h1>$gProject $gBugreport logs -".
337 "\n <A href=\"../$linkto.html\">$short</A>,".
338 " boring messages</h1>\n$boring\n<hr>\n".
339 $tail_html."</body></html>\n");
341 &file("$linkto.html",'non',
342 "<html><head><title>$gProject $gBug report logs - ".
344 "<link rev=\"made\" href=\"mailto:$gMaintainerEmail\">\n".
345 "</head>$gHTMLStart<h1>$gProject $gBug report logs - $short<br>\n".
346 &sani($s_subject)."</h1>".
347 "$descriptivehead\n".
350 $tail_html."</body></html>\n");
356 s/([^<>()]+) \(([^()<>]+)\)/$2 \<$1\>/;
360 $email= s/ *\<[^<>()]+\>$//g ? $& : '';
361 $_= "$1 $_" if s/ (\S+)$//;
367 return $maintencoded{$_[0]} if defined($maintencoded{$_[0]});
369 local ($todo,$encoded)= ($input);
370 while ($todo =~ m/\W/) {
371 $encoded.=$`.sprintf("-%02x_",unpack("C",$&));
375 $encoded =~ s/-2e_/\./g;
376 $encoded =~ s/^([^,]+)-20_-3c_(.*)-40_(.*)-3e_/$1,$2,$3,/;
377 $encoded =~ s/^(.*)-40_(.*)-20_-28_([^,]+)-29_$/,$1,$2,$3/;
378 $encoded =~ s/-20_/_/g;
379 $encoded =~ s/-([^_]+)_-/-$1/g;
380 $maintencoded{$input}= $encoded;
383 for $tmaint (keys %countpermaint) {
385 $after=$before=$sort2d=$sort2s=$sort1d=$sort1s='';
386 $after= "$&$after" if s/\s*\<[^<>()]+\>\s*$//;
387 $after= "$&$after" if s/\s*\)\s*$//;
388 $after= "$&$after" if s/\s*,.*$//;
389 $before.= $& if s/^.*\(\s*//;
390 $sort2d= $& if s/\S+$//;
392 while (s/^([^()<>]+)\. */$1 /) { };
393 s/\s+$//; y/A-Za-z/a-zA-Z/; $sort1s= $_;
394 $sort2s= $sort2d; $sort2s =~ y/A-Za-z/a-zA-Z/;
395 $maintsort{$tmaint}= $sort2s.' '.$sort1s.' '.$before.$sort1d.$sort2d.$after;
396 $maintdisplay{$tmaint}=
397 &sani($before).'<strong>'.&sani($sort1d.$sort2d).'</strong>'.&sani($after);
402 return $displayshowseverities{$sv}.' - '.$displayshowpendings{$pt};
405 sub makeindex ($$$) {
406 my ($varprefix,$varsuffix,$tkey) = @_;
407 my ($pending,$severity,$anydone,$text);
410 for $pending (qw(pending forwarded done)) {
411 for $severity (@showseverities) {
412 $estr= "\$value= \\${varprefix}${pending}${severity}${varsuffix}; 1;";
415 or &quit("eval get \$${varprefix}${pending}${severity} failed: $@");
416 #print STDERR ">$$value<\n";
417 next unless length($$value);
418 $text.= "<hr>\n<h2>".&heading($pending,$severity).":</h2>\n".
419 "(List of <A href=\"../si/$pending$severity.html\">all".
420 " such $gBugs</A> is available.)\n<ul>\n".
423 $anydone=1 if $pending eq 'done';
426 $text.= $expirynote_html if $anydone;
430 &file("ix/full.html",'def',
432 makeindex('$index',"",'').
434 $tail_html."</body><html>\n");
436 &file("ju/junk.html",'non',
438 "<hr>\n<h2>Junk (messages without a specific $gBug report number):</h2>\n".
439 "(\`this week' is everything since last Wednesday.)\n<ul>\n".
442 $tail_html."</body><html>\n");
444 $nobugs_html= "No reports are currently in this state.";
445 $who_html= $gProject;
446 $owner_addr= $gMaintainerEmail;
447 $otherindex_html= "For other kinds of index or for other information about
448 $gProject and the $gBug system, see the <A HREF\"../../\">$gBug system top-level
449 contents WWW page</A>.
453 for $pending (qw(pending forwarded done)) {
454 for $severity (@showseverities) {
455 eval "\$value= \\\$iiindex${pending}${severity}; 1;"
456 or &quit("eval get \$iiindex${pendingtype}${severity} failed: $@");
457 $value= \$nobugs_html if !length($$value);
458 $headstring= &heading($pending,$severity);
459 &file("si/$pending$severity.html",'ref',
460 "<html><head><title>$who_html $gBug reports: $headstring</title>\n".
461 "<link rev=\"made\" href=\"mailto:".&sani($owner_addr)."\">\n".
462 "</head>$gHTMLStart<h1>$who_html $gBug reports: $headstring</h1>\n".
464 ($pending eq 'done' ? "<P>\n$expirynote_html" : '').
468 $tail_html."</body></html>\n");
472 sub individualindexes ($\@&\%&&$$$$$&&) {
473 my ($filename,$keysref,$getfilenameref,$countref,$getdisplayref,
474 $getsimpledisplayref,$what,$caveat,$whatplural,$abbrev,$ihead,
475 $getxinforef,$getxindexref) = @_;
476 my ($itext,$i,$tkey,$sani,$count,$tfilename,$refto,$backnext,$xitext,$bugbugs);
478 for ($i=0; $i<=$#$keysref; $i++) {
479 $tkey= $$keysref[$i];
480 $tfilename= &$getfilenameref($tkey);
481 $sani= &$getsimpledisplayref($tkey);
482 $count= $$countref{$tkey};
483 $count= $count >= 1 ? "$count" : "no";
484 $bugbugs= $count == 1 ? "$gBug" : "$gBugs";
485 $xitext= &$getxindexref($tkey);
486 $xitext= length($xitext) ? "$count $bugbugs; $xitext"
487 : "$count outstanding $bugbugs";
488 $itext .= "<li><A href=\"../$tfilename\">".&$getdisplayref($tkey)."</A>"."\n".
492 $refto= $$keysref[$i-1];
493 $xitext= &$getxindexref($refto);
494 $xitext= " ($xitext)" if length($xitext);
495 $backnext .= "<br>\nPrevious $what in list, <A href=\"../".
496 &$getfilenameref($refto)."\">".&$getdisplayref($refto)."</A>".
500 $refto= $$keysref[$i+1];
501 $xitext= &$getxindexref($refto);
502 $xitext= " ($xitext)" if length($xitext);
503 $backnext .= "<br>\nNext $what in list, <A href=\"../".
504 &$getfilenameref($refto)."\">".&$getdisplayref($refto)."</A>".
507 &file($tfilename,'ref',
508 "<html><head><title>$gProject $gBug reports: $what $sani</title>\n".
509 "<link rev=\"made\" href=\"mailto:$gMaintainerEmail\">\n".
510 "</head>$gHTMLStart<h1>$gProject $gBug reports: $what $sani</h1>\n".
511 &$getxinforef($tkey).
513 "See the <A href=\"../$filename\">listing of $whatplural</A>.\n".
515 &makeindex("\$per${abbrev}","{\$tkey}",$tkey).
517 $tail_html."</body></html>\n");
519 &file($filename,'non',
524 $tail_html."</body></html>\n");
527 @maintainers= sort { $maintsort{$a} cmp $maintsort{$b}; } keys %countpermaint;
528 individualindexes('ix/maintainers.html',
530 sub { 'ma/l'.&maintencoded($_[0]).'.html'; },
532 sub { $maintdisplay{$_[0]}; },
533 sub { &sani($_[0]); },
535 "Note that there may be other reports filed under different
536 variations on the maintainer\'s name and email address.<P>",
543 @packages= sort keys %countperpack;
544 individualindexes('ix/packages.html',
546 sub { length($_[0]) ? "pa/l$_[0].html" : 'pa/none.html'; },
548 sub { length($_[0]) ? $_[0] : 'not specified'; },
549 sub { &sani(length($_[0]) ? $_[0] : 'not specified'); },
551 "Note that with multi-binary packages there may be other
552 reports filed under the different binary package names.<P>",
557 return unless defined($maintainer{$_[0]});
558 $tmaint= $maintainer{$_[0]};
559 return "Maintainer for $_[0] is <A href=\"../ma/l".
560 &maintencoded($tmaint).
561 ".html\">".&sani($tmaint)."</A>.\n<p>\n";
564 return unless defined($maintainer{$_[0]});
565 $tmaint= $maintainer{$_[0]};
566 return "<A href=\"../ma/l".
567 &maintencoded($tmaint).
568 ".html\">".&sani($tmaint)."</A>";
571 &file('ix/summary.html','non',
576 $tail_html."</body></html>\n");
579 for $k (map {$_->[0] }
580 sort { $a->[2] cmp $b->[2] || $a->[1] <=> $b->[1] }
581 map { [$_, split(' ',$_,2)] } keys %sient)
582 { $bypackageindex.= $sient{$k}; }
583 &file('ix/psummary.html','non',
585 "<hr><pre>\n$shorthead\n".
588 $tail_html."</body></html>\n");
590 open(P,"$gPseudoDescFile") ||
591 &quit("$gPseudoDescFile: $!");
592 $ppd=''; while(<P>) { s/\s*\n$//; $ppd.= &sani($_)."\n"; } close(P);
593 &file('ix/pseudopackages.html','non',
597 $tail_html."</body></html>\n");
599 $_= $gHTMLStamp; s/SUBSTITUTE_DTIME/$dtime/o;
601 &file('ix/zstamp.html','non',$_."</body></html>\n");
603 sub notimestamp ($) {
605 s/\<\!\-\-timestamp\-\-\>\n.*\n\<\!\-\-\/timestamp\-\-\>\n//;
610 local ($name,$ii,$file)= @_;
612 $cmppath= "$wwwbase/$name".($ii eq 'ref' ? '.ref' : '');
613 if (open(ORIG,"$cmppath")) {
614 undef $/; $orig= <ORIG>; $/= "\n";
616 if (¬imestamp($orig) eq ¬imestamp($file)) {
617 print "preserve $name\n";
620 defined($c= open(P,"-|")) or &quit("pipe/fork for diff: $!");
622 open(Q,"|diff -e $cmppath -") or die "pipe/fork II for diff: $!\n";
623 print Q $file or die "write orig to diff: $!\n";
624 close(Q); $?==0 || $?==256 or die "diff gave $?\n";
627 undef $/; $difftxt= <P>; $/= "\n";
628 close(P); $?==0 || $?==256 or die "diff fork gave $?\n";
630 print "preserve $name\n";
633 $v= (split(/\n/,$difftxt));
634 print "diff $v $ii $name\n${difftxt}thatdiff $name\n"
635 or &quit("stdout (diff): $!");
639 $v= (split(/\n/,$file));
640 print "file $v $ii $name\n${file}thatfile $name\n" or &quit("stdout: $!");
644 print "preserve $_[0]\n";
649 while ($u= $cleanups[$#cleanups]) { &$u; }