3 # $Id: SWList.pm,v 1.3 2004/04/08 01:52:19 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 #----- Package header -------------------------------------------------------
37 use SWCGI
qw(:DEFAULT
:layout
);
39 #----- Main code ------------------------------------------------------------
43 # Action to output the installed software list.
45 %archmap = ( "linux" => 'l',
58 # --- Read the architecture table and assign mnemonic-ish letters ---
61 my $a = IO
::File
->new("$C{datadir}/archtab") or
62 barf
("couldn't open archtab: $!");
64 LINE
: while (my $line = $a->getline()) {
66 # --- Skip comments and boring things ---
69 next LINE
if $line =~ /^\s*$/ || $line =~ /^\s*\#/;
71 # --- Break into components ---
73 my ($arch, $host) = split(" ", $line, 3);
75 # --- Assign a mnemonic character ---
77 # In dire cases, this will choose multiple characters. Oh, well. If
78 # you have more than 26 architectures to maintain, this is the least of
83 foreach my $k (keys(%archmap)) {
84 if (index($arch, $k) >= 0 && !$mn->{$archmap{$k}}) {
90 for (my $i = 0; $i < length($arch); $i++) {
91 my $ch = lc(substr($arch, $i, 1));
92 next unless $ch =~ /[a-z]/;
93 $mn = $ch, last unless $mn{$ch};
97 ($hi = $arch) =~ s
:$mn:<u
>$mn</u
>:;
99 for ($mn = "a"; $mn{$mn}; $mn++) { }
100 $hi = "$arch (<u>$mn</u>)";
102 push(@arch, { arch
=> $arch, host
=> $host, mn
=> $mn, hi
=> $hi });
105 @arch = sort { length($a->{mn
}) <=> length($b->{mn
}) ||
106 $a->{mn
} cmp $b->{mn
} } @arch;
109 # --- Emit a header ---
111 header
("Installed software");
114 <h3>Documentation</h3>
116 <li><a href="$ref?act=man">Manual pages</a>
117 <li><a href="$ref?act=info">GNU Info</a>
120 <h3>Installed software</h3>
123 <th rowspan=2>Package
124 <th rowspan=2>Version
125 <th rowspan=2 colspan=2>Maintainer
126 <th colspan=$narch>Architectures
127 <th rowspan=2>Date installed
131 # --- Spit out the archtecture mnemonics ---
133 print "<tr align=left>\n ";
134 foreach my $a (@arch) { print "<th>" . $a->{mn
}; }
137 # --- Iterate through the installed packages ---
140 foreach my $pkg ($sw->list()) {
141 my $m = $sw->get($pkg);
144 # --- The package and version number are easy ---
146 print(" <td>$m->{package}\n");
147 print(" <td>$m->{version}\n");
149 # --- Resolve the maintainer into a sensible real name ---
152 my $maint = $m->{"maintainer"};
153 my @pw = getpwnam($maint);
154 my ($gecos) = split(/,/, $pw[6], 2);
155 my $addr = $maint . ($C{domain
} && "\@" . $C{domain
});
156 print(" <td>$gecos<td><<a href=\"mailto:$addr\">$addr</a>>\n");
159 # --- Dump out the architectures ---
161 # Assume that the names aren't ambiguous.
165 foreach my $ar (split(/[\s,]+/, $m->{"arch"})) {
167 foreach my $a (@arch) {
168 if ($a->{arch
} =~ /^$ar/) {
176 foreach my $a (@arch) {
177 if ($a{$a->{arch
}}) {
178 print("<td>", $a->{mn
});
186 # --- Print the date ---
188 print(" <td>$m->{date}\n");
190 # --- If the documentation file exists, put a link in ---
192 if (-r
"$C{doc}/$pkg") {
193 printf(" <td><a href=\"$ref?act=doc&pkg=%s\">Yes</a>\n",
194 SWCGI
::sanitize
($pkg));
204 # --- Emit a legend for the architecture lists ---
206 print "<p><b>Architectures:</b>\n";
207 foreach my $a (@arch) {
208 print $a->{hi
}, "\n";
213 #----- Register actions -----------------------------------------------------
215 $main::ACT
{"list"} = \
&list
;
217 #----- That's all, folks ----------------------------------------------------