17 use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES @LANGUAGES $LOCALES);
18 use Packages::Template;
19 use Packages::I18N::Locale;
21 use Packages::SrcPage;
22 use Packages::Sections;
23 &Packages::Config::init( './' );
25 delete $ENV{'LANGUAGE'};
27 delete $ENV{'LC_ALL'};
28 delete $ENV{'LC_MESSAGES'};
29 bindtextdomain ( 'pdo', $LOCALES );
30 bindtextdomain ( 'sections', $LOCALES );
33 my $wwwdir = "$TOPDIR/www";
35 tie my %packages, 'DB_File', "$DBDIR/packages_small.db",
36 O_RDONLY, 0666, $DB_BTREE
37 or die "couldn't tie DB $DBDIR/packages_small.db: $!";
38 tie my %src_packages, 'DB_File', "$DBDIR/sources_small.db",
39 O_RDONLY, 0666, $DB_BTREE
40 or die "couldn't tie DB $DBDIR/sources_small.db: $!";
41 tie my %src2bin, 'DB_File', "$DBDIR/sources_packages.db",
42 O_RDONLY, 0666, $DB_BTREE
43 or die "couldn't open $DBDIR/sources_packages.db: $!";
45 my $sections = retrieve "$DBDIR/sections.info";
46 my $subsections = retrieve "$DBDIR/subsections.info";
47 # work around problems with non-US security updates
48 $subsections->{oldstable}{us}{'non-US'}++;
49 my $priorities = retrieve "$DBDIR/priorities.info";
52 #print STDERR Dumper($sections, $subsections, $priorities);
56 my $template = new Packages::Template( "$TOPDIR/templates", 'html', {} );
58 print "write suite index files ...\n";
59 foreach my $s (@SUITES) {
61 mkpath ( "$wwwdir/$key" );
62 foreach my $lang (@LANGUAGES) {
63 my $locale = get_locale( $lang );
64 my $charset = get_locale( $lang );
65 setlocale ( LC_ALL, $locale ) or do {
66 warn "couldn't set locale ($lang/$locale)\n";
69 print "writing $key/index (lang=$lang)...\n";
71 my %content = ( subsections => [], suite => $s,
72 lang => $lang, charset => $charset,
74 $content{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
75 $content{make_url} = sub { return &Packages::CGI::make_url(@_) };
76 # needed to work around the limitations of the the FILTER syntax
77 $content{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
78 $content{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
79 $content{quotemeta} = sub { return quotemeta($_[0]) };
81 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
83 if ($sections_descs{$ssec}) {
84 push @{$content{subsections}}, {
86 name => dgettext( 'sections', $sections_descs{$ssec}[0] ),
87 desc => dgettext( 'sections', $sections_descs{$ssec}[1] ),
92 open $pages{$key}{$lang}{index}{fh}, '>', "$wwwdir/$key/index.$lang.html.new"
93 or die "can't open index file for output: $!";
94 print {$pages{$key}{$lang}{index}{fh}} $template->page( 'suite_index', \%content );
95 print {$pages{$key}{$lang}{index}{fh}} $template->trailer( 'index', $lang, \@LANGUAGES );
96 close $pages{$key}{$lang}{index}{fh} or
97 warn "can't close index file $wwwdir/$key/index.$lang.html.new: $!";
98 rename( "$wwwdir/$key/index.$lang.html.new",
99 "$wwwdir/$key/index.$lang.html" );
101 $content{source} = 'source';
102 open $pages{$key}{$lang}{source_index}{fh}, '>', "$wwwdir/source/$key/index.$lang.html.new"
103 or die "can't open index file for output: $!";
104 print {$pages{$key}{$lang}{source_index}{fh}} $template->page( 'suite_index', \%content );
105 print {$pages{$key}{$lang}{source_index}{fh}} $template->trailer( 'index', $lang, \@LANGUAGES );
106 close $pages{$key}{$lang}{source_index}{fh} or
107 warn "can't close index file $wwwdir/source/$key/index.$lang.html.new: $!";
108 rename( "$wwwdir/source/$key/index.$lang.html.new",
109 "$wwwdir/source/$key/index.$lang.html" );
113 setlocale( LC_ALL, 'C' ) or die "couldn't reset locale";
115 print "collecting package info ...\n";
117 while (my ($pkg, $data) = each %packages) {
119 my ($virt, $p_data) = split /\000/o, $data, 2;
120 %virt = split /\01/o, $virt;
121 foreach (split /\000/o, $p_data||'') {
122 my @data = split ( /\s/o, $_, 8 );
123 $pkg{$data[1]} ||= new Packages::Page( $pkg );
124 $pkg{$data[1]}->merge_package( { package => $pkg,
127 architecture => $data[2],
129 subsection => $data[4],
130 priority => $data[5],
132 description => $data[7] } );
134 foreach (keys %virt) {
136 $pkg{$_} ||= new Packages::Page( $pkg );
137 $pkg{$_}->add_provided_by([split /\s+/, $virt{$_}]);
140 while (my ($key, $entry) = each %pkg) {
141 $allpkgs{$key} ||= [];
143 my %p = ( name => $pkg, providers => [], versions => '' );
144 if (my $provided_by = $entry->{provided_by}) {
145 $p{providers} = $provided_by;
147 $p{subsection} = $p{section} = $p{archive} = $p{desc} = $p{priority} = '';
148 unless ($entry->is_virtual) {
149 (undef, $p{versions}) = $entry->get_version_string;
150 $p{subsection} = $entry->get_newest( 'subsection' );
151 $p{section} = $entry->get_newest( 'section' );
152 $p{archive} = $entry->get_newest( 'archive' );
153 $p{desc} = $entry->get_newest( 'description' );
154 $p{priority} = $entry->get_newest( 'priority' );
156 push @{$allpkgs{$key}}, \%p;
160 write_files(\%allpkgs);
162 print "collecting source package info ...\n";
164 while (my ($pkg, $data) = each %src_packages) {
166 foreach (split /\000/o, $data||'') {
167 my @data = split ( /\s/o, $_ );
168 $pkg{$data[1]} ||= new Packages::SrcPage( $pkg );
169 $pkg{$data[1]}->merge_package( { package => $pkg,
173 subsection => $data[3],
174 priority => $data[4],
179 while (my ($key, $entry) = each %pkg) {
180 $allsrcpkgs{$key} ||= [];
182 my %p = ( name => $pkg, providers => [], versions => '' );
183 $p{versions} = $entry->{version};
184 $p{subsection} = $entry->get_newest( 'subsection' );
185 $p{section} = $entry->get_newest( 'section' );
186 $p{archive} = $entry->get_newest( 'archive' );
187 $p{priority} = $entry->get_newest( 'priority' );
191 # my $binaries = find_binaries( $pkg, $p{archive}, $p{suite}, \%src2bin );
192 # if ($binaries && @$binaries) {
193 # pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
196 push @{$allsrcpkgs{$key}}, \%p;
200 write_files(\%allsrcpkgs, 1);
203 my ($pkgs, $source) = @_;
205 $source = $source ? 'source/' : '';
206 print "writing files ...\n";
207 foreach my $s (@SUITES) {
209 mkpath ( "$wwwdir/$source$key" );
210 print "writing $source$s/allpackages...\n";
211 $template->process( 'html/index.tmpl', { packages => $pkgs->{$key}, suite => $s, lang => 'en', is_source => $source },
212 "$wwwdir/$source$key/allpackages.en.html.new" )
213 or die "error writing allpackages for $key: ".$template->error();
214 print "writing $source$s/allpackages (txt)...\n";
215 my $gzfh = gzopen("$wwwdir/$source$key/allpackages.en.txt.gz.new",
217 or die "can't open text index file for output: $!";
219 $template->process( 'txt/index.tmpl', { packages => $pkgs->{$key}, suite => $s, lang => 'en', is_source => $source },
221 or die "error writing allpackages txt for $key: ".$template->error();
222 $gzfh->gzwrite($gztxt);
223 ($gzfh->gzclose == Z_OK) or
224 warn "can't close text index file $wwwdir/$source$key/allpackages.en.txt.gz.new: ".$gzfh->gzerror;
226 rename( "$wwwdir/$source$key/allpackages.en.html.new",
227 "$wwwdir/$source$key/allpackages.en.html" );
228 rename( "$wwwdir/$source$key/allpackages.en.txt.gz.new",
229 "$wwwdir/$source$key/allpackages.en.txt.gz" );
231 foreach my $sec (keys %{$sections->{$s}}) {
232 mkpath ( "$wwwdir/$source$key/$sec" );
234 print "writing $source$s/$sec/index...\n";
235 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{section} eq $sec } @{$pkgs->{$key}} ],
236 suite => $s, lang => 'en', is_source => $source,
237 category => { id => 'section', name => $sec } },
238 "$wwwdir/$source$key/$sec/index.en.html.new" )
239 or die "error writing section index for $key/$sec: ".$template->error();
240 rename( "$wwwdir/$source$key/$sec/index.en.html.new",
241 "$wwwdir/$source$key/$sec/index.en.html" );
243 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
244 next if $ssec eq '-';
245 mkpath ( "$wwwdir/$source$key/$ssec" );
247 print "writing $source$s/$ssec/index...\n";
248 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{subsection} eq $ssec } @{$pkgs->{$key}} ],
249 suite => $s, lang => 'en', is_source => $source,
250 category => { id => 'subsection', name => $ssec } },
251 "$wwwdir/$source$key/$ssec/index.en.html.new" )
252 or die "error writing subsection index for $key/$ssec: ".$template->error();
253 rename( "$wwwdir/$source$key/$ssec/index.en.html.new",
254 "$wwwdir/$source$key/$ssec/index.en.html" );
256 foreach my $prio (keys %{$priorities->{$s}}) {
257 next if $prio eq '-';
258 mkpath ( "$wwwdir/$source$key/$prio" );
260 print "writing $source$s/$prio/index...\n";
261 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{priority} eq $prio } @{$pkgs->{$key}} ],
262 suite => $s, lang => 'en', is_source => $source,
263 category => { id => 'priority', name => $prio } },
264 "$wwwdir/$source$key/$prio/index.en.html.new" )
265 or die "error writing priority index for $key/$prio: ".$template->error();
266 rename( "$wwwdir/$source$key/$prio/index.en.html.new",
267 "$wwwdir/$source$key/$prio/index.en.html" );