-
Notifications
You must be signed in to change notification settings - Fork 1
/
WriteModulesFile.pm
86 lines (77 loc) · 2.59 KB
/
WriteModulesFile.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package WriteModulesFile;
use strict;
use Log::Log4perl qw(get_logger);
use ModuleList;
sub WriteSwitchModuleTableFragment ($$) {
my $ModuleList = shift;
my $SwitchName = shift;
my $logger = get_logger('log3');
$logger->debug("called, SwitchName = \"$SwitchName\"");
my $NbrModulesWritten = 0;
my $RemainderOfFragment = '';
my $FirstTimeThroughLoop = 1;
foreach my $ModNbr (sort {$a <=> $b} keys %{$ModuleList->{Model}}) {
my $HtmlStyle= ModuleList::GetModuleHtmlStyle($ModuleList, $ModNbr);
if ($FirstTimeThroughLoop) {
$FirstTimeThroughLoop = 0; # first time through, don't output "<tr>"
} else {
$RemainderOfFragment .= "<tr>";
}
$RemainderOfFragment .= <<MBS2;
<td $HtmlStyle>$ModNbr</td>
<td $HtmlStyle>$ModuleList->{Model}{$ModNbr}</td>
<td $HtmlStyle>$ModuleList->{Description}{$ModNbr}</td>
<td $HtmlStyle>$ModuleList->{HwVersion}{$ModNbr}</td>
<td $HtmlStyle>$ModuleList->{FwVersion}{$ModNbr}</td>
<td $HtmlStyle>$ModuleList->{SwVersion}{$ModNbr}</td>
<td $HtmlStyle>$ModuleList->{SerialNumberString}{$ModNbr}</td>
</tr>
MBS2
$NbrModulesWritten++;
}
my $SwitchCell = <<FULLMOD;
<tr><td colspan="8" height="4" bgcolor="black"></td></tr>
<tr><td rowspan="$NbrModulesWritten"><a href=\"switches/$SwitchName.html\">$SwitchName</a></td>
FULLMOD
my $retval = $SwitchCell . $RemainderOfFragment;
$logger->debug("returning");
return $retval;
}
sub WriteModulesFile ($) {
my $SwitchesRef = shift;
my $logger = get_logger('log2');
my $ModulesBySwitchFileName = File::Spec->catfile($ThisSite::DestinationDirectory, $Constants::ModulesBySwitchFile);
$logger->debug("called, writing $ModulesBySwitchFileName");
$logger->info("writing $ModulesBySwitchFileName");
open MODSBYSWITCHFILE, ">$ModulesBySwitchFileName" or do {
$logger->fatal("Couldn't open $ModulesBySwitchFileName for writing, $!");
exit;
};
print MODSBYSWITCHFILE SwitchUtils::HtmlHeader("Modules");
print MODSBYSWITCHFILE <<MBS;
<p>
<table class="Modules">
<tr class="tblHead">
<th>Switch</th>
<th>Slot</th>
<th>Model</th>
<th>Description</th>
<th>HW</th>
<th>FW</th>
<th>SW</th>
<th>Serial</th>
</tr>
MBS
foreach my $Switch (@$SwitchesRef) {
if ($Switch->{NbrModules} > 1) { # if it has modules (i.e. 6509s have modules, 3524s don't)
my $SwitchName = GetName $Switch;
print MODSBYSWITCHFILE WriteSwitchModuleTableFragment($Switch->{ModuleList}, $SwitchName);
}
}
print MODSBYSWITCHFILE "</table>\n";
print MODSBYSWITCHFILE SwitchUtils::HtmlTrailer;
close MODSBYSWITCHFILE;
SwitchUtils::AllowAllToReadFile $ModulesBySwitchFileName;
$logger->debug("returning");
}
1;