16 use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES @LANGUAGES );
17 use Packages::Template;
18 use Packages::I18N::Locale;
20 use Packages::SrcPage;
21 use Packages::Sections;
22 &Packages::Config::init( './' );
23 &Packages::I18N::Locale::load( "$TOPDIR/po" );
25 my $wwwdir = "$TOPDIR/www";
27 tie my %packages, 'DB_File', "$DBDIR/packages_small.db",
28 O_RDONLY, 0666, $DB_BTREE
29 or die "couldn't tie DB $DBDIR/packages_small.db: $!";
30 tie my %src_packages, 'DB_File', "$DBDIR/sources_small.db",
31 O_RDONLY, 0666, $DB_BTREE
32 or die "couldn't tie DB $DBDIR/sources_small.db: $!";
33 tie my %src2bin, 'DB_File', "$DBDIR/sources_packages.db",
34 O_RDONLY, 0666, $DB_BTREE
35 or die "couldn't open $DBDIR/sources_packages.db: $!";
36 tie my %desctrans, 'DB_File', "$DBDIR/descriptions_translated.db",
37 O_RDONLY, 0666, $DB_BTREE
38 or die "couldn't tie DB $DBDIR/descriptions_translated.db: $!";
40 my $sections = retrieve "$DBDIR/sections.info";
41 my $subsections = retrieve "$DBDIR/subsections.info";
42 my $priorities = retrieve "$DBDIR/priorities.info";
45 #print STDERR Dumper($sections, $subsections, $priorities);
49 my $template = new Packages::Template( "$TOPDIR/templates", 'html');
50 my $txt_template = new Packages::Template( "$TOPDIR/templates", 'txt');
52 print "write suite index files ...\n";
53 foreach my $s (@SUITES) {
55 mkpath ( "$wwwdir/$key" );
56 mkpath ( "$wwwdir/source/$key" );
57 foreach my $lang (@LANGUAGES) {
58 my $charset = 'UTF-8';
59 my $cat = Packages::I18N::Locale->get_handle($lang)
60 or die "get_handle failed for $lang";
61 print "writing $key/index (lang=$lang)...\n";
63 my %content = ( subsections => [], suite => $s,
64 lang => $lang, charset => $charset, cat => $cat,
65 used_langs => \@LANGUAGES, suites => \@SUITES );
66 foreach my $ssec (sort (keys %{$subsections->{$s}}, 'virtual')) {
68 if ($sections_descs{$ssec}) {
69 push @{$content{subsections}}, {
71 name => $cat->g($sections_descs{$ssec}[0]),
72 desc => $cat->g($sections_descs{$ssec}[1]),
77 $template->page( 'suite_index', \%content,
78 "$wwwdir/$key/index.$lang.html.new");
79 rename( "$wwwdir/$key/index.$lang.html.new",
80 "$wwwdir/$key/index.$lang.html" );
82 $content{source} = 'source';
83 $template->page( 'suite_index', \%content,
84 "$wwwdir/source/$key/index.$lang.html.new");
85 rename( "$wwwdir/source/$key/index.$lang.html.new",
86 "$wwwdir/source/$key/index.$lang.html" );
91 print "collecting package info ...\n";
93 while (my ($pkg, $data) = each %packages) {
95 my ($virt, $p_data) = split /\000/o, $data, 2;
96 %virt = split /\01/o, $virt;
97 foreach (split /\000/o, $p_data||'') {
98 my @data = split ( /\s/o, $_, 9 );
99 $pkg{$data[1]} ||= new Packages::Page( $pkg );
100 $pkg{$data[1]}->merge_package( { package => $pkg,
103 architecture => $data[2],
105 subsection => $data[4],
106 priority => $data[5],
108 'description-md5' => $data[7],
109 description => $data[8] } );
111 foreach (keys %virt) {
113 $pkg{$_} ||= new Packages::Page( $pkg );
114 $pkg{$_}->add_provided_by([split /\s+/, $virt{$_}]);
117 while (my ($key, $entry) = each %pkg) {
118 $allpkgs{$key} ||= [];
120 my %p = ( name => $pkg, providers => [], versions => '' );
121 if (my $provided_by = $entry->{provided_by}) {
122 $p{providers} = $provided_by;
124 $p{subsection} = $p{section} = $p{archive} = $p{desc} = $p{priority} = '';
125 unless ($entry->is_virtual) {
126 (undef, $p{versions}) = $entry->get_version_string;
127 $p{subsection} = $entry->get_newest( 'subsection' );
128 $p{section} = $entry->get_newest( 'section' );
129 $p{archive} = $entry->get_newest( 'archive' );
130 $p{desc} = $entry->get_newest( 'description' );
131 my $desc_md5 = $entry->get_newest( 'description-md5' );
132 my $trans_desc = $desctrans{$desc_md5};
135 my %trans_desc = split /\000|\001/, $trans_desc;
136 while (my ($l, $d) = each %trans_desc) {
141 $p{trans_desc} = \%sdescs;
143 $p{priority} = $entry->get_newest( 'priority' );
145 push @{$allpkgs{$key}}, \%p;
149 write_files(\%allpkgs);
151 print "collecting source package info ...\n";
153 while (my ($pkg, $data) = each %src_packages) {
155 foreach (split /\000/o, $data||'') {
156 my @data = split ( /\s/o, $_ );
157 $pkg{$data[1]} ||= new Packages::SrcPage( $pkg );
158 $pkg{$data[1]}->merge_package( { package => $pkg,
162 subsection => $data[3],
163 priority => $data[4],
168 while (my ($key, $entry) = each %pkg) {
169 $allsrcpkgs{$key} ||= [];
171 my %p = ( name => $pkg, providers => [], versions => '' );
172 $p{versions} = $entry->{version};
173 $p{subsection} = $entry->get_newest( 'subsection' );
174 $p{section} = $entry->get_newest( 'section' );
175 $p{archive} = $entry->get_newest( 'archive' );
176 $p{priority} = $entry->get_newest( 'priority' );
180 # my $binaries = find_binaries( $pkg, $p{archive}, $p{suite}, \%src2bin );
181 # if ($binaries && @$binaries) {
182 # pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
185 push @{$allsrcpkgs{$key}}, \%p;
189 write_files(\%allsrcpkgs, 1);
192 my ($pkgs, $source) = @_;
194 $source = $source ? 'source/' : '';
195 print "writing files ...\n";
196 foreach my $s (@SUITES) {
198 mkpath ( "$wwwdir/$source$key" );
199 foreach my $lang (@LANGUAGES) {
200 my $charset = 'UTF-8';
201 my $cat = Packages::I18N::Locale->get_handle($lang)
202 or die "get_handle failed for $lang";
204 my %lang_vars = ( lang => $lang, charset => $charset,
205 cat => $cat, used_langs => \@LANGUAGES );
206 print "writing $source$s/allpackages (lang=$lang)...\n";
207 $template->page( 'index', { %lang_vars, packages => $pkgs->{$key},
208 suite => $s, is_source => $source },
209 "$wwwdir/$source$key/allpackages.$lang.html.new" );
210 print "writing $source$s/allpackages (txt,lang=$lang)...\n";
211 my $gzfh = gzopen("$wwwdir/$source$key/allpackages.$lang.txt.gz.new",
213 or die "can't open text index file for output: $!";
215 $gztxt = $txt_template->page( 'index', { %lang_vars, packages => $pkgs->{$key},
216 suite => $s, is_source => $source },
218 $gzfh->gzwrite($gztxt);
219 ($gzfh->gzclose == Z_OK) or
220 warn "can't close text index file $wwwdir/$source$key/allpackages.$lang.txt.gz.new: ".$gzfh->gzerror;
222 rename( "$wwwdir/$source$key/allpackages.$lang.html.new",
223 "$wwwdir/$source$key/allpackages.$lang.html" );
224 rename( "$wwwdir/$source$key/allpackages.$lang.txt.gz.new",
225 "$wwwdir/$source$key/allpackages.$lang.txt.gz" );
227 foreach my $sec (keys %{$sections->{$s}}) {
228 mkpath ( "$wwwdir/$source$key/$sec" );
230 print "writing $source$s/$sec/index (lang=$lang)...\n";
231 $template->page( 'index', { packages => [ grep { $_->{section} eq $sec } @{$pkgs->{$key}} ],
232 %lang_vars, suite => $s, is_source => $source,
233 category => { id => $cat->g('Section'), name => $sec } },
234 "$wwwdir/$source$key/$sec/index.$lang.html.new" );
235 rename( "$wwwdir/$source$key/$sec/index.$lang.html.new",
236 "$wwwdir/$source$key/$sec/index.$lang.html" );
238 foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
239 next if $ssec eq '-';
240 mkpath ( "$wwwdir/$source$key/$ssec" );
242 print "writing $source$s/$ssec/index (lang=$lang)...\n";
243 $template->page( 'index', { packages => [ grep { $_->{subsection} eq $ssec } @{$pkgs->{$key}} ],
244 %lang_vars, suite => $s, is_source => $source,
245 category => { id => $cat->g('Subsection'), name => $ssec } },
246 "$wwwdir/$source$key/$ssec/index.$lang.html.new" );
247 rename( "$wwwdir/$source$key/$ssec/index.$lang.html.new",
248 "$wwwdir/$source$key/$ssec/index.$lang.html" );
250 foreach my $prio (keys %{$priorities->{$s}}) {
251 next if $prio eq '-';
252 mkpath ( "$wwwdir/$source$key/$prio" );
254 print "writing $source$s/$prio/index (lang=$lang)...\n";
255 $template->page( 'index', { packages => [ grep { $_->{priority} eq $prio } @{$pkgs->{$key}} ],
256 %lang_vars, suite => $s, is_source => $source,
257 category => { id => $cat->g('Priority'), name => $prio } },
258 "$wwwdir/$source$key/$prio/index.$lang.html.new" );
259 rename( "$wwwdir/$source$key/$prio/index.$lang.html.new",
260 "$wwwdir/$source$key/$prio/index.$lang.html" );