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 my $page_base = "$source$s/";
192 close_file("$source$s", { %common_vars,
193 page_name => "${page_base}allpackages" },
195 close_txt_file("$source$s", { %common_vars,
196 page_name => "{$page_base}allpackages" },
199 foreach my $sec (keys %{$sections->{$s}}) {
200 close_file("$source$s/$sec",
202 page_name => "$page_base$sec/",
203 category => { id => N_('Section'),
206 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
207 next if $ssec eq '-';
208 close_file("$source$s/$ssec",
210 page_name => "$page_base$ssec/",
211 category => { id => N_('Subsection'),
214 foreach my $prio (keys %{$priorities->{$s}}) {
215 next if $prio eq '-';
216 close_file("$source$s/$prio",
218 page_name => "$page_base$prio/",
219 category => { id => N_('Priority'),
225 sub process_packages {
227 print "processing package info ...\n";
229 foreach my $pkg (@PACKAGES) {
230 warn "pkg=$pkg\n" if DEBUG;
231 print "$count\n" unless ++$count % 1000;
234 my ($virt, $p_data) = split /\000/o, $packages{$pkg}, 2;
235 %virt = split /\01/o, $virt;
236 foreach (split /\000/o, $p_data||'') {
237 my @data = split ( /\s/o, $_, 9 );
238 $pkg{$data[1]} ||= new Packages::Page( $pkg );
239 $pkg{$data[1]}->merge_package( { package => $pkg,
242 architecture => $data[2],
244 subsection => $data[4],
245 priority => $data[5],
247 'description-md5' => $data[7],
248 description => $data[8] } );
250 foreach (keys %virt) {
252 $pkg{$_} ||= new Packages::Page( $pkg );
253 $pkg{$_}->add_provided_by([split /\s+/, $virt{$_}]);
256 while (my ($suite, $entry) = each %pkg) {
258 warn "\tsuite=$suite\n" if DEBUG;
259 my %p = ( name => $pkg, providers => [], versions => '' );
260 if (my $provided_by = $entry->{provided_by}) {
261 $p{providers} = $provided_by;
263 $p{subsection} = $p{section} = $p{archive} =
264 $p{desc} = $p{priority} = '';
265 unless ($entry->is_virtual) {
266 (undef, $p{versions}) = $entry->get_version_string;
267 $p{subsection} = $entry->get_newest( 'subsection' );
268 $p{section} = $entry->get_newest( 'section' );
269 $p{archive} = $entry->get_newest( 'archive' );
270 $p{desc} = $entry->get_newest( 'description' );
271 my $desc_md5 = $entry->get_newest( 'description-md5' );
272 my $trans_desc = $desctrans{$desc_md5};
275 my %trans_desc = split /\000|\001/, $trans_desc;
276 while (my ($l, $d) = each %trans_desc) {
277 # filter out non-po languages
278 next unless exists $lang_vars{$l};
283 $p{trans_desc} = \%sdescs if %sdescs;
285 $p{priority} = $entry->get_newest( 'priority' );
288 my $html = my $txt = "";
289 my $id = " id='$p{name}'";
291 warn "\tversions=$p{versions}\n" if DEBUG;
293 $html .= "\n<dt><a href='$p{name}'$id>$p{name}</a> ($p{versions})";
295 $html .= " [<strong class='pmarker'>$p{section}</strong>]"
296 if $p{section} ne 'main';
297 $html .= " [<strong class='pmarker'>$p{archive}</strong>]"
298 if $p{archive} ne 'us';
299 $html .= "</dt>\n<dd";
301 $txt .= "\n$p{name} ($p{versions})";
302 $txt .= " [$p{section}]" if $p{section} ne 'main';
303 $txt .= " [$p{archive}]" if $p{archive} ne 'us';
306 if ($p{trans_desc}) {
307 foreach my $lang (@LANGUAGES) {
308 my ($sdesc, $sdesc_html, $desclang) = ($p{desc},
309 encode_entities($p{desc}, '<>&"\''),
311 if ($p{trans_desc}{$lang}) {
312 $sdesc = $p{trans_desc}{$lang};
313 $sdesc_html = encode_entities($sdesc, '<>&"\'');
317 $html .= $s{begin}{$lang};
318 $html .= " lang='$desclang'" if $desclang ne $lang;
319 $html .= ">$sdesc_html$s{end}{$lang}";
322 $html .= " lang='en'>".encode_entities($p{desc}, '<>&"\'');
328 if (@{$p{providers}}) {
329 warn "\tproviders=@{$p{providers}}\n" if DEBUG;
330 $html .= "\n<dt><a href='$p{name}'$id>$p{name}</a></dt><dd>$prov_string ";
332 foreach my $prov (@{$p{providers}}) {
333 my $prov_uri = uri_escape($prov);
334 push @prov, "<a href='../$prov_uri'>$prov</a>";
336 $html .= join(', ', @prov)."</dd>";
337 $txt .= "\n$p{name} virtual package provided by ".
338 join(', ', @{$p{providers}});
340 warn "HTML=$html\n" if DEBUG > 1;
341 warn "TXT=$txt\n" if DEBUG > 1;
343 print {$fh{$suite}} $html;
344 $fh{"$suite/en/txt"}->gzwrite($txt);
345 foreach my $key (qw(section subsection priority)) {
346 next unless $fh{"$suite/$p{$key}"};
347 warn "\t\t$suite/$p{$key}\n" if DEBUG;
348 print {$fh{"$suite/$p{$key}"}} $html;
355 sub process_source_packages {
357 print "collecting source package info ...\n";
359 foreach my $pkg (@SRC_PACKAGES) {
360 warn "pkg=$pkg\n" if DEBUG;
361 print "$count\n" unless ++$count % 1000;
364 foreach (split /\000/o, $src_packages{$pkg}||'') {
365 my @data = split ( /\s/o, $_ );
366 $pkg{$data[1]} ||= new Packages::SrcPage( $pkg );
367 $pkg{$data[1]}->merge_package( { package => $pkg,
371 subsection => $data[3],
372 priority => $data[4],
377 while (my ($suite, $entry) = each %pkg) {
378 my %p = ( name => $pkg, providers => [], versions => '' );
379 $p{versions} = $entry->{version};
380 $p{subsection} = $entry->get_newest( 'subsection' );
381 $p{section} = $entry->get_newest( 'section' );
382 $p{archive} = $entry->get_newest( 'archive' );
383 $p{priority} = $entry->get_newest( 'priority' );
387 # my $binaries = find_binaries( $pkg, $p{archive}, $p{suite}, \%src2bin );
388 # if ($binaries && @$binaries) {
389 # pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
392 my $html = my $txt = "";
393 warn "\tversions=$p{versions}\n" if DEBUG;
395 $html .= "\n<dt><a href='$p{name}' id='$p{name}'>$p{name}</a> ($p{versions})";
396 $html .= " [<strong class='pmarker'>$p{section}</strong>]"
397 if $p{section} ne 'main';
398 $html .= " [<strong class='pmarker'>$p{archive}</strong>]"
399 if $p{archive} ne 'us';
402 $txt .= "\n$p{name} ($p{versions})";
403 $txt .= " [$p{section}]" if $p{section} ne 'main';
404 $txt .= " [$p{archive}]" if $p{archive} ne 'us';
406 warn "HTML=$html\n" if DEBUG > 1;
407 warn "TXT=$txt\n" if DEBUG > 1;
409 print {$fh{"source/$suite"}} $html;
410 $fh{"source/$suite/en/txt"}->gzwrite($txt);
411 foreach my $key (qw(section subsection priority)) {
412 next unless $fh{"source/$suite/$p{$key}"};
413 warn "\t\tsource/$suite/$p{$key}\n" if DEBUG;
414 print {$fh{"source/$suite/$p{$key}"}} $html;