2 # $Id: db2html.in,v 1.18 2003/05/25 14:43:30 joy 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 = $gHTMLExpireNote;
26 $shorthead = ' Ref * Package Keywords/Subject Submitter';
30 %displayshowpendings = ('pending','outstanding',
32 'forwarded','forwarded to upstream software authors');
34 #set timestamp for html files
35 $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
36 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
38 #check for commandline switches
39 while (@ARGV && $ARGV[0] =~ m/^-/)
40 { if ($ARGV[0] eq '-diff') { $diff=1; }
41 elsif ($ARGV[0] =~ m/^-lastrun\=([0-9.]+)$/) { $lastrun= $1; undef $stampfile; }
42 elsif ($ARGV[0] =~ m/^-full$/) { undef $lastrun; undef $stampfile; }
43 elsif ($ARGV[0] =~ m/^-stampfile\=(\S+)$/) { $stampfile= $1; }
44 else { &quit("bad usage"); }
48 #check for remaing argument, only one...
50 $wwwbase= shift(@ARGV);
53 defined($startdate= time) || &quit("failed to get time: $!");
57 #if stamp file was given,
58 if (defined($stampfile))
59 { if (open(X,"< $stampfile"))
62 printf "progress last run %.7f days\n",$lastrun;
63 } else { print "progress stamp file $stampfile: $! - full\n"; }
66 #only process file if greater than last run...
67 if (defined($lastrun) && -M "db-h" > $lastrun)
69 s/SUBSTITUTE_DTIME/$dtime/o;
70 s/\<\!\-\-updateupdate\-\-\>.*\<\!\-\-\/updateupdate\-\-\>/check/;
71 &file('ix/zstamp.html','non',$_."</body></html>\n");
73 # print "db2html: no changes since last run\n";
77 #parse maintainer file
78 open(MM,"$gMaintainerFile") || &quit("open $gMaintainerFile: $!");
80 { m/^(\S+)\s+(\S.*\S)\s*$/ || &quit("$gMaintainerFile: \`$_'");
87 #load all database files
88 opendir(D,'db-h') || &quit("opendir db-h: $!");
89 @dirs = sort { $a <=> $b } grep(s#^#db-h/#,grep(/^\d+$/,readdir(D)));
91 foreach my $dir (@dirs) {
93 push @files, sort { $a <=> $b } grep(/^-?\d+\.log$/,readdir(D));
97 for $pending (qw(pending done forwarded))
98 { for $severity (@showseverities)
99 { eval "\$index${pending}${severity}= \$iiindex${pending}${severity}= ''; 1;"
100 or &quit("reset \$index${pending}${severity}: $@");
105 { next unless $f =~ m/^(-?\d+)\.log$/;
107 #((print STDERR "$ref\n"),
110 # unless $ref =~ m/^-/ || $ref =~ m/^124/;
111 &filelock("lock/$ref");
112 $preserveonly= defined($lastrun) && -M "db-h/".get_hashname($ref)."/$ref.log" > $lastrun;
113 if ($ref =~ m/^-\d$/)
114 { $week= $ref eq '-1' ? 'this week' :
115 $ref eq '-2' ? 'last week' :
116 $ref eq '-3' ? 'two weeks ago' :
117 ($ref-1)." weeks ago";
118 $linkto= "ju/unmatched$ref";
119 $short= "junk, $week";
121 "This includes messages sent to <code>done\@$gEmailDomain</code>\n".
122 "which did not have a $gBug reference number in the Subject line\n".
123 "or which contained an\n".
124 "unknown or out of date $gBug report number (these cause a warning\n".
125 "to be sent to the sender) and details about the messages\n".
126 "sent to <code>request@$gEmailDomain</code> (all of which".
127 "produce replies).\n";
128 $indexlink= "Messages not matched to a specific $gBug report - $week";
129 $data->{subject}= '';
134 $tpackfile= "pnone.html";
135 $indexpart= 'unmatched';
139 $_= $data->{package}; y/A-Z/a-z/; $_= $` if m/[^-+._a-z0-9()]/;
141 if ($data->{severity} eq '' || $data->{severity} eq 'normal')
143 $addseverity= $gDefaultSeverity;
144 } elsif (grep($data->{severity} eq $_, @strongseverities))
145 { $showseverity= "<strong>Severity: $data->{severity}</strong>;\n";
146 $addseverity= $data->{severity};
148 { $showseverity= "Severity: <em>$data->{severity}</em>;\n";
149 $addseverity= $data->{severity};
151 $days= int(($startdate - $data->{date})/86400); close(S);
152 $indexlink= "#$ref: ".&sani($data->{subject});
154 $packfile= length($tpack) ? "pa/l$tpack.html" : "pa/none.html";
155 $indexentry .= "Package: <A href=\"../$packfile\"><strong>".
156 &sani($data->{package})."</strong></A>;\n"
157 if length($data->{package});
158 $indexentry .= $showseverity;
159 $indexentry .= "Reported by: ".&sani($data->{originator});
160 $indexentry .= ";\nKeywords: ".&sani($data->{keywords})
161 if length($data->{keywords});
162 $linkto= $ref; $linkto =~ s,^..,$&/$&,;
163 @merged= split(/ /,$data->{mergedwith});
165 { $mseparator= ";\nmerged with ";
167 { $mfile= $m; $mfile =~ s,^..,$&/$&,;
168 $indexentry .= $mseparator."<A href=\"../$mfile.html\">#$m</A>";
172 $daysold=$submitted='';
173 if (length($data->{done}))
174 { $indexentry .= ";\n<strong>Done:</strong> ".&sani($data->{done});
175 $indexpart= "done$addseverity";
176 } elsif (length($data->{forwarded}))
177 { $indexentry .= ";\n<strong>Forwarded</strong> to ".&sani($data->{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($data->{keywords}) ? $data->{keywords}.'/' : '').
197 $data->{subject}, $data->{originator}));
198 $shortindex.= $thissient;
199 $sient{"$ref $data->{package}"}= $thissient;
201 { $font= $days <= 30 ? '' :
204 $efont= length($font) ? "</$font>" : '';
205 $font= length($font) ? "<$font>" : '';
206 $daysold= "; $font$days days old$efont";
209 $submitted = 'THIS IS A BUG IN THE BUG PROCESSOR';
211 $submitted = strftime "%a, %e %b %Y %T %Z", localtime($data->{date});
213 $submitted= "; dated $submitted";
214 $indexpart= "pending$addseverity";
217 $short= $ref; $short =~ s/^\d+/#$&/;
218 $tmaint= defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
219 $qpackage= &sani($_);
220 $descriptivehead= $indexentry.$submitted.";\nMaintainer for $qpackage is\n".
221 '<A href="../ma/l'.&maintencoded($tmaint).'.html">'.&sani($tmaint).'</A>.';
222 $indexentry .= $daysold;
226 $indexadd .= "<!--iid $iiref-->" if defined($iiref);
227 $indexadd .= "<li><A href=\"../$linkto.html\">".$indexlink."</A>";
228 $indexadd .= "<br>\n".$indexentry if length($indexentry);
229 $indexadd .= "<!--/iid-->" if defined($iiref);
231 $estr= "\$index$indexpart = \$indexadd.\$index$indexpart; 1;";
232 eval($estr) || &quit("eval add to \$index$indexpart ($estr) failed: $@");
233 #print STDERR ">$estr|$indexadd<\n";
234 $indexadd= "<!--ii $iiref-->\n" if defined($iiref);
235 eval("\$iiindex$indexpart = \$indexadd.\$iiindex$indexpart; 1;") ||
236 &quit("eval add to \$iiindex$indexpart failed: $@");
237 if (defined($tmaint))
238 { $countpermaint{$tmaint} += length($data->{done}) ? 0 : length($data->{forwarded}) ? 0 : 1;
239 eval("\$permaint${indexpart}{\$tmaint} .= \$indexadd; 1;") ||
240 &quit("eval add to \$permaint${indexpart}{\$tmaint} failed: $@");
243 { $countperpack{$tpack} += length($data->{done}) ? 0 : length($data->{forwarded}) ? 0 : 1;
244 eval("\$perpack${indexpart}{\$tpack} .= \$indexadd; 1;") ||
245 &quit("eval add to \$perpack${indexpart}{\$tpack} failed: $@");
247 if ($preserveonly) { &preserve("$linkto.html"); &preserve("$linkto-b.html"); &unfilelock; next; }
248 my $hash = get_hashname($ref);
249 open(L,"db-h/$hash/$ref.log") || &quit("open db-h/$hash/$ref.log: $!");
251 $boring=''; $xmessage= 0;
252 $normstate= 'kill-init';
256 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
257 &quit("$ref ^G in state $normstate");
258 $normstate= 'incoming-recv';
260 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
261 &quit("$ref ^A in state $normstate");
262 $normstate= 'autocheck';
264 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
265 &quit("$ref ^B in state $normstate");
266 $normstate= 'recips';
268 $normstate eq 'go' || $normstate eq 'go-nox' || $normstate eq 'html' ||
269 &quit("$ref ^C in state $normstate");
270 $this .= "</pre>\n" if $normstate eq 'go' || $normstate eq 'go-nox';
271 if ($normstate eq 'html') {
273 $this .= " <em><A href=\"../$linkto-b.html#m$xmessage\">Full text</A>".
276 if ($suppressnext && $normstate ne 'html') {
277 $ntis= $this; $ntis =~ s:\<pre\>:</A><pre>:i;
278 $boring .= "<hr><A name=\"m$xmessage\">\n$ntis\n";
280 $log = $this. "<hr>\n". $log;
282 $suppressnext= $normstate eq 'html';
283 $normstate= 'kill-end';
285 $normstate eq 'kill-body' || &quit("^E in state $normstate");
289 $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
290 &quit("$ref ^F in state $normstate");
291 $normstate= 'html'; $this= '';
292 } elsif ($normstate eq 'incoming-recv') {
293 $pl= $_; $pl =~ s/\n+$//;
294 m/^Received: \(at (\S+)\) by (\S+)\;/ ||
295 &quit("bad line \`$pl' in state incoming-recv");
296 $this = "<h2>Message received at ".&sani("$1\@$2").":</h2><br>\n".
300 } elsif ($normstate eq 'html') {
302 } elsif ($normstate eq 'go') {
305 } elsif ($normstate eq 'go-nox') {
308 } elsif ($normstate eq 'recips') {
310 $this = "<h2>Message sent:</h2><br>\n";
313 $this = "<h2>Message sent to ".&sani($_).":</h2><br>\n";
315 $normstate= 'kill-body';
316 } elsif ($normstate eq 'autocheck') {
317 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
318 $normstate= 'autowait';
319 $this = "<h2>Message received at $2:</h2><br>\n";
320 } elsif ($normstate eq 'autowait') {
322 $normstate= 'go-nox';
325 &quit("$ref state $normstate line \`$_'");
328 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
330 if (length($boring)) {
331 &file("$linkto-b.html",'non',
332 "<html><head><title>$gProject $gBug report logs - ".
333 "$short, boring messages</title>\n".
334 "<link rev=\"made\" href=\"mailto:$gMaintainerEmail)\">\n".
335 "</head>$gHTMLStart<h1>$gProject $gBugreport logs -".
336 "\n <A href=\"../$linkto.html\">$short</A>,".
337 " boring messages</h1>\n$boring\n<hr>\n".
338 $tail_html."</body></html>\n");
340 &file("$linkto.html",'non',
341 "<html><head><title>$gProject $gBug report logs - ".
343 "<link rev=\"made\" href=\"mailto:$gMaintainerEmail\">\n".
344 "</head>$gHTMLStart<h1>$gProject $gBug report logs - $short<br>\n".
345 &sani($data->{subject})."</h1>".
346 "$descriptivehead\n".
349 $tail_html."</body></html>\n");
355 s/([^<>()]+) \(([^()<>]+)\)/$2 \<$1\>/;
359 $email= s/ *\<[^<>()]+\>$//g ? $& : '';
360 $_= "$1 $_" if s/ (\S+)$//;
366 return $maintencoded{$_[0]} if defined($maintencoded{$_[0]});
368 local ($todo,$encoded)= ($input);
369 while ($todo =~ m/\W/) {
370 $encoded.=$`.sprintf("-%02x_",unpack("C",$&));
374 $encoded =~ s/-2e_/\./g;
375 $encoded =~ s/^([^,]+)-20_-3c_(.*)-40_(.*)-3e_/$1,$2,$3,/;
376 $encoded =~ s/^(.*)-40_(.*)-20_-28_([^,]+)-29_$/,$1,$2,$3/;
377 $encoded =~ s/-20_/_/g;
378 $encoded =~ s/-([^_]+)_-/-$1/g;
379 $maintencoded{$input}= $encoded;
382 for $tmaint (keys %countpermaint) {
384 $after=$before=$sort2d=$sort2s=$sort1d=$sort1s='';
385 $after= "$&$after" if s/\s*\<[^<>()]+\>\s*$//;
386 $after= "$&$after" if s/\s*\)\s*$//;
387 $after= "$&$after" if s/\s*,.*$//;
388 $before.= $& if s/^.*\(\s*//;
389 $sort2d= $& if s/\S+$//;
391 while (s/^([^()<>]+)\. */$1 /) { };
392 s/\s+$//; y/A-Za-z/a-zA-Z/; $sort1s= $_;
393 $sort2s= $sort2d; $sort2s =~ y/A-Za-z/a-zA-Z/;
394 $maintsort{$tmaint}= $sort2s.' '.$sort1s.' '.$before.$sort1d.$sort2d.$after;
395 $maintdisplay{$tmaint}=
396 &sani($before).'<strong>'.&sani($sort1d.$sort2d).'</strong>'.&sani($after);
401 return $displayshowseverities{$sv}.' - '.$displayshowpendings{$pt};
404 sub makeindex ($$$) {
405 my ($varprefix,$varsuffix,$tkey) = @_;
406 my ($pending,$severity,$anydone,$text);
409 for $pending (qw(pending forwarded done)) {
410 for $severity (@showseverities) {
411 $estr= "\$value= \\${varprefix}${pending}${severity}${varsuffix}; 1;";
414 or &quit("eval get \$${varprefix}${pending}${severity} failed: $@");
415 #print STDERR ">$$value<\n";
416 next unless length($$value);
417 $text.= "<hr>\n<h2>".&heading($pending,$severity).":</h2>\n".
418 "(List of <A href=\"../si/$pending$severity.html\">all".
419 " such $gBugs</A> is available.)\n<ul>\n".
422 $anydone=1 if $pending eq 'done';
425 $text.= $expirynote_html if $anydone;
429 &file("ix/full.html",'def',
431 makeindex('$index',"",'').
433 $tail_html."</body><html>\n");
435 &file("ju/junk.html",'non',
437 "<hr>\n<h2>Junk (messages without a specific $gBug report number):</h2>\n".
438 "(\`this week' is everything since last Wednesday.)\n<ul>\n".
441 $tail_html."</body><html>\n");
443 $nobugs_html= "No reports are currently in this state.";
444 $who_html= $gProject;
445 $owner_addr= $gMaintainerEmail;
446 $otherindex_html= "For other kinds of index or for other information about
447 $gProject and the $gBug system, see the <A HREF=\"../../\">$gBug system top-level
448 contents WWW page</A>.
452 for $pending (qw(pending forwarded done)) {
453 for $severity (@showseverities) {
454 eval "\$value= \\\$iiindex${pending}${severity}; 1;"
455 or &quit("eval get \$iiindex${pendingtype}${severity} failed: $@");
456 $value= \$nobugs_html if !length($$value);
457 $headstring= &heading($pending,$severity);
458 &file("si/$pending$severity.html",'ref',
459 "<html><head><title>$who_html $gBug reports: $headstring</title>\n".
460 "<link rev=\"made\" href=\"mailto:".&sani($owner_addr)."\">\n".
461 "</head>$gHTMLStart<h1>$who_html $gBug reports: $headstring</h1>\n".
463 ($pending eq 'done' ? "<P>\n$expirynote_html" : '').
467 $tail_html."</body></html>\n");
471 sub individualindexes ($\@&\%&&$$$$$&&) {
472 my ($filename,$keysref,$getfilenameref,$countref,$getdisplayref,
473 $getsimpledisplayref,$what,$caveat,$whatplural,$abbrev,$ihead,
474 $getxinforef,$getxindexref) = @_;
475 my ($itext,$i,$tkey,$sani,$count,$tfilename,$refto,$backnext,$xitext,$bugbugs);
477 for ($i=0; $i<=$#$keysref; $i++) {
478 $tkey= $$keysref[$i];
479 $tfilename= &$getfilenameref($tkey);
480 $sani= &$getsimpledisplayref($tkey);
481 $count= $$countref{$tkey};
482 $count= $count >= 1 ? "$count" : "no";
483 $bugbugs= $count == 1 ? "$gBug" : "$gBugs";
484 $xitext= &$getxindexref($tkey);
485 $xitext= length($xitext) ? "$count $bugbugs; $xitext"
486 : "$count outstanding $bugbugs";
487 $itext .= "<li><A href=\"../$tfilename\">".&$getdisplayref($tkey)."</A>"."\n".
491 $refto= $$keysref[$i-1];
492 $xitext= &$getxindexref($refto);
493 $xitext= " ($xitext)" if length($xitext);
494 $backnext .= "<br>\nPrevious $what in list, <A href=\"../".
495 &$getfilenameref($refto)."\">".&$getdisplayref($refto)."</A>".
499 $refto= $$keysref[$i+1];
500 $xitext= &$getxindexref($refto);
501 $xitext= " ($xitext)" if length($xitext);
502 $backnext .= "<br>\nNext $what in list, <A href=\"../".
503 &$getfilenameref($refto)."\">".&$getdisplayref($refto)."</A>".
506 &file($tfilename,'ref',
507 "<html><head><title>$gProject $gBug reports: $what $sani</title>\n".
508 "<link rev=\"made\" href=\"mailto:$gMaintainerEmail\">\n".
509 "</head>$gHTMLStart<h1>$gProject $gBug reports: $what $sani</h1>\n".
510 &$getxinforef($tkey).
512 "See the <A href=\"../$filename\">listing of $whatplural</A>.\n".
514 &makeindex("\$per${abbrev}","{\$tkey}",$tkey).
516 $tail_html."</body></html>\n");
518 &file($filename,'non',
523 $tail_html."</body></html>\n");
526 @maintainers= sort { $maintsort{$a} cmp $maintsort{$b}; } keys %countpermaint;
527 individualindexes('ix/maintainers.html',
529 sub { 'ma/l'.&maintencoded($_[0]).'.html'; },
531 sub { $maintdisplay{$_[0]}; },
532 sub { &sani($_[0]); },
534 "Note that there may be other reports filed under different
535 variations on the maintainer\'s name and email address.<P>",
542 @packages= sort keys %countperpack;
543 individualindexes('ix/packages.html',
545 sub { length($_[0]) ? "pa/l$_[0].html" : 'pa/none.html'; },
547 sub { length($_[0]) ? $_[0] : 'not specified'; },
548 sub { &sani(length($_[0]) ? $_[0] : 'not specified'); },
550 "Note that with multi-binary packages there may be other
551 reports filed under the different binary package names.<P>",
556 return unless defined($maintainer{$_[0]});
557 $tmaint= $maintainer{$_[0]};
558 return "Maintainer for $_[0] is <A href=\"../ma/l".
559 &maintencoded($tmaint).
560 ".html\">".&sani($tmaint)."</A>.\n<p>\n";
563 return unless defined($maintainer{$_[0]});
564 $tmaint= $maintainer{$_[0]};
565 return "<A href=\"../ma/l".
566 &maintencoded($tmaint).
567 ".html\">".&sani($tmaint)."</A>";
570 &file('ix/summary.html','non',
575 $tail_html."</body></html>\n");
578 for $k (map {$_->[0] }
579 sort { $a->[2] cmp $b->[2] || $a->[1] <=> $b->[1] }
580 map { [$_, split(' ',$_,2)] } keys %sient)
581 { $bypackageindex.= $sient{$k}; }
582 &file('ix/psummary.html','non',
584 "<hr><pre>\n$shorthead\n".
587 $tail_html."</body></html>\n");
589 open(P,"$gPseudoDescFile") ||
590 &quit("$gPseudoDescFile: $!");
591 $ppd=''; while(<P>) { s/\s*\n$//; $ppd.= &sani($_)."\n"; } close(P);
592 &file('ix/pseudopackages.html','non',
596 $tail_html."</body></html>\n");
598 $_= $gHTMLStamp; s/SUBSTITUTE_DTIME/$dtime/o;
600 &file('ix/zstamp.html','non',$_."</body></html>\n");
602 sub notimestamp ($) {
604 s/\<\!\-\-timestamp\-\-\>\n.*\n\<\!\-\-\/timestamp\-\-\>\n//;
609 local ($name,$ii,$file)= @_;
611 $cmppath= "$wwwbase/$name".($ii eq 'ref' ? '.ref' : '');
612 if (open(ORIG,"$cmppath")) {
613 undef $/; $orig= <ORIG>; $/= "\n";
615 if (¬imestamp($orig) eq ¬imestamp($file)) {
616 print "preserve $name\n";
619 defined($c= open(P,"-|")) or &quit("pipe/fork for diff: $!");
621 open(Q,"|diff -e $cmppath -") or die "pipe/fork II for diff: $!\n";
622 print Q $file or die "write orig to diff: $!\n";
623 close(Q); $?==0 || $?==256 or die "diff gave $?\n";
626 undef $/; $difftxt= <P>; $/= "\n";
627 close(P); $?==0 || $?==256 or die "diff fork gave $?\n";
629 print "preserve $name\n";
632 $v= (split(/\n/,$difftxt));
633 print "diff $v $ii $name\n${difftxt}thatdiff $name\n"
634 or &quit("stdout (diff): $!");
638 $v= (split(/\n/,$file));
639 print "file $v $ii $name\n${file}thatfile $name\n" or &quit("stdout: $!");
643 print "preserve $_[0]\n";
648 while ($u= $cleanups[$#cleanups]) { &$u; }