2 # $Id: db2html.in,v 1.19 2003/08/06 10:57:23 cjwatson Exp $
3 # usage: db2html [-diff] [-stampfile=<stampfile>] [-lastrun=<days>] <wwwbase>
5 #load the necessary libraries/configuration
6 $config_path = '/etc/debbugs';
7 $lib_path = '/usr/lib/debbugs';
9 require("$config_path/config");
10 require("$config_path/text");
11 require("$lib_path/errorlib");
12 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
14 use POSIX qw(strftime tzset);
18 #set current working directory
19 chdir("$gSpoolDir") || die "chdir spool: $!\n";
23 $stampfile = 'stamp.html';
24 $tail_html = $gHTMLTail;
25 $expirynote_html = '';
26 $expirynote_html = $gHTMLExpireNote if $gRemoveAge;
27 $shorthead = ' Ref * Package Keywords/Subject Submitter';
31 %displayshowpendings = ('pending','outstanding',
33 'forwarded','forwarded to upstream software authors');
35 #set timestamp for html files
36 $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
37 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
39 #check for commandline switches
40 while (@ARGV && $ARGV[0] =~ m/^-/)
41 { if ($ARGV[0] eq '-diff') { $diff=1; }
42 elsif ($ARGV[0] =~ m/^-lastrun\=([0-9.]+)$/) { $lastrun= $1; undef $stampfile; }
43 elsif ($ARGV[0] =~ m/^-full$/) { undef $lastrun; undef $stampfile; }
44 elsif ($ARGV[0] =~ m/^-stampfile\=(\S+)$/) { $stampfile= $1; }
45 else { &quit("bad usage"); }
49 #check for remaing argument, only one...
51 $wwwbase= shift(@ARGV);
54 defined($startdate= time) || &quit("failed to get time: $!");
58 #if stamp file was given,
59 if (defined($stampfile))
60 { if (open(X,"< $stampfile"))
63 printf "progress last run %.7f days\n",$lastrun;
64 } else { print "progress stamp file $stampfile: $! - full\n"; }
67 #only process file if greater than last run...
68 if (defined($lastrun) && -M "db-h" > $lastrun)
70 s/SUBSTITUTE_DTIME/$dtime/o;
71 s/\<\!\-\-updateupdate\-\-\>.*\<\!\-\-\/updateupdate\-\-\>/check/;
72 &file('ix/zstamp.html','non',$_."</body></html>\n");
74 # print "db2html: no changes since last run\n";
78 #parse maintainer file
79 open(MM,"$gMaintainerFile") || &quit("open $gMaintainerFile: $!");
81 { m/^(\S+)\s+(\S.*\S)\s*$/ || &quit("$gMaintainerFile: \`$_'");
88 #load all database files
89 opendir(D,'db-h') || &quit("opendir db-h: $!");
90 @dirs = sort { $a <=> $b } grep(s#^#db-h/#,grep(/^\d+$/,readdir(D)));
92 foreach my $dir (@dirs) {
94 push @files, sort { $a <=> $b } grep(/^-?\d+\.log$/,readdir(D));
98 for $pending (qw(pending done forwarded))
99 { for $severity (@showseverities)
100 { eval "\$index${pending}${severity}= \$iiindex${pending}${severity}= ''; 1;"
101 or &quit("reset \$index${pending}${severity}: $@");
106 { next unless $f =~ m/^(-?\d+)\.log$/;
108 #((print STDERR "$ref\n"),
111 # unless $ref =~ m/^-/ || $ref =~ m/^124/;
112 &filelock("lock/$ref");
113 $preserveonly= defined($lastrun) && -M "db-h/".get_hashname($ref)."/$ref.log" > $lastrun;
114 if ($ref =~ m/^-\d$/)
115 { $week= $ref eq '-1' ? 'this week' :
116 $ref eq '-2' ? 'last week' :
117 $ref eq '-3' ? 'two weeks ago' :
118 ($ref-1)." weeks ago";
119 $linkto= "ju/unmatched$ref";
120 $short= "junk, $week";
122 "This includes messages sent to <code>done\@$gEmailDomain</code>\n".
123 "which did not have a $gBug reference number in the Subject line\n".
124 "or which contained an\n".
125 "unknown or out of date $gBug report number (these cause a warning\n".
126 "to be sent to the sender) and details about the messages\n".
127 "sent to <code>request@$gEmailDomain</code> (all of which".
128 "produce replies).\n";
129 $indexlink= "Messages not matched to a specific $gBug report - $week";
130 $data->{subject}= '';
135 $tpackfile= "pnone.html";
136 $indexpart= 'unmatched';
140 $_= $data->{package}; y/A-Z/a-z/; $_= $` if m/[^-+._a-z0-9()]/;
142 if ($data->{severity} eq '' || $data->{severity} eq 'normal')
144 $addseverity= $gDefaultSeverity;
145 } elsif (grep($data->{severity} eq $_, @strongseverities))
146 { $showseverity= "<strong>Severity: $data->{severity}</strong>;\n";
147 $addseverity= $data->{severity};
149 { $showseverity= "Severity: <em>$data->{severity}</em>;\n";
150 $addseverity= $data->{severity};
152 $days= int(($startdate - $data->{date})/86400); close(S);
153 $indexlink= "#$ref: ".&sani($data->{subject});
155 $packfile= length($tpack) ? "pa/l$tpack.html" : "pa/none.html";
156 $indexentry .= "Package: <A href=\"../$packfile\"><strong>".
157 &sani($data->{package})."</strong></A>;\n"
158 if length($data->{package});
159 $indexentry .= $showseverity;
160 $indexentry .= "Reported by: ".&sani($data->{originator});
161 $indexentry .= ";\nKeywords: ".&sani($data->{keywords})
162 if length($data->{keywords});
163 $linkto= $ref; $linkto =~ s,^..,$&/$&,;
164 @merged= split(/ /,$data->{mergedwith});
166 { $mseparator= ";\nmerged with ";
168 { $mfile= $m; $mfile =~ s,^..,$&/$&,;
169 $indexentry .= $mseparator."<A href=\"../$mfile.html\">#$m</A>";
173 $daysold=$submitted='';
174 if (length($data->{done}))
175 { $indexentry .= ";\n<strong>Done:</strong> ".&sani($data->{done});
176 $indexpart= "done$addseverity";
177 } elsif (length($data->{forwarded}))
178 { $indexentry .= ";\n<strong>Forwarded</strong> to ".&sani($data->{forwarded});
179 $indexpart= "forwarded$addseverity";
181 { $cmonths= int($days/30);
182 if ($cmonths != $amonths)
183 { $msg= $cmonths == 0 ? "Submitted in the last month" :
184 $cmonths == 1 ? "Over one month old" :
185 $cmonths == 2 ? "Over two months old - attention is required" :
186 "OVER $cmonths MONTHS OLD - ATTENTION IS REQUIRED";
187 $shortindex .= "</pre><h2>$msg:</h2><pre>\n$shorthead\n";
190 $pad= 6-length(sprintf("%d",$f));
192 ($pad>0 ? ' 'x$pad : '').
193 sprintf("<A href=\"../%s.html\">%d</A>",$linkto,$ref).
194 &sani(sprintf(" %-1.1s %-10.10s %-35.35s %-.25s\n",
197 (length($data->{keywords}) ? $data->{keywords}.'/' : '').
198 $data->{subject}, $data->{originator}));
199 $shortindex.= $thissient;
200 $sient{"$ref $data->{package}"}= $thissient;
202 { $font= $days <= 30 ? '' :
205 $efont= length($font) ? "</$font>" : '';
206 $font= length($font) ? "<$font>" : '';
207 $daysold= "; $font$days days old$efont";
210 $submitted = 'THIS IS A BUG IN THE BUG PROCESSOR';
212 $submitted = strftime "%a, %e %b %Y %T %Z", localtime($data->{date});
214 $submitted= "; dated $submitted";
215 $indexpart= "pending$addseverity";
218 $short= $ref; $short =~ s/^\d+/#$&/;
219 $tmaint= defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
220 $qpackage= &sani($_);
221 $descriptivehead= $indexentry.$submitted.";\nMaintainer for $qpackage is\n".
222 '<A href="../ma/l'.&maintencoded($tmaint).'.html">'.&sani($tmaint).'</A>.';
223 $indexentry .= $daysold;
227 $indexadd .= "<!--iid $iiref-->" if defined($iiref);
228 $indexadd .= "<li><A href=\"../$linkto.html\">".$indexlink."</A>";
229 $indexadd .= "<br>\n".$indexentry if length($indexentry);
230 $indexadd .= "<!--/iid-->" if defined($iiref);
232 $estr= "\$index$indexpart = \$indexadd.\$index$indexpart; 1;";
233 eval($estr) || &quit("eval add to \$index$indexpart ($estr) failed: $@");
234 #print STDERR ">$estr|$indexadd<\n";
235 $indexadd= "<!--ii $iiref-->\n" if defined($iiref);
236 eval("\$iiindex$indexpart = \$indexadd.\$iiindex$indexpart; 1;") ||
237 &quit("eval add to \$iiindex$indexpart failed: $@");
238 if (defined($tmaint))
239 { $countpermaint{$tmaint} += length($data->{done}) ? 0 : length($data->{forwarded}) ? 0 : 1;
240 eval("\$permaint${indexpart}{\$tmaint} .= \$indexadd; 1;") ||
241 &quit("eval add to \$permaint${indexpart}{\$tmaint} failed: $@");
244 { $countperpack{$tpack} += length($data->{done}) ? 0 : length($data->{forwarded}) ? 0 : 1;
245 eval("\$perpack${indexpart}{\$tpack} .= \$indexadd; 1;") ||
246 &quit("eval add to \$perpack${indexpart}{\$tpack} failed: $@");
248 if ($preserveonly) { &preserve("$linkto.html"); &preserve("$linkto-b.html"); &unfilelock; next; }
249 my $hash = get_hashname($ref);
250 open(L,"db-h/$hash/$ref.log") || &quit("open db-h/$hash/$ref.log: $!");
252 $boring=''; $xmessage= 0;
253 $normstate= 'kill-init';
257 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
258 &quit("$ref ^G in state $normstate");
259 $normstate= 'incoming-recv';
261 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
262 &quit("$ref ^A in state $normstate");
263 $normstate= 'autocheck';
265 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
266 &quit("$ref ^B in state $normstate");
267 $normstate= 'recips';
269 $normstate eq 'go' || $normstate eq 'go-nox' || $normstate eq 'html' ||
270 &quit("$ref ^C in state $normstate");
271 $this .= "</pre>\n" if $normstate eq 'go' || $normstate eq 'go-nox';
272 if ($normstate eq 'html') {
274 $this .= " <em><A href=\"../$linkto-b.html#m$xmessage\">Full text</A>".
277 if ($suppressnext && $normstate ne 'html') {
278 $ntis= $this; $ntis =~ s:\<pre\>:</A><pre>:i;
279 $boring .= "<hr><A name=\"m$xmessage\">\n$ntis\n";
281 $log = $this. "<hr>\n". $log;
283 $suppressnext= $normstate eq 'html';
284 $normstate= 'kill-end';
286 $normstate eq 'kill-body' || &quit("^E in state $normstate");
290 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
291 &quit("$ref ^F in state $normstate");
292 $normstate= 'html'; $this= '';
293 } elsif ($normstate eq 'incoming-recv') {
294 $pl= $_; $pl =~ s/\n+$//;
295 m/^Received: \(at (\S+)\) by (\S+)\;/ ||
296 &quit("bad line \`$pl' in state incoming-recv");
297 $this = "<h2>Message received at ".&sani("$1\@$2").":</h2><br>\n".
301 } elsif ($normstate eq 'html') {
303 } 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($data->{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; }