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 mkpath ( "$wwwdir/source/$key" );
63 foreach my $lang (@LANGUAGES) {
64 my $locale = get_locale( $lang );
65 my $charset = get_locale( $lang );
66 setlocale ( LC_ALL, $locale ) or do {
67 warn "couldn't set locale ($lang/$locale)\n";
70 print "writing $key/index (lang=$lang)...\n";
72 my %content = ( subsections => [], suite => $s,
73 lang => $lang, charset => $charset,
74 used_langs => \@LANGUAGES, suites => \@SUITES );
75 $content{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
76 $content{make_url} = sub { return &Packages::CGI::make_url(@_) };
77 # needed to work around the limitations of the the FILTER syntax
78 $content{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
79 $content{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
80 $content{quotemeta} = sub { return quotemeta($_[0]) };
82 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
84 if ($sections_descs{$ssec}) {
85 push @{$content{subsections}}, {
87 name => dgettext( 'sections', $sections_descs{$ssec}[0] ),
88 desc => dgettext( 'sections', $sections_descs{$ssec}[1] ),
93 open $pages{$key}{$lang}{index}{fh}, '>', "$wwwdir/$key/index.$lang.html.new"
94 or die "can't open index file for output: $!";
95 print {$pages{$key}{$lang}{index}{fh}} $template->page( 'suite_index', \%content );
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 close $pages{$key}{$lang}{source_index}{fh} or
106 warn "can't close index file $wwwdir/source/$key/index.$lang.html.new: $!";
107 rename( "$wwwdir/source/$key/index.$lang.html.new",
108 "$wwwdir/source/$key/index.$lang.html" );
112 setlocale( LC_ALL, 'C' ) or die "couldn't reset locale";
114 print "collecting package info ...\n";
116 while (my ($pkg, $data) = each %packages) {
118 my ($virt, $p_data) = split /\000/o, $data, 2;
119 %virt = split /\01/o, $virt;
120 foreach (split /\000/o, $p_data||'') {
121 my @data = split ( /\s/o, $_, 8 );
122 $pkg{$data[1]} ||= new Packages::Page( $pkg );
123 $pkg{$data[1]}->merge_package( { package => $pkg,
126 architecture => $data[2],
128 subsection => $data[4],
129 priority => $data[5],
131 description => $data[7] } );
133 foreach (keys %virt) {
135 $pkg{$_} ||= new Packages::Page( $pkg );
136 $pkg{$_}->add_provided_by([split /\s+/, $virt{$_}]);
139 while (my ($key, $entry) = each %pkg) {
140 $allpkgs{$key} ||= [];
142 my %p = ( name => $pkg, providers => [], versions => '' );
143 if (my $provided_by = $entry->{provided_by}) {
144 $p{providers} = $provided_by;
146 $p{subsection} = $p{section} = $p{archive} = $p{desc} = $p{priority} = '';
147 unless ($entry->is_virtual) {
148 (undef, $p{versions}) = $entry->get_version_string;
149 $p{subsection} = $entry->get_newest( 'subsection' );
150 $p{section} = $entry->get_newest( 'section' );
151 $p{archive} = $entry->get_newest( 'archive' );
152 $p{desc} = $entry->get_newest( 'description' );
153 $p{priority} = $entry->get_newest( 'priority' );
155 push @{$allpkgs{$key}}, \%p;
159 write_files(\%allpkgs);
161 print "collecting source package info ...\n";
163 while (my ($pkg, $data) = each %src_packages) {
165 foreach (split /\000/o, $data||'') {
166 my @data = split ( /\s/o, $_ );
167 $pkg{$data[1]} ||= new Packages::SrcPage( $pkg );
168 $pkg{$data[1]}->merge_package( { package => $pkg,
172 subsection => $data[3],
173 priority => $data[4],
178 while (my ($key, $entry) = each %pkg) {
179 $allsrcpkgs{$key} ||= [];
181 my %p = ( name => $pkg, providers => [], versions => '' );
182 $p{versions} = $entry->{version};
183 $p{subsection} = $entry->get_newest( 'subsection' );
184 $p{section} = $entry->get_newest( 'section' );
185 $p{archive} = $entry->get_newest( 'archive' );
186 $p{priority} = $entry->get_newest( 'priority' );
190 # my $binaries = find_binaries( $pkg, $p{archive}, $p{suite}, \%src2bin );
191 # if ($binaries && @$binaries) {
192 # pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
195 push @{$allsrcpkgs{$key}}, \%p;
199 write_files(\%allsrcpkgs, 1);
202 my ($pkgs, $source) = @_;
204 $source = $source ? 'source/' : '';
205 print "writing files ...\n";
206 foreach my $s (@SUITES) {
208 mkpath ( "$wwwdir/$source$key" );
209 print "writing $source$s/allpackages...\n";
210 $template->process( 'html/index.tmpl', { packages => $pkgs->{$key}, suite => $s, lang => 'en', is_source => $source },
211 "$wwwdir/$source$key/allpackages.en.html.new" )
212 or die "error writing allpackages for $key: ".$template->error();
213 print "writing $source$s/allpackages (txt)...\n";
214 my $gzfh = gzopen("$wwwdir/$source$key/allpackages.en.txt.gz.new",
216 or die "can't open text index file for output: $!";
218 $template->process( 'txt/index.tmpl', { packages => $pkgs->{$key}, suite => $s, lang => 'en', is_source => $source },
220 or die "error writing allpackages txt for $key: ".$template->error();
221 $gzfh->gzwrite($gztxt);
222 ($gzfh->gzclose == Z_OK) or
223 warn "can't close text index file $wwwdir/$source$key/allpackages.en.txt.gz.new: ".$gzfh->gzerror;
225 rename( "$wwwdir/$source$key/allpackages.en.html.new",
226 "$wwwdir/$source$key/allpackages.en.html" );
227 rename( "$wwwdir/$source$key/allpackages.en.txt.gz.new",
228 "$wwwdir/$source$key/allpackages.en.txt.gz" );
230 foreach my $sec (keys %{$sections->{$s}}) {
231 mkpath ( "$wwwdir/$source$key/$sec" );
233 print "writing $source$s/$sec/index...\n";
234 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{section} eq $sec } @{$pkgs->{$key}} ],
235 suite => $s, lang => 'en', is_source => $source,
236 category => { id => 'section', name => $sec } },
237 "$wwwdir/$source$key/$sec/index.en.html.new" )
238 or die "error writing section index for $key/$sec: ".$template->error();
239 rename( "$wwwdir/$source$key/$sec/index.en.html.new",
240 "$wwwdir/$source$key/$sec/index.en.html" );
242 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
243 next if $ssec eq '-';
244 mkpath ( "$wwwdir/$source$key/$ssec" );
246 print "writing $source$s/$ssec/index...\n";
247 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{subsection} eq $ssec } @{$pkgs->{$key}} ],
248 suite => $s, lang => 'en', is_source => $source,
249 category => { id => 'subsection', name => $ssec } },
250 "$wwwdir/$source$key/$ssec/index.en.html.new" )
251 or die "error writing subsection index for $key/$ssec: ".$template->error();
252 rename( "$wwwdir/$source$key/$ssec/index.en.html.new",
253 "$wwwdir/$source$key/$ssec/index.en.html" );
255 foreach my $prio (keys %{$priorities->{$s}}) {
256 next if $prio eq '-';
257 mkpath ( "$wwwdir/$source$key/$prio" );
259 print "writing $source$s/$prio/index...\n";
260 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{priority} eq $prio } @{$pkgs->{$key}} ],
261 suite => $s, lang => 'en', is_source => $source,
262 category => { id => 'priority', name => $prio } },
263 "$wwwdir/$source$key/$prio/index.en.html.new" )
264 or die "error writing priority index for $key/$prio: ".$template->error();
265 rename( "$wwwdir/$source$key/$prio/index.en.html.new",
266 "$wwwdir/$source$key/$prio/index.en.html" );