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 my $priorities = retrieve "$DBDIR/priorities.info";
50 #print STDERR Dumper($sections, $subsections, $priorities);
52 my (%pages, %tt_vars);
54 $tt_vars{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
55 $tt_vars{make_url} = sub { return &Packages::CGI::make_url(@_) };
56 # needed to work around the limitations of the the FILTER syntax
57 $tt_vars{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
58 $tt_vars{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
59 $tt_vars{quotemeta} = sub { return quotemeta($_[0]) };
61 my $template = new Packages::Template( "$TOPDIR/templates", 'html', \%tt_vars );
63 print "write suite index files ...\n";
64 foreach my $s (@SUITES) {
66 mkpath ( "$wwwdir/$key" );
67 mkpath ( "$wwwdir/source/$key" );
68 foreach my $lang (@LANGUAGES) {
69 my $locale = get_locale( $lang );
70 my $charset = get_charset( $lang );
71 setlocale ( LC_ALL, $locale ) or do {
72 warn "couldn't set locale ($lang/$locale)\n";
75 print "writing $key/index (lang=$lang)...\n";
77 my %content = ( subsections => [], suite => $s,
78 lang => $lang, charset => $charset,
79 used_langs => \@LANGUAGES, suites => \@SUITES );
80 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
82 if ($sections_descs{$ssec}) {
83 push @{$content{subsections}}, {
85 name => dgettext( 'sections', $sections_descs{$ssec}[0] ),
86 desc => dgettext( 'sections', $sections_descs{$ssec}[1] ),
91 open $pages{$key}{$lang}{index}{fh}, '>', "$wwwdir/$key/index.$lang.html.new"
92 or die "can't open index file for output: $!";
93 print {$pages{$key}{$lang}{index}{fh}} $template->page( 'suite_index', \%content );
94 close $pages{$key}{$lang}{index}{fh} or
95 warn "can't close index file $wwwdir/$key/index.$lang.html.new: $!";
96 rename( "$wwwdir/$key/index.$lang.html.new",
97 "$wwwdir/$key/index.$lang.html" );
99 $content{source} = 'source';
100 open $pages{$key}{$lang}{source_index}{fh}, '>', "$wwwdir/source/$key/index.$lang.html.new"
101 or die "can't open index file for output: $!";
102 print {$pages{$key}{$lang}{source_index}{fh}} $template->page( 'suite_index', \%content );
103 close $pages{$key}{$lang}{source_index}{fh} or
104 warn "can't close index file $wwwdir/source/$key/index.$lang.html.new: $!";
105 rename( "$wwwdir/source/$key/index.$lang.html.new",
106 "$wwwdir/source/$key/index.$lang.html" );
110 setlocale( LC_ALL, 'C' ) or die "couldn't reset locale";
112 print "collecting package info ...\n";
114 while (my ($pkg, $data) = each %packages) {
116 my ($virt, $p_data) = split /\000/o, $data, 2;
117 %virt = split /\01/o, $virt;
118 foreach (split /\000/o, $p_data||'') {
119 my @data = split ( /\s/o, $_, 8 );
120 $pkg{$data[1]} ||= new Packages::Page( $pkg );
121 $pkg{$data[1]}->merge_package( { package => $pkg,
124 architecture => $data[2],
126 subsection => $data[4],
127 priority => $data[5],
129 description => $data[7] } );
131 foreach (keys %virt) {
133 $pkg{$_} ||= new Packages::Page( $pkg );
134 $pkg{$_}->add_provided_by([split /\s+/, $virt{$_}]);
137 while (my ($key, $entry) = each %pkg) {
138 $allpkgs{$key} ||= [];
140 my %p = ( name => $pkg, providers => [], versions => '' );
141 if (my $provided_by = $entry->{provided_by}) {
142 $p{providers} = $provided_by;
144 $p{subsection} = $p{section} = $p{archive} = $p{desc} = $p{priority} = '';
145 unless ($entry->is_virtual) {
146 (undef, $p{versions}) = $entry->get_version_string;
147 $p{subsection} = $entry->get_newest( 'subsection' );
148 $p{section} = $entry->get_newest( 'section' );
149 $p{archive} = $entry->get_newest( 'archive' );
150 $p{desc} = $entry->get_newest( 'description' );
151 $p{priority} = $entry->get_newest( 'priority' );
153 push @{$allpkgs{$key}}, \%p;
157 write_files(\%allpkgs);
159 print "collecting source package info ...\n";
161 while (my ($pkg, $data) = each %src_packages) {
163 foreach (split /\000/o, $data||'') {
164 my @data = split ( /\s/o, $_ );
165 $pkg{$data[1]} ||= new Packages::SrcPage( $pkg );
166 $pkg{$data[1]}->merge_package( { package => $pkg,
170 subsection => $data[3],
171 priority => $data[4],
176 while (my ($key, $entry) = each %pkg) {
177 $allsrcpkgs{$key} ||= [];
179 my %p = ( name => $pkg, providers => [], versions => '' );
180 $p{versions} = $entry->{version};
181 $p{subsection} = $entry->get_newest( 'subsection' );
182 $p{section} = $entry->get_newest( 'section' );
183 $p{archive} = $entry->get_newest( 'archive' );
184 $p{priority} = $entry->get_newest( 'priority' );
188 # my $binaries = find_binaries( $pkg, $p{archive}, $p{suite}, \%src2bin );
189 # if ($binaries && @$binaries) {
190 # pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
193 push @{$allsrcpkgs{$key}}, \%p;
197 write_files(\%allsrcpkgs, 1);
200 my ($pkgs, $source) = @_;
202 $source = $source ? 'source/' : '';
203 print "writing files ...\n";
204 foreach my $s (@SUITES) {
206 mkpath ( "$wwwdir/$source$key" );
207 print "writing $source$s/allpackages...\n";
208 $template->process( 'html/index.tmpl', { packages => $pkgs->{$key}, suite => $s, lang => 'en', is_source => $source },
209 "$wwwdir/$source$key/allpackages.en.html.new" )
210 or die "error writing allpackages for $key: ".$template->error();
211 print "writing $source$s/allpackages (txt)...\n";
212 my $gzfh = gzopen("$wwwdir/$source$key/allpackages.en.txt.gz.new",
214 or die "can't open text index file for output: $!";
216 $template->process( 'txt/index.tmpl', { packages => $pkgs->{$key}, suite => $s, lang => 'en', is_source => $source },
218 or die "error writing allpackages txt for $key: ".$template->error();
219 $gzfh->gzwrite($gztxt);
220 ($gzfh->gzclose == Z_OK) or
221 warn "can't close text index file $wwwdir/$source$key/allpackages.en.txt.gz.new: ".$gzfh->gzerror;
223 rename( "$wwwdir/$source$key/allpackages.en.html.new",
224 "$wwwdir/$source$key/allpackages.en.html" );
225 rename( "$wwwdir/$source$key/allpackages.en.txt.gz.new",
226 "$wwwdir/$source$key/allpackages.en.txt.gz" );
228 foreach my $sec (keys %{$sections->{$s}}) {
229 mkpath ( "$wwwdir/$source$key/$sec" );
231 print "writing $source$s/$sec/index...\n";
232 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{section} eq $sec } @{$pkgs->{$key}} ],
233 suite => $s, lang => 'en', is_source => $source,
234 category => { id => 'section', name => $sec } },
235 "$wwwdir/$source$key/$sec/index.en.html.new" )
236 or die "error writing section index for $key/$sec: ".$template->error();
237 rename( "$wwwdir/$source$key/$sec/index.en.html.new",
238 "$wwwdir/$source$key/$sec/index.en.html" );
240 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
241 next if $ssec eq '-';
242 mkpath ( "$wwwdir/$source$key/$ssec" );
244 print "writing $source$s/$ssec/index...\n";
245 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{subsection} eq $ssec } @{$pkgs->{$key}} ],
246 suite => $s, lang => 'en', is_source => $source,
247 category => { id => 'subsection', name => $ssec } },
248 "$wwwdir/$source$key/$ssec/index.en.html.new" )
249 or die "error writing subsection index for $key/$ssec: ".$template->error();
250 rename( "$wwwdir/$source$key/$ssec/index.en.html.new",
251 "$wwwdir/$source$key/$ssec/index.en.html" );
253 foreach my $prio (keys %{$priorities->{$s}}) {
254 next if $prio eq '-';
255 mkpath ( "$wwwdir/$source$key/$prio" );
257 print "writing $source$s/$prio/index...\n";
258 $template->process( 'html/index.tmpl', { packages => [ grep { $_->{priority} eq $prio } @{$pkgs->{$key}} ],
259 suite => $s, lang => 'en', is_source => $source,
260 category => { id => 'priority', name => $prio } },
261 "$wwwdir/$source$key/$prio/index.en.html.new" )
262 or die "error writing priority index for $key/$prio: ".$template->error();
263 rename( "$wwwdir/$source$key/$prio/index.en.html.new",
264 "$wwwdir/$source$key/$prio/index.en.html" );