]> git.deb.at Git - deb/packages.git/blob - bin/create_index_pages
config.sh: disable local archive
[deb/packages.git] / bin / create_index_pages
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use POSIX;
7 use File::Path;
8 use DB_File;
9 use Storable;
10 use HTML::Entities;
11 use URI::Escape;
12 use Compress::Zlib;
13
14 use lib './lib';
15
16 use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES @LANGUAGES );
17 use Packages::Template;
18 use Packages::I18N::Locale;
19 use Packages::Page;
20 use Packages::SrcPage;
21 use Packages::Sections;
22 &Packages::Config::init( './' );
23 &Packages::I18N::Locale::load( "$TOPDIR/po" );
24
25 my $wwwdir = "$TOPDIR/www";
26
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: $!";
39
40 my $sections = retrieve "$DBDIR/sections.info";
41 my $subsections = retrieve "$DBDIR/subsections.info";
42 my $priorities = retrieve "$DBDIR/priorities.info";
43
44 #use Data::Dumper;
45 #print STDERR Dumper($sections, $subsections, $priorities);
46
47 my (%pages);
48
49 my $template = new Packages::Template( "$TOPDIR/templates", 'html');
50 my $txt_template = new Packages::Template( "$TOPDIR/templates", 'txt');
51
52 print "write suite index files ...\n";
53 foreach my $s (@SUITES) {
54     my $key = $s;
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";
62
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')) {
67             next if $ssec eq '-';
68             if ($sections_descs{$ssec}) {
69                 push @{$content{subsections}}, {
70                     id => $ssec,
71                     name => $cat->g($sections_descs{$ssec}[0]),
72                     desc => $cat->g($sections_descs{$ssec}[1]),
73                 };
74             }
75         }
76
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" );
81
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" );
87
88     }
89 }
90
91 print "collecting package info ...\n";
92 my %allpkgs;
93 while (my ($pkg, $data) = each %packages) {
94     my (%pkg,%virt);
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,
101                                          archive => $data[0],
102                                          suite => $data[1],
103                                          architecture => $data[2],
104                                          section => $data[3],
105                                          subsection => $data[4],
106                                          priority => $data[5],
107                                          version => $data[6],
108                                          'description-md5' => $data[7],
109                                          description => $data[8] } );
110     }
111     foreach (keys %virt) {
112         next if $_ eq '-';
113         $pkg{$_} ||= new Packages::Page( $pkg );
114         $pkg{$_}->add_provided_by([split /\s+/, $virt{$_}]);
115     }
116
117     while (my ($key, $entry) = each %pkg) {
118         $allpkgs{$key} ||= [];
119
120         my %p = ( name => $pkg, providers => [], versions => '' );
121         if (my $provided_by = $entry->{provided_by}) {
122             $p{providers} = $provided_by;
123         }
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};
133             if ($trans_desc) {
134                 my %sdescs;
135                 my %trans_desc = split /\000|\001/, $trans_desc;
136                 while (my ($l, $d) = each %trans_desc) {
137                     $d =~ s/\n.*//os;
138
139                     $sdescs{$l} = $d;
140                 }
141                 $p{trans_desc} = \%sdescs;
142             }
143             $p{priority} = $entry->get_newest( 'priority' );
144         }
145         push @{$allpkgs{$key}}, \%p;
146     }
147 }
148
149 write_files(\%allpkgs);
150
151 print "collecting source package info ...\n";
152 my %allsrcpkgs;
153 while (my ($pkg, $data) = each %src_packages) {
154     my %pkg;    
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,
159                                          archive => $data[0],
160                                          suite => $data[1],
161                                          section => $data[2],
162                                          subsection => $data[3],
163                                          priority => $data[4],
164                                          version => $data[5],
165                                          } );
166     }
167
168     while (my ($key, $entry) = each %pkg) {
169         $allsrcpkgs{$key} ||= [];
170
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' );
177         
178         $p{desc} = '';
179         $p{binaries} = [];
180 #       my $binaries = find_binaries( $pkg, $p{archive}, $p{suite}, \%src2bin );
181 #       if ($binaries && @$binaries) {
182 #           pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
183 #       }
184
185         push @{$allsrcpkgs{$key}}, \%p;
186     }
187 }
188
189 write_files(\%allsrcpkgs, 1);
190
191 sub write_files {
192     my ($pkgs, $source) = @_;
193
194     $source = $source ? 'source/' : '';
195     print "writing files ...\n";
196     foreach my $s (@SUITES) {
197         my $key = $s;
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";
203
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",
212                               'wb9')
213                 or die "can't open text index file for output: $!";
214             my $gztxt;
215             $gztxt = $txt_template->page( 'index', { %lang_vars, packages => $pkgs->{$key},
216                                                      suite => $s, is_source => $source  },
217                                           );
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;
221
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" );
226
227             foreach my $sec (keys %{$sections->{$s}}) {
228                 mkpath ( "$wwwdir/$source$key/$sec" );
229
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" );
237             }
238             foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) {
239                 next if $ssec eq '-';
240                 mkpath ( "$wwwdir/$source$key/$ssec" );
241
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" );
249             }
250             foreach my $prio (keys %{$priorities->{$s}}) {
251                 next if $prio eq '-';
252                 mkpath ( "$wwwdir/$source$key/$prio" );
253
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" );
261             }
262         }
263     }
264 }