work on output formatting
[pspp] / results2html
1 #! /usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use HTML::Entities;
7
8 open (LOG, '<', "LOG");
9 open (LOG_HTML, '>', "log.html");
10
11 print LOG_HTML <<EOF;
12 <html>
13 <head>
14   <link rel="stylesheet" href="build.css">
15 </head>
16 <body>
17 EOF
18 print LOG_HTML "<pre>";
19
20 sub read_vars {
21     my ($file) = @_;
22     my %vars = ();
23     if (open (VARS, "<", $file)) {
24         while (<VARS>) {
25             chomp;
26             my ($key, $value) = /^([^=]+)=(.*)/ or next;
27             $vars{$key} = $value;
28         }
29         close (VARS);
30     }
31     return %vars;
32 }
33 my (%vars) = read_vars ('VARS');
34
35 my (@products);
36 my (@steps);
37 my ($new_page) = 0;
38 my ($result) = "failure";
39 while (<LOG>) {
40     my $ln = $.;
41     chomp;
42
43     if (/^\f$/) {
44         $new_page = 1;
45         print LOG_HTML "</pre><hr><pre>\n";
46         next;
47     }
48
49     my $log_class;
50     if ($new_page) {
51         $new_page = 0;
52         $log_class = "step";
53         if (my ($name, $product) = /^Saving(?:([^:]*):)?\s+(.*)$/) {
54             my $href = "$product/index.html";
55             $href = $product if ! -e $href;
56
57             my (%p);
58             $p{NAME} = $name if defined ($name);
59             $p{PRODUCT} = $product;
60             $p{HREF} = $href;
61             $p{LN} = $ln;
62             push (@products, \%p);
63             push (@{$steps[$#steps]{CHILDREN}}, \%p);
64         } else {
65             my (%s);
66             $s{TITLE} = $_;
67             $s{LN} = $ln;
68             push (@steps, \%s);
69         }
70         $result = 'success' if $_ eq 'Success';
71     } else {
72         if (my ($diagnostic) = /(error|warning):/i) {
73             my (%d);
74             $d{DIAGNOSTIC} = lc ($diagnostic);
75             $d{MESSAGE} = $_;
76             $d{LN} = $ln;
77             push (@{$steps[$#steps]{CHILDREN}}, \%d);
78
79             $log_class = "$diagnostic";
80         }
81     }
82     printf LOG_HTML "<a name=\"%d\"><tt>%4d</tt></a>  ", $ln, $ln;
83     if (defined ($log_class)) {
84         print LOG_HTML "<span class=\"$log_class\">", encode_entities ($_), "</span>\n";
85     } else {
86         print LOG_HTML encode_entities ($_), "\n";
87     }
88 }
89
90 open (INDEX, '>','index.html');
91
92 print INDEX <<EOF;
93 <html>
94 <head>
95   <link rel="stylesheet" href="build.css">
96 </head>
97 <body>
98 EOF
99
100 print INDEX "<h1>Build ", $vars{"build_number"}, ": $result</h1>\n";
101
102 print INDEX "<h2>Build Properties</h2>\n";
103 print INDEX "<table>\n";
104 print INDEX "<tr><th>Name</th><th>Value</th></tr>\n";
105 foreach my $key (sort (keys (%vars))) {
106     print INDEX "<tr>";
107     print INDEX "<td>", encode_entities ($key), "</td>";
108     print INDEX "<td>", encode_entities ($vars{$key}), "</td>";
109     print INDEX "</tr>\n";
110 }
111 print INDEX "</table>\n";
112
113 print INDEX "<h2>Build Products</h2>\n";
114 print INDEX "<ul>\n";
115 foreach my $p (@products) {
116     print INDEX "<li>";
117     print INDEX encode_entities ($p->{NAME}), ": " if defined ($p->{NAME});
118     print INDEX "<a href=\"", encode_entities ($p->{HREF}), "\">";
119     print INDEX encode_entities ($p->{PRODUCT});
120     print INDEX "</a></li>\n";
121 }
122 print INDEX "</ul>\n";
123
124 sub log_link {
125     my ($ln) = @_;
126     return "<small><a href=\"log.html#$ln\">(log)</a></small>";
127 }
128
129 print INDEX "<h2>Build Summary</h2>\n";
130 print INDEX "<ol>\n";
131 foreach my $s (@steps) {
132     print INDEX "<li>", encode_entities ($s->{TITLE});
133     print INDEX " ", log_link ($s->{LN});
134     foreach my $c (@{$s->{CHILDREN}}) {
135         if (defined ($c->{DIAGNOSTIC})) {
136             print INDEX "<p class=\"$c->{DIAGNOSTIC}\">";
137             print INDEX "<a href=\"log.html#$c->{LN}\">";
138             print INDEX encode_entities ($c->{MESSAGE});
139             print INDEX "</a></p>\n";
140         } else {
141             print INDEX "<p>&rarr; <a href=\"", encode_entities ($c->{HREF}), "\">";
142             print INDEX encode_entities ($c->{PRODUCT});
143             print INDEX "</a> ";
144             print INDEX log_link ($c->{LN});
145             print INDEX "</p>\n";
146         }
147     }
148     print INDEX "</li>\n";
149 }
150 print INDEX "</ol>\n";
151
152 print INDEX <<EOF;
153 </body>
154 </html>
155 EOF
156
157 print LOG_HTML <<EOF;
158 </pre>
159 </body>
160 </html>
161 EOF
162
163 open (CSS, '>', "build.css");
164 print CSS <<EOF;
165 body {
166         background: white;
167         color: black;
168         padding: 0em 3em 0em 3em;
169         margin: 0
170 }
171 body>p {
172         margin: 0pt 0pt 0pt 0em
173 }
174 body>p + p {
175         text-indent: 1.5em;
176 }
177 H1 {
178         font-size: 150%;
179         margin-left: -1.33em
180 }
181 H2 {
182         font-size: 125%;
183         font-weight: bold;
184         margin-left: -.8em
185 }
186 H3 {
187         font-size: 100%;
188         font-weight: bold;
189         margin-left: -.5em }
190 H4 {
191         font-size: 100%;
192         margin-left: 0em
193 }
194 H1, H2, H3, H4, H5, H6 {
195         font-family: sans-serif;
196         color: blue
197 }
198 html {
199         margin: 0
200 }
201
202 a:link {
203         color: blue;
204         text-decoration: none;
205 }
206 a:visited {
207         color: gray;
208         text-decoration: none;
209 }
210 a:active {
211         color: black;
212         text-decoration: none;
213 }
214 a:hover {
215         text-decoration: underline
216 }
217
218 ol>li>p {
219         margin-top: 0;
220         margin-bottom: 0
221 }
222 .step {
223         font-weight: bold
224 }
225 .warning {
226         background: yellow
227 }
228 .error {
229         background: orange
230 }
231 EOF