+my $charset = 'UTF-8';
+my (%cat, %lang_vars, $prov_string, %s, %fh);
+foreach my $lang (@LANGUAGES) {
+ $cat{$lang} = Packages::I18N::Locale->get_handle($lang)
+ or die "get_handle failed for $lang";
+ $lang_vars{$lang} = { po_lang => $lang, ddtp_lang => $lang,
+ charset => $charset,
+ cat => $cat{$lang}, used_langs => \@LANGUAGES };
+ $s{begin}{$lang} = '['.uc($lang).':';
+ $s{end}{$lang} = ':'.uc($lang).']';
+ $prov_string .= $s{begin}{$lang}.$cat{$lang}->g('virtual package provided by').$s{end}{$lang};
+}
+
+sub open_file {
+ my ($key, $vars, $file) = @_;
+
+ $file ||= 'index';
+
+ print "opening $key\n";
+ mkdirp ( "$wwwdir/$key" );
+ if ($fh{$key}) {
+ warn "filehandle for $key already open\n";
+ return;
+ }
+ open($fh{$key}, '>',
+ "$wwwdir/$key/$file.slices.new")
+ or die "Cannot open file $wwwdir/$key/$file.slices.new: $!";
+
+ foreach my $lang (@LANGUAGES) {
+ print {$fh{$key}} "$s{begin}{$lang}\n";
+ $template->page( 'index_head',
+ { %{$lang_vars{$lang}},
+ %$vars },
+ $fh{$key});
+ print {$fh{$key}} "\n$s{end}{$lang}\n";
+ }
+}
+
+sub close_file {
+ my ($key, $vars, $file) = @_;
+
+ $file ||= 'index';
+
+ print "closing $key\n";
+ unless ($fh{$key}->opened()) {
+ warn "filehandle for $key already closed\n";
+ return;
+ }
+
+ foreach my $lang (@LANGUAGES) {
+ print {$fh{$key}} "\n$s{begin}{$lang}\n";
+ $template->page( 'index_foot',
+ { %{$lang_vars{$lang}},
+ %$vars },
+ $fh{$key});
+ print {$fh{$key}} "\n$s{end}{$lang}\n";
+ }
+ close($fh{$key})
+ or die "Cannot close file $wwwdir/$key/$file.slices.new: $!";
+
+ activate("$wwwdir/$key/$file.slices");
+}
+
+
+sub open_txt_file {
+ my ($key, $vars, $file) = @_;
+
+ $file ||= 'allpackages';
+ my $lang = 'en';
+
+ print "opening $key (txt,lang=$lang)\n";
+ mkdirp ( "$wwwdir/$key" );
+ $fh{"$key/$lang/txt"} = gzopen("$wwwdir/$key/$file.$lang.txt.gz.new", 'wb9')
+ or die "Cannot open file $wwwdir/$key/$file.$lang.txt.gz.new: $!";
+
+ my $gztxt = $txt_template->page( 'index_head',
+ { %{$lang_vars{$lang}},
+ %$vars });
+ $fh{"$key/$lang/txt"}->gzwrite($gztxt);
+}
+
+sub close_txt_file {
+ my ($key, $vars, $file) = @_;
+
+ $file ||= 'allpackages';
+ my $lang = 'en';
+
+ print "closing $key (txt,lang=$lang)\n";
+ my $gztxt = $txt_template->page( 'index_foot',
+ { %{$lang_vars{$lang}},
+ %$vars });
+ $fh{"$key/$lang/txt"}->gzwrite($gztxt);
+ ($fh{"$key/$lang/txt"}->gzclose == Z_OK) or
+ warn("can't close text index file $wwwdir/$key/$file.$lang.txt.gz.new: "
+ . $fh{"$key/$lang/txt"}->gzerror);
+ activate("$wwwdir/$key/$file.$lang.txt.gz");
+}
+
+
+foreach my $source (("", "source/")) {
+ print "write headers ...\n";
+ foreach my $s (@SUITES) {
+ mkdirp ( "$wwwdir/$source$s" );
+ my %common_vars = ( suite => $s,
+ is_source => $source );
+
+ open_file("$source$s", \%common_vars, 'allpackages');
+ open_txt_file("$source$s", \%common_vars, 'allpackages');
+
+ foreach my $sec (keys %{$sections->{$s}}) {
+ open_file("$source$s/$sec",
+ { %common_vars,
+ category => { id => N_('Section'),
+ name => $sec }});
+ }
+ foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
+ next if $ssec eq '-';
+ open_file("$source$s/$ssec",
+ { %common_vars,
+ category => { id => N_('Subsection'),
+ name => $ssec }});
+ }
+ foreach my $prio (keys %{$priorities->{$s}}) {
+ next if $prio eq '-';
+ open_file("$source$s/$prio",
+ { %common_vars,
+ category => { id => N_('Priority'),
+ name => $prio }});
+ }
+ }
+
+ if ($source) {
+ process_source_packages();
+ } else {
+ process_packages();
+ }
+
+ print "write footers ...\n";
+ foreach my $s (@SUITES) {
+ my %common_vars = ( suite => $s,
+ is_source => $source );
+ my $page_base = "$source$s/";
+ close_file("$source$s", { %common_vars,
+ page_name => "${page_base}allpackages" },
+ 'allpackages');
+ close_txt_file("$source$s", { %common_vars,
+ page_name => "{$page_base}allpackages" },
+ 'allpackages');
+
+ foreach my $sec (keys %{$sections->{$s}}) {
+ close_file("$source$s/$sec",
+ { %common_vars,
+ page_name => "$page_base$sec/",
+ category => { id => N_('Section'),
+ name => $sec }});
+ }
+ foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
+ next if $ssec eq '-';
+ close_file("$source$s/$ssec",
+ { %common_vars,
+ page_name => "$page_base$ssec/",
+ category => { id => N_('Subsection'),
+ name => $ssec }});
+ }
+ foreach my $prio (keys %{$priorities->{$s}}) {
+ next if $prio eq '-';
+ close_file("$source$s/$prio",
+ { %common_vars,
+ page_name => "$page_base$prio/",
+ category => { id => N_('Priority'),
+ name => $prio }});
+ }
+ }
+}
+
+sub process_packages {
+
+print "processing package info ...\n";
+my $count = 0;
+foreach my $pkg (@PACKAGES) {
+ warn "pkg=$pkg\n" if DEBUG;
+ print "$count\n" unless ++$count % 1000;
+