16 use Packages::CommonCode qw(:all);
17 use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES @LANGUAGES );
18 use Packages::Template;
19 use Packages::I18N::Locale;
21 use Packages::SrcPage;
22 use Packages::Sections;
23 &Packages::Config::init( './' );
25 use constant DEBUG => 0;
27 my $wwwdir = "$TOPDIR/www";
29 tie my %packages, 'DB_File', "$DBDIR/packages_small.db",
30 O_RDONLY, 0666, $DB_BTREE
31 or die "couldn't tie DB $DBDIR/packages_small.db: $!";
32 tie my %src_packages, 'DB_File', "$DBDIR/sources_small.db",
33 O_RDONLY, 0666, $DB_BTREE
34 or die "couldn't tie DB $DBDIR/sources_small.db: $!";
35 tie my %src2bin, 'DB_File', "$DBDIR/sources_packages.db",
36 O_RDONLY, 0666, $DB_BTREE
37 or die "couldn't open $DBDIR/sources_packages.db: $!";
38 tie my %desctrans, 'DB_File', "$DBDIR/descriptions_translated.db",
39 O_RDONLY, 0666, $DB_BTREE
40 or die "couldn't tie DB $DBDIR/descriptions_translated.db: $!";
42 my $sections = retrieve "$DBDIR/sections.info";
43 my $subsections = retrieve "$DBDIR/subsections.info";
44 my $priorities = retrieve "$DBDIR/priorities.info";
47 #print STDERR Dumper($sections, $subsections, $priorities);
49 my @PACKAGES = sort keys %packages;
50 my @SRC_PACKAGES = sort keys %src_packages;
52 print "Found ".scalar(@PACKAGES)." packages\n";
53 print "Found ".scalar(@SRC_PACKAGES)." source packages\n";
55 my $template = new Packages::Template( "$TOPDIR/templates", 'html');
56 my $txt_template = new Packages::Template( "$TOPDIR/templates", 'txt');
58 my $charset = 'UTF-8';
59 my (%cat, %lang_vars, $prov_string, %s, %fh);
60 foreach my $lang (@LANGUAGES) {
61 $cat{$lang} = Packages::I18N::Locale->get_handle($lang)
62 or die "get_handle failed for $lang";
63 $lang_vars{$lang} = { po_lang => $lang, ddtp_lang => $lang,
65 cat => $cat{$lang}, used_langs => \@LANGUAGES };
66 $s{begin}{$lang} = '['.uc($lang).':';
67 $s{end}{$lang} = ':'.uc($lang).']';
68 $prov_string .= $s{begin}{$lang}.$cat{$lang}->g('virtual package provided by').$s{end}{$lang};
72 my ($key, $vars, $file) = @_;
76 print "opening $key\n";
77 mkdirp ( "$wwwdir/$key" );
79 "$wwwdir/$key/$file.slices.new")
80 or die "Cannot open file $wwwdir/$key/$file.slices.new: $!";
82 foreach my $lang (@LANGUAGES) {
83 print {$fh{$key}} "$s{begin}{$lang}\n";
84 $template->page( 'index_head',
85 { %{$lang_vars{$lang}},
88 print {$fh{$key}} "\n$s{end}{$lang}\n";
93 my ($key, $vars, $file) = @_;
97 print "closing $key\n";
99 foreach my $lang (@LANGUAGES) {
100 print {$fh{$key}} "\n$s{begin}{$lang}\n";
101 $template->page( 'index_foot',
102 { %{$lang_vars{$lang}},
105 print {$fh{$key}} "\n$s{end}{$lang}\n";
108 or die "Cannot close file $wwwdir/$key/$file.slices.new: $!";
110 activate("$wwwdir/$key/$file.slices");
115 my ($key, $vars, $file) = @_;
117 $file ||= 'allpackages';
120 print "opening $key (txt,lang=$lang)\n";
121 mkdirp ( "$wwwdir/$key" );
122 $fh{"$key/$lang/txt"} = gzopen("$wwwdir/$key/$file.$lang.txt.gz.new", 'wb9')
123 or die "Cannot open file $wwwdir/$key/$file.$lang.txt.gz.new: $!";
125 my $gztxt = $txt_template->page( 'index_head',
126 { %{$lang_vars{$lang}},
128 $fh{"$key/$lang/txt"}->gzwrite($gztxt);
132 my ($key, $vars, $file) = @_;
134 $file ||= 'allpackages';
137 print "closing $key (txt,lang=$lang)\n";
138 my $gztxt = $txt_template->page( 'index_foot',
139 { %{$lang_vars{$lang}},
141 $fh{"$key/$lang/txt"}->gzwrite($gztxt);
142 ($fh{"$key/$lang/txt"}->gzclose == Z_OK) or
143 warn("can't close text index file $wwwdir/$key/$file.$lang.txt.gz.new: "
144 . $fh{"$key/$lang/txt"}->gzerror);
145 activate("$wwwdir/$key/$file.$lang.txt.gz");
149 foreach my $source (("", "source/")) {
150 print "write headers ...\n";
151 foreach my $s (@SUITES) {
152 mkdirp ( "$wwwdir/$source$s" );
153 my %common_vars = ( suite => $s,
154 is_source => $source );
156 open_file("$source$s", \%common_vars, 'allpackages');
157 open_txt_file("$source$s", \%common_vars, 'allpackages');
159 foreach my $sec (keys %{$sections->{$s}}) {
160 open_file("$source$s/$sec",
162 category => { id => N_('Section'),
165 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
166 next if $ssec eq '-';
167 open_file("$source$s/$ssec",
169 category => { id => N_('Subsection'),
172 foreach my $prio (keys %{$priorities->{$s}}) {
173 next if $prio eq '-';
174 open_file("$source$s/$prio",
176 category => { id => N_('Priority'),
182 process_source_packages();
187 print "write footers ...\n";
188 foreach my $s (@SUITES) {
189 my %common_vars = ( suite => $s,
190 is_source => $source );
191 close_file("$source$s", \%common_vars, 'allpackages');
192 close_txt_file("$source$s", \%common_vars, 'allpackages');
194 foreach my $sec (keys %{$sections->{$s}}) {
195 close_file("$source$s/$sec",
197 category => { id => N_('Section'),
200 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
201 next if $ssec eq '-';
202 close_file("$source$s/$ssec",
204 category => { id => N_('Subsection'),
207 foreach my $prio (keys %{$priorities->{$s}}) {
208 next if $prio eq '-';
209 close_file("$source$s/$prio",
211 category => { id => N_('Priority'),
217 sub process_packages {
219 print "processing package info ...\n";
221 foreach my $pkg (@PACKAGES) {
222 warn "pkg=$pkg\n" if DEBUG;
223 print "$count\n" unless ++$count % 1000;
226 my ($virt, $p_data) = split /\000/o, $packages{$pkg}, 2;
227 %virt = split /\01/o, $virt;
228 foreach (split /\000/o, $p_data||'') {
229 my @data = split ( /\s/o, $_, 9 );
230 $pkg{$data[1]} ||= new Packages::Page( $pkg );
231 $pkg{$data[1]}->merge_package( { package => $pkg,
234 architecture => $data[2],
236 subsection => $data[4],
237 priority => $data[5],
239 'description-md5' => $data[7],
240 description => $data[8] } );
242 foreach (keys %virt) {
244 $pkg{$_} ||= new Packages::Page( $pkg );
245 $pkg{$_}->add_provided_by([split /\s+/, $virt{$_}]);
248 while (my ($suite, $entry) = each %pkg) {
250 warn "\tsuite=$suite\n" if DEBUG;
251 my %p = ( name => $pkg, providers => [], versions => '' );
252 if (my $provided_by = $entry->{provided_by}) {
253 $p{providers} = $provided_by;
255 $p{subsection} = $p{section} = $p{archive} =
256 $p{desc} = $p{priority} = '';
257 unless ($entry->is_virtual) {
258 (undef, $p{versions}) = $entry->get_version_string;
259 $p{subsection} = $entry->get_newest( 'subsection' );
260 $p{section} = $entry->get_newest( 'section' );
261 $p{archive} = $entry->get_newest( 'archive' );
262 $p{desc} = $entry->get_newest( 'description' );
263 my $desc_md5 = $entry->get_newest( 'description-md5' );
264 my $trans_desc = $desctrans{$desc_md5};
267 my %trans_desc = split /\000|\001/, $trans_desc;
268 while (my ($l, $d) = each %trans_desc) {
269 # filter out non-po languages
270 next unless exists $lang_vars{$l};
275 $p{trans_desc} = \%sdescs if %sdescs;
277 $p{priority} = $entry->get_newest( 'priority' );
280 my $html = my $txt = "";
281 my $id = " id='$p{name}'";
283 warn "\tversions=$p{versions}\n" if DEBUG;
285 $html .= "\n<dt><a href='$p{name}'$id>$p{name}</a> ($p{versions})";
287 $html .= " [<strong class='pmarker'>$p{section}</strong>]"
288 if $p{section} ne 'main';
289 $html .= " [<strong class='pmarker'>$p{archive}</strong>]"
290 if $p{archive} ne 'us';
291 $html .= "</dt>\n<dd";
293 $txt .= "\n$p{name} ($p{versions})";
294 $txt .= " [$p{section}]" if $p{section} ne 'main';
295 $txt .= " [$p{archive}]" if $p{archive} ne 'us';
298 if ($p{trans_desc}) {
299 foreach my $lang (@LANGUAGES) {
300 my ($sdesc, $sdesc_html, $desclang) = ($p{desc},
301 encode_entities($p{desc}, '<>&"\''),
303 if ($p{trans_desc}{$lang}) {
304 $sdesc = $p{trans_desc}{$lang};
305 $sdesc_html = encode_entities($sdesc, '<>&"\'');
309 $html .= $s{begin}{$lang};
310 $html .= " lang='$desclang'" if $desclang ne $lang;
311 $html .= ">$sdesc_html$s{end}{$lang}";
314 $html .= " lang='en'>".encode_entities($p{desc}, '<>&"\'');
320 if (@{$p{providers}}) {
321 warn "\tproviders=@{$p{providers}}\n" if DEBUG;
322 $html .= "\n<dt><a href='$p{name}'$id>$p{name}</a></dt><dd>$prov_string ";
324 foreach my $prov (@{$p{providers}}) {
325 my $prov_uri = uri_escape($prov);
326 push @prov, "<a href='../$prov_uri'>$prov</a>";
328 $html .= join(', ', @prov)."</dd>";
329 $txt .= "\n$p{name} virtual package provided by ".
330 join(', ', @{$p{providers}});
332 warn "HTML=$html\n" if DEBUG > 1;
333 warn "TXT=$txt\n" if DEBUG > 1;
335 print {$fh{$suite}} $html;
336 $fh{"$suite/en/txt"}->gzwrite($txt);
337 foreach my $key (qw(section subsection priority)) {
338 next unless $fh{"$suite/$p{$key}"};
339 warn "\t\t$suite/$p{$key}\n" if DEBUG;
340 print {$fh{"$suite/$p{$key}"}} $html;
347 sub process_source_packages {
349 print "collecting source package info ...\n";
351 foreach my $pkg (@SRC_PACKAGES) {
352 warn "pkg=$pkg\n" if DEBUG;
353 print "$count\n" unless ++$count % 1000;
356 foreach (split /\000/o, $src_packages{$pkg}||'') {
357 my @data = split ( /\s/o, $_ );
358 $pkg{$data[1]} ||= new Packages::SrcPage( $pkg );
359 $pkg{$data[1]}->merge_package( { package => $pkg,
363 subsection => $data[3],
364 priority => $data[4],
369 while (my ($suite, $entry) = each %pkg) {
370 my %p = ( name => $pkg, providers => [], versions => '' );
371 $p{versions} = $entry->{version};
372 $p{subsection} = $entry->get_newest( 'subsection' );
373 $p{section} = $entry->get_newest( 'section' );
374 $p{archive} = $entry->get_newest( 'archive' );
375 $p{priority} = $entry->get_newest( 'priority' );
379 # my $binaries = find_binaries( $pkg, $p{archive}, $p{suite}, \%src2bin );
380 # if ($binaries && @$binaries) {
381 # pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
384 my $html = my $txt = "";
385 warn "\tversions=$p{versions}\n" if DEBUG;
387 $html .= "\n<dt><a href='$p{name}' id='$p{name}'>$p{name}</a> ($p{versions})";
388 $html .= " [<strong class='pmarker'>$p{section}</strong>]"
389 if $p{section} ne 'main';
390 $html .= " [<strong class='pmarker'>$p{archive}</strong>]"
391 if $p{archive} ne 'us';
394 $txt .= "\n$p{name} ($p{versions})";
395 $txt .= " [$p{section}]" if $p{section} ne 'main';
396 $txt .= " [$p{archive}]" if $p{archive} ne 'us';
398 warn "HTML=$html\n" if DEBUG > 1;
399 warn "TXT=$txt\n" if DEBUG > 1;
401 print {$fh{"source/$suite"}} $html;
402 $fh{"source/$suite/en/txt"}->gzwrite($txt);
403 foreach my $key (qw(section subsection priority)) {
404 next unless $fh{"source/$suite/$p{$key}"};
405 warn "\t\tsource/$suite/$p{$key}\n" if DEBUG;
406 print {$fh{"source/$suite/$p{$key}"}} $html;