3 # $Id: SWList.pm,v 1.1 1999/07/30 18:46:37 mdw Exp $
5 # Create the main list of installed packages
10 #----- Licensing notice -----------------------------------------------------
12 # This file is part of sw-tools.
14 # sw-tools is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # sw-tools is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with sw-tools; if not, write to the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #----- Revision history -----------------------------------------------------
31 # Revision 1.1 1999/07/30 18:46:37 mdw
32 # New CGI script for browsing installed software and documentation.
35 #----- Package header -------------------------------------------------------
44 use SWCGI
qw(:DEFAULT
:layout
);
46 #----- Main code ------------------------------------------------------------
50 # Action to output the installed software list.
52 %archmap = ( "linux" => 'l',
65 # --- Read the architecture table and assign mnemonic-ish letters ---
68 my $a = IO
::File
->new("$C{datadir}/archtab") or
69 barf
("couldn't open archtab: $!");
71 LINE
: while (my $line = $a->getline()) {
73 # --- Skip comments and boring things ---
76 next LINE
if $line =~ /^\s*$/ || $line =~ /^\s*\#/;
78 # --- Break into components ---
80 my ($arch, $host) = split(" ", $line, 3);
82 # --- Assign a mnemonic character ---
84 # In dire cases, this will choose multiple characters. Oh, well. If
85 # you have more than 26 architectures to maintain, this is the least of
90 foreach my $k (keys(%archmap)) {
91 if (index($arch, $k) >= 0 && !$mn->{$archmap{$k}}) {
97 for (my $i = 0; $i < length($arch); $i++) {
98 my $ch = lc(substr($arch, $i, 1));
99 next unless $ch =~ /[a-z]/;
100 $mn = $ch, last unless $mn{$ch};
104 ($hi = $arch) =~ s
:$mn:<u
>$mn</u
>:;
106 for ($mn = "a"; $mn{$mn}; $mn++) { }
107 $hi = "$arch (<u>$mn</u>)";
109 push(@arch, { arch
=> $arch, host
=> $host, mn
=> $mn, hi
=> $hi });
112 @arch = sort { length($a->{mn
}) <=> length($b->{mn
}) ||
113 $a->{mn
} cmp $b->{mn
} } @arch;
116 # --- Emit a header ---
118 header
("Installed software");
121 <h3>Documentation</h3>
123 <li><a href="$ref?act=man">Manual pages</a>
124 <li><a href="$ref?act=info">GNU Info</a>
127 <h3>Installed software</h3>
130 <th rowspan=2>Package
131 <th rowspan=2>Version
132 <th rowspan=2 colspan=2>Maintainer
133 <th colspan=$narch>Architectures
134 <th rowspan=2>Date installed
138 # --- Spit out the archtecture mnemonics ---
140 print "<tr align=left>\n ";
141 foreach my $a (@arch) { print "<th>" . $a->{mn
}; }
144 # --- Iterate through the installed packages ---
147 foreach my $pkg ($sw->list()) {
148 my $m = $sw->get($pkg);
151 # --- The package and version number are easy ---
153 print(" <td>$m->{package}\n");
154 print(" <td>$m->{version}\n");
156 # --- Resolve the maintainer into a sensible real name ---
159 my $maint = $m->{"maintainer"};
160 my @pw = getpwnam($maint);
161 my ($gecos) = split(/,/, $pw[6], 2);
162 my $addr = $maint . ($C{domain
} && "\@" . $C{domain
});
163 print(" <td>$gecos<td><<a href=\"mailto:$addr\">$addr</a>>\n");
166 # --- Dump out the architectures ---
168 # Assume that the names aren't ambiguous.
172 foreach my $ar (split(/[\s,]+/, $m->{"arch"})) {
174 foreach my $a (@arch) {
175 if ($a->{arch
} =~ /^$ar/) {
183 foreach my $a (@arch) {
184 if ($a{$a->{arch
}}) {
185 print("<td>", $a->{mn
});
193 # --- Print the date ---
195 print(" <td>$m->{date}\n");
197 # --- If the documentation file exists, put a link in ---
199 if (-r
"$C{doc}/$pkg") {
200 print(" <td><a href=\"$ref?act=doc&pkg=$pkg\">Yes</a>\n");
210 # --- Emit a legend for the architecture lists ---
212 print "<p><b>Architectures:</b>\n";
213 foreach my $a (@arch) {
214 print $a->{hi
}, "\n";
219 #----- Register actions -----------------------------------------------------
221 $main::ACT
{"list"} = \
&list
;
223 #----- That's all, folks ----------------------------------------------------