/[cricket]/generate-overview.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /generate-overview.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dpavlin, Fri Jun 28 09:28:36 2002 UTC revision 1.14 by dpavlin, Sat May 31 13:52:51 2003 UTC
# Line 34  BEGIN { Line 34  BEGIN {
34          # You need to update this to point to the URL          # You need to update this to point to the URL
35          # you use to access Cricket.          # you use to access Cricket.
36  #       $gBaseURL = "http://localhost/~cricket/grapher.cgi";  #       $gBaseURL = "http://localhost/~cricket/grapher.cgi";
37          $gBaseURL = "http://romul.pliva.hr/cgi-bin/cricket/grapher.cgi";          my $hostname = `hostname -f`;
38            chomp($hostname);
39            $gBaseURL = "http://$hostname/cgi-bin/cricket/grapher.cgi";
40    
41          # change this to destination directory          # change this to destination directory
42          $path = "/home/dpavlin/public_html";          $path = "/data/mon/";
         # this is basename of all html files  
         $name = "overview";  
43  }  }
44    
45  #use lib "$gInstallRoot/../lib";  #use lib "$gInstallRoot/../lib";
# Line 57  use Common::Map; Line 57  use Common::Map;
57  use Common::Options;  use Common::Options;
58  use Common::Log;  use Common::Log;
59    
60    #
61    # Set this option to 0 if you don't want JavaScript roll-up/roll-down
62    # of images to be created
63    #
64    my $dynamic_js = 1;
65    
66  Common::Options::commonOptions( 'baseURL=s' => \$gBaseURL );  Common::Options::commonOptions( 'baseURL=s' => \$gBaseURL );
67  initConst();  initConst();
68    
# Line 87  foreach $subtree (@ARGV) { Line 93  foreach $subtree (@ARGV) {
93      }      }
94  }  }
95    
96  foreach my $filename (keys %html) {  my %html_file;
97    
98    foreach my $item (sort keys %html) {
99            my ($range,$target) = split(/\t/,$item,2);
100            my (undef,$service,$arg) = split(/\//,$target,3);
101    
102            $html_file{"$range/$service"} .= $html{$item};
103            $html_file{"overview-$range"} .= $html{$item};
104    }
105    
106    foreach my $key (keys %html_file) {
107    
108            my $filename = "$path/$key.html";
109            my($dir) = dirname($filename);
110            if (! -d $dir) {
111               Info("Making directory $dir to hold file $filename.");
112               Common::Util::MkDir($dir);
113            }
114            Info("Dumping HTML for $key to $filename.");
115          open(OUT,"> $filename") || die "can't open output html '$filename': $!";          open(OUT,"> $filename") || die "can't open output html '$filename': $!";
116          print OUT $html{$filename},"</body></html>";          print OUT "<html><head><title>$key</title>";
117            print OUT '<meta content="no-cache" http-equiv="Pragma">
118                    <meta content="300" http-equiv="Refresh">' if ($filename =~ m/Daily/i);
119            print OUT '</head><body>';
120            my $html=<<'HTMLEND';
121    
122    <script language="JavaScript">
123    var Selected = "";
124    
125    function Switch(elm)
126    {
127            var cookie = Get_Cookie("##cookie_name##");
128    
129            var elmref;
130    
131            // uncomment following lines for just 1 selected content
132    /*
133            if (Selected != "")
134            {
135                    elmref = eval("document.getElementById('" + Selected + "_h1')");
136                    if (elmref) elmref.style.display = 'none';
137                    elmref = eval("document.getElementById('" + Selected + "_h0')");
138                    // roll-up color
139                    if (elmref) elmref.bgColor = '#e0e0e0';
140            }
141            if (Selected != elm.name)
142            {
143                    Selected = elm.name;
144                    elmref = eval("document.getElementById('" + Selected + "_h1')");
145                    if (elmref)
146                    {
147                            if (elmref.style.display=='none') elmref.style.display='';
148                            else elmref.style.display = 'none';
149                    }
150                    elmref = eval("document.getElementById('" + Selected + "_h0')");
151                    // roll-down color
152                    if (elmref) elmref.bgColor = '#ffffff';
153            }
154            else
155                    Selected="";
156    */
157    
158            // or use this to unroll more than one line
159            Selected = elm.name;
160            elmref = eval("document.getElementById('" + Selected + "_h1')");
161            elmref0 = eval("document.getElementById('" + Selected + "_h0')");
162            if (elmref)
163            {
164                    if (elmref.style.display=='none') {
165                            elmref.style.display='';
166                            if (elmref0) elmref0.bgColor = '#eeeeee';
167                    } else {
168                            elmref.style.display = 'none';
169                            if (elmref0) elmref0.bgColor = '#e0e0e0';
170                    }
171                    cookie ^= 1 << Selected;
172            }
173    
174            Set_Cookie("##cookie_name##",cookie);
175            return false;
176    }
177    
178    function SwitchThis()
179    {
180            return Switch(this);
181    }
182    
183    
184    </script>
185    
186    <table border=0 id=DynamicTable bgColor='#e0e0e0' cellpadding=2 cellspacing=1>
187    
188    HTMLEND
189            if ($dynamic_js) {
190                    my $cookie_name = $key;
191                    $cookie_name =~ s/[^a-zA-Z0-9]//g;
192                    $html =~ s/##cookie_name##/$cookie_name/g;
193                    print OUT $html;
194            }
195    
196            print OUT $html_file{$key};
197            $html = <<'HTMLEND';
198    </table>
199    
200    <script language=javascript>
201    
202    function Get_Cookie(name) {
203        var start = document.cookie.indexOf(name+"=");
204        var len = start+name.length+1;
205        if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
206        if (start == -1) return null;
207        var end = document.cookie.indexOf(";",len);
208        if (end == -1) end = document.cookie.length;
209        return unescape(document.cookie.substring(len,end));
210    }
211    
212    function Set_Cookie(name,value,expires,path,domain,secure) {
213        document.cookie = name + "=" +escape(value) +
214            ( (expires) ? ";expires=" + expires.toGMTString() : "") +
215            ( (path) ? ";path=" + path : "") +
216            ( (domain) ? ";domain=" + domain : "") +
217            ( (secure) ? ";secure" : "");
218    }
219    
220    function Delete_Cookie(name,path,domain) {
221        if (Get_Cookie(name)) document.cookie = name + "=" +
222           ( (path) ? ";path=" + path : "") +
223           ( (domain) ? ";domain=" + domain : "") +
224           ";expires=Thu, 01-Jan-70 00:00:01 GMT";
225    }
226    
227    var table = document.getElementById("DynamicTable");
228    var links = table.getElementsByTagName("a");
229    var cookie = Get_Cookie("##cookie_name##");
230    var new_cookie = 0;
231    for (var i = 0; i < links.length; i++) {
232        if (links[i].id == "DynMessLink") {
233            links[i].onclick = SwitchThis;
234            elmref = eval("document.getElementById('" + links[i].name + "_h1')");
235            elmref0 = eval("document.getElementById('" + links[i].name + "_h0')");
236            if (elmref && cookie) {
237                    if (cookie & 1 << links[i].name) {
238                            elmref.style.display='';
239                            if (elmref0) elmref0.bgColor = '#eeeeee';
240                    } else {
241                            elmref.style.display = 'none';
242                            if (elmref0) elmref0.bgColor = '#e0e0e0';
243                    }
244            } else if(elmref) {
245                    // default: show all
246                    new_cookie |= 1 << links[i].name;
247                    if (elmref.style.display=='none') {
248                            elmref.style.display='';
249                            if (elmref0) elmref0.bgColor = '#eeeeee';
250                    } else {
251                            // hide? no...
252                            //elmref.style.display = 'none';
253                            //if (elmref0) elmref0.bgColor = '#e0e0e0';
254                            if (elmref0) elmref0.bgColor = '#eeeeee';
255                    }
256            }
257        }
258    }
259    if (new_cookie) Set_Cookie("##cookie_name##",new_cookie);
260    </script>
261    HTMLEND
262    
263            if ($dynamic_js) {
264                    my $cookie_name = $key;
265                    $cookie_name =~ s/[^a-zA-Z0-9]//g;
266                    $html =~ s/##cookie_name##/$cookie_name/g;
267                    print OUT $html;
268            }
269    
270            print OUT "</body></html>";
271          close(OUT);          close(OUT);
272    
273  }  }
274    
275  exit;  exit;
276    
277    sub do_html {
278            my ($desc,$url,$img) = @_;
279            if ($dynamic_js) {
280                    my $html =<<'HTMLEND';
281    <tr bgcolor='#e0e0e0' id=##id##_h0>
282    <td><a name="##id##"><a href="###id##" id=DynMessLink name=##id## >##desc##</a></td>
283    </tr>
284    <tr id=##id##_h1 style='' bgcolor='#ffffff' >
285    <td><a href="##url##"><img src="##img##"</td>
286    </tr>
287    HTMLEND
288                    $html =~ s/##desc##/$desc/;
289                    $html =~ s/##url##/$url/;
290                    $html =~ s/##img##/$img/;
291                    $html =~ s/##id##/$dynamic_js/g;
292                    $dynamic_js++;                  # increment usage counter
293                    return $html;
294            } else {
295                    return "$desc<br><a href=\"$url\"><img src=\"$img\"></a><br>\n";
296            }
297    }
298    
299  sub localHandleTargetInstance {  sub localHandleTargetInstance {
300          my($Name, $target) = @_;          my($Name, $target) = @_;
301    
# Line 145  sub localHandleTargetInstance { Line 346  sub localHandleTargetInstance {
346    
347                                  my($dslist);                                  my($dslist);
348    
                                 my($filename)="$path/$name-$rangeLabel.html";  
                                 if (! defined $html{$filename}) {  
                                         $html{$filename}="<html><head><title>$rangeLabel</title></head><body>";  
                                 }  
                                 my($dir) = dirname($filename);  
                                 if (! -d $dir) {  
                                    Info("Making directory $dir to hold file $filename.");  
                                    Common::Util::MkDir($dir);  
                                 }  
   
349                                  if (defined($ttRef->{'view'}))                                  if (defined($ttRef->{'view'}))
350                                  {                                  {
351                                          my($v);                                          my($v);
# Line 169  sub localHandleTargetInstance { Line 360  sub localHandleTargetInstance {
360    
361                                                  $URL = "$gBaseURL?type=png&target=$paramtarget";                                                  $URL = "$gBaseURL?type=png&target=$paramtarget";
362                                                  $URL .= "&dslist=$dslist&range=$paramrange";                                                  $URL .= "&dslist=$dslist&range=$paramrange";
363                                                  my $desc = "view: ";                                                      my $desc = "$paramtarget $vname";
364                                                    $desc .= " <b>".$target->{'short-desc'}."</b>" if (defined $target->{'short-desc'});
365                                                  if ($paraminst ne "") {                                                  if ($paraminst ne "") {
366                                                          $URL .= "&inst=$paraminst";                                                          $URL .= "&inst=$paraminst";
                                                         $desc.="$paraminst $paramtarget $vname";  
                                                 } else {  
                                                         $desc.="$paramtarget $vname";  
367                                                  }                                                  }
368    
369                                                  Info("Retrieving graph for $desc");                                                  Info("Retrieving graph for $desc");
370  #                                               getURL($URL,"$path/$name-$vname-$rangeLabel.png");  #                                               getURL($URL,"$path/$name-$vname-$rangeLabel.png");
371                                                  $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y&view=$vname";                                                  $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y&view=$vname";
372                                                  $html{$filename}.="$desc<br><a href=\"$tmp_URL\"><img src=$URL></a><br>";                                                  $html{"$rangeLabel\t$paramtarget"}.=do_html($desc,$tmp_URL,$URL);
373                                          }                                          }
374                                  } else {                                  } else {
375                                          $dslist = $ttRef->{'ds'};                                          $dslist = $ttRef->{'ds'};
# Line 189  sub localHandleTargetInstance { Line 378  sub localHandleTargetInstance {
378    
379                                          $URL = "$gBaseURL?type=png&target=$paramtarget";                                          $URL = "$gBaseURL?type=png&target=$paramtarget";
380                                          $URL .= "&dslist=$dslist&range=$paramrange";                                          $URL .= "&dslist=$dslist&range=$paramrange";
381                                          my $desc = "ds: ";                                                my $desc ="$paraminst $rangeLabel";
382                                            $desc .= " <b>".$target->{'short-desc'}."</b>" if (defined $target->{'short-desc'});
383                                          if ($paraminst ne "") {                                          if ($paraminst ne "") {
384                                                  $URL .= "&inst=$paraminst";                                                  $URL .= "&inst=$paraminst";
                                                 $desc.="$paraminst $rangeLabel"  
                                         } else {  
                                                 $desc.="$paramtarget $rangeLabel";  
385                                          }                                          }
386    
387                                          Info("Retrieving graph for $desc");                                          Info("Retrieving graph for $desc");
388    
389  #                                       getURL($URL,"$path/$name-$rangeLabel.png");  #                                       getURL($URL,"$path/$name-$rangeLabel.png");
390                                          $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y";                                          $tmp_URL = "$gBaseURL?target=$paramtarget&range=d:w:m:y";
391                                          $html{$filename}.="$desc:<br><a href=\"$tmp_URL\"><img src=$URL><a/><br>";                                          $html{"$rangeLabel\t$paramtarget"}.=do_html($desc,$tmp_URL,$URL);
392                                  }                                  }
393                          }                          }
394                  }                  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.26