1 package Packages::DoShow;
10 use Benchmark ':hireswallclock';
14 use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @SECTIONS
15 @ARCHITECTURES %FTP_SITES
16 @LANGUAGES @DDTP_LANGUAGES);
17 use Packages::CGI qw( :DEFAULT make_url make_search_url );
19 use Packages::Search qw( :all );
20 use Packages::Page ();
21 use Packages::SrcPage ();
23 our @ISA = qw( Exporter );
24 our @EXPORT = qw( do_show );
27 my ($params, $opts, $page_contents) = @_;
28 my $cat = $opts->{cat};
30 if ($params->{errors}{package}) {
31 fatal_error( $cat->g( "package not valid or not specified" ) );
33 if ($params->{errors}{suite}) {
34 fatal_error( $cat->g( "suite not valid or not specified" ) );
36 if (@{$opts->{suite}} > 1) {
37 fatal_error( $cat->g( "more than one suite specified for show (%s)",
38 "@{$opts->{suite}}" ) );
42 $contents{make_url} = sub { return &Packages::CGI::make_url(@_) };
44 my $pkg = $opts->{package};
45 $contents{pkg} = $pkg;
46 my $suite = $opts->{suite}[0];
47 $contents{suite} = $suite;
48 my $archive = $opts->{archive}[0] ||'';
50 our (%packages_all, %sources_all);
51 my (@results, @non_results);
52 my $page = $opts->{source} ?
53 new Packages::SrcPage( $pkg ) :
54 new Packages::Page( $pkg );
55 my ($short_desc, $version, $section, $subsection) = ("")x5;
57 my $st0 = new Benchmark;
58 unless (@Packages::CGI::fatal_errors) {
59 tie %packages_all, 'DB_File', "$DBDIR/packages_all_$suite.db",
60 O_RDONLY, 0666, $DB_BTREE
61 or die "couldn't tie DB $DBDIR/packages_all_$suite.db: $!";
62 tie %sources_all, 'DB_File', "$DBDIR/sources_all_$suite.db",
63 O_RDONLY, 0666, $DB_BTREE
64 or die "couldn't tie DB $DBDIR/sources_all_$suite.db: $!";
66 unless ($opts->{source}) {
67 read_entry_all( \%packages, $pkg, \@results, \@non_results, $opts );
69 read_src_entry_all( \%sources, $pkg, \@results, \@non_results, $opts );
72 unless (@results || @non_results ) {
73 fatal_error( $cat->g( "No such package.") );
74 #sprintf( _g( '<a href="%s">Search for the package</a>' ), make_search_url('','keywords='.uri_escape($pkg)) ) );
77 foreach (@results, @non_results) {
82 $contents{suites} = [ suites_sort(keys %all_suites) ];
85 fatal_error( $cat->g( "Package not available in this suite." ) );
87 $contents{page} = $page;
88 unless ($opts->{source}) {
90 for my $entry (@results) {
91 debug( join(":", @$entry), 1 ) if DEBUG;
92 my (undef, $archive, undef, $arch, $section, $subsection,
93 $priority, $version, undef, $provided_by) = @$entry;
95 if ($arch ne 'virtual') {
96 my %data = split /\000/, $packages_all{"$pkg $arch $version"};
97 $data{package} = $pkg;
98 $data{architecture} = $arch;
99 $data{version} = $version;
100 $page->merge_package(\%data)
101 or debug( "Merging $pkg $arch $version FAILED", 2 ) if DEBUG;
103 $page->add_provided_by([split /\s+/, $provided_by]);
107 unless ($page->is_virtual()) {
108 $version = $page->{newest};
109 $contents{version} = $version;
110 my $source = $page->get_newest( 'source' );
111 $archive = $page->get_newest( 'archive' );
112 $contents{archive} = $archive;
114 debug( "find source package: source=$source", 1) if DEBUG;
115 my $src_data = $sources_all{"$archive $suite $source"};
116 #FIXME: should be $main_archive or similar, not hardcoded "us"
117 $src_data = $sources_all{"us $suite $source"} unless $src_data;
118 $page->add_src_data( $source, $src_data )
121 my $st1 = new Benchmark;
122 my $std = timediff($st1, $st0);
123 debug( "Data search and merging took ".timestr($std) ) if DEBUG;
125 my @similar = find_similar( $pkg, "$DBDIR/xapian/",
127 $contents{similar} = \@similar;
129 my $did = $page->get_newest( 'description' );
130 my $desc_md5 = $page->get_newest( 'description-md5' );
131 my @complete_tags = split(/, /, $page->get_newest( 'tag' )||'' );
133 foreach (@complete_tags) {
134 my ($facet, $tag) = split( /::/, $_, 2);
135 next if $facet =~ /^special/;
136 next if $tag =~ /^special:/;
137 push @tags, [ $facet, $tag ];
140 $contents{tags} = \@tags;
141 $contents{debtags_voc} = \%debtags;
143 $section = $page->get_newest( 'section' );
144 $contents{section} = $section;
145 $subsection = $page->get_newest( 'subsection' );
146 $contents{subsection} = $subsection;
148 my $archives = $page->get_arch_field( 'archive' );
149 my $versions = $page->get_arch_field( 'version' );
150 my $sizes_inst = $page->get_arch_field( 'installed-size' );
151 my $sizes_deb = $page->get_arch_field( 'size' );
152 my @archs = sort $page->get_architectures;
154 # process description
156 sub process_description {
159 my $short_desc = encode_entities( $1, "<>&\"" )
160 if $desc =~ s/^(.*)$//m;
161 my $long_desc = encode_entities( $desc, "<>&\"" );
163 $long_desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
164 $long_desc =~ s/\A //o;
165 $long_desc =~ s/\n /\n/sgo;
166 $long_desc =~ s/\n.\n/\n<p>\n/go;
167 $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$1\n<\/pre>/sgo;
169 return ($short_desc, $long_desc);
172 my $desc = $descriptions{$did};
174 ($short_desc, $long_desc) = process_description($desc);
176 $contents{desc}{en} = { short => $short_desc,
177 long => $long_desc, };
179 debug( "desc_md5=$desc_md5", 2)
181 my $trans_desc = $desctrans{$desc_md5};
183 my %trans_desc = split /\000|\001/, $trans_desc;
184 my %all_langs = map { $_ => 1 } (@LANGUAGES, keys %trans_desc);
185 $contents{used_langs} = [ keys %all_langs ];
186 debug( "TRANSLATIONS: ".join(" ",keys %trans_desc), 2)
188 while (my ($l, $d) = each %trans_desc) {
189 my ($short_t, $long_t) = process_description($d);
191 $contents{desc}{$l} = { short => $short_t,
196 my $v_str = $version;
197 my $multiple_versions = grep { $_ ne $version } values %$versions;
198 $v_str .= $cat->g(" and others") if $multiple_versions;
199 $contents{versions} = { short => $v_str,
200 multiple => $multiple_versions };
202 my $provided_by = $page->{provided_by};
203 $contents{providers} = [];
204 pkg_list( \%packages, $opts, $provided_by, $contents{providers} ) if $provided_by;
207 # display dependencies
209 build_deps( \%packages, $opts, $pkg,
210 $page->get_dep_field('pre-depends'),
211 'depends', \%contents );
212 build_deps( \%packages, $opts, $pkg,
213 $page->get_dep_field('depends'),
214 'depends', \%contents );
215 build_deps( \%packages, $opts, $pkg,
216 $page->get_dep_field('recommends'),
217 'recommends', \%contents );
218 build_deps( \%packages, $opts, $pkg,
219 $page->get_dep_field('suggests'),
220 'suggests', \%contents );
226 foreach my $a ( @archs ) {
227 my %d = ( arch => $a,
228 pkgsize => floor(($sizes_deb->{$a}/102.4)+0.5)/10,
229 instsize => $sizes_inst->{$a}, );
231 $d{version} = $versions->{$a} if $multiple_versions;
232 $d{archive} = $archives->{$a};
233 if ( ($suite ne "woody") && ($suite ne "bo")
234 && ($subsection ne 'debian-installer')) {
235 $d{contents_avail} = 1;
237 push @downloads, \%d;
239 $contents{downloads} = \@downloads;
244 moreinfo( name => $pkg, data => $page, vars => \%contents,
247 bugreports => 1, sourcedownload => 1,
248 changesandcopy => 0, maintainers => 1,
250 } else { # unless $page->is_virtual
251 $contents{is_virtual} = 1;
252 $contents{desc}{short} = $cat->g( "virtual package" );
253 $contents{subsection} = 'virtual';
255 my $provided_by = $page->{provided_by};
256 $contents{providers} = [];
257 pkg_list( \%packages, $opts, $provided_by, $contents{providers} );
259 } # else (unless $page->is_virtual)
260 } else { # unless $opts->{source}
261 $contents{is_source} = 1;
263 for my $entry (@results) {
264 debug( join(":", @$entry), 1 ) if DEBUG;
265 my (undef, $archive, undef, $section, $subsection,
266 $priority, $version) = @$entry;
268 my $data = $sources_all{"$archive $suite $pkg"};
269 $page->merge_data($pkg, $suite, $archive, $data)
270 or debug( "Merging $pkg $version FAILED", 2 ) if DEBUG;
272 $version = $page->{version};
273 $contents{version} = $version;
275 my $st1 = new Benchmark;
276 my $std = timediff($st1, $st0);
277 debug( "Data search and merging took ".timestr($std) ) if DEBUG;
279 $archive = $page->get_newest( 'archive' );
280 $contents{archive} = $archive;
281 $section = $page->get_newest( 'section' );
282 $contents{section} = $section;
283 $subsection = $page->get_newest( 'subsection' );
284 $contents{subsection} = $subsection;
286 my $binaries = find_binaries( $pkg, $archive, $suite, \%src2bin );
287 if ($binaries && @$binaries) {
288 $contents{binaries} = [];
289 pkg_list( \%packages, $opts, $binaries, $contents{binaries} );
293 # display dependencies
295 build_deps( \%packages, $opts, $pkg,
296 $page->get_dep_field('build-depends'),
297 'build-depends', \%contents );
298 build_deps( \%packages, $opts, $pkg,
299 $page->get_dep_field('build-depends-indep'),
300 'build-depends-indep', \%contents );
303 # Source package download
305 my $source_files = $page->get_src( 'files' );
306 my $source_dir = $page->get_src( 'directory' );
308 $contents{srcfiles} = [];
309 foreach( @$source_files ) {
310 my ($src_file_md5, $src_file_size, $src_file_name)
312 my $server = $FTP_SITES{lc $archive}
314 my $path = "/$source_dir/$src_file_name";
316 push @{$contents{srcfiles}}, { server => $server, path => $path, filename => $src_file_name,
317 size => floor(($src_file_size/102.4)+0.5)/10,
318 md5sum => $src_file_md5 };
324 moreinfo( name => $pkg, data => $page, vars => \%contents,
328 changesandcopy => 0, maintainers => 1,
329 search => 1, is_source => 1 );
331 } # else (unless $opts->{source})
332 } # else (unless @results)
333 } # else (unless (@results || @non_results ))
337 # debug( "Final page object:\n".Dumper(\%contents), 3 ) if DEBUG;
339 %$page_contents = %contents;
345 my $name = $info{name} or return;
346 my $env = $info{env} or return;
347 my $opts = $info{opts} or return;
348 my $page = $info{data} or return;
349 my $contents = $info{vars} or return;
350 my $is_source = $info{is_source};
351 my $suite = $opts->{suite}[0];
353 my $source = $page->get_src( 'package' );
354 my $source_version = $page->get_src( 'version' );
355 my $src_dir = $page->get_src('directory');
356 if ($info{sourcedownload}) {
357 $contents->{src}{url} = make_url($source,'',{source=>'source'});
358 $contents->{src}{pkg} = $source;
361 my $files = $page->get_src( 'files' );
362 if (defined($files) and @$files) {
364 my ($src_file_md5, $src_file_size, $src_file_name) = split /\s/o, $_;
366 $server = $env->{lc $page->get_newest('archive')}||$env->{us};
367 $path = "/$src_dir/$src_file_name";
368 push @downloads, { name => $src_file_name, server => $server, path => $path };
371 $contents->{src}{downloads} = \@downloads;
374 if ($info{changesandcopy}) {
376 (my $src_basename = $source_version) =~ s,^\d+:,,; # strip epoche
377 $src_basename = "${source}_$src_basename";
378 $src_dir =~ s,pool/updates,pool,o;
380 $contents->{files}{changelog}{path} = "$src_dir/$src_basename/changelog";
381 $contents->{files}{copyright}{path} = "$src_dir/$src_basename/".( $is_source ? 'copyright' : "$name.copyright" );
385 if ($info{maintainers}) {
386 my $uploaders = $page->get_src( 'uploaders' );
387 if ($uploaders && @$uploaders) {
388 my @maintainers = map { { name => $_->[0], mail => $_->[1] } } @$uploaders;
389 $contents->{maintainers} = \@maintainers;
396 my ($suite, $entry, $also) = @_;
397 my %tmp = map { $_ => 1 } split /\s/, $entry;
398 my @provided_by = keys %tmp; # weed out duplicates
399 my %out = ( also => $also,
400 pkgs => \@provided_by );
405 my ( $packages, $opts, $pkg, $relations, $type, $contents) = @_;
406 my %dep_type = ('depends' => 'dep', 'recommends' => 'rec',
407 'suggests' => 'sug', 'build-depends' => 'adep',
408 'build-depends-indep' => 'idep' );
409 my $suite = $opts->{suite}[0];
410 my $cat = $opts->{cat};
412 my %out = ( id => $dep_type{$type}, terms => [] );
415 # debug( "print_deps called:\n".Dumper( $pkg, $relations, \$type ), 3 ) if DEBUG;
417 foreach my $rel (@$relations) {
419 $rel_out{is_old_pkgs} = $rel->[0];
420 $rel_out{alternatives} = [];
422 foreach my $rel_alt ( @$rel ) {
423 next unless ref($rel_alt);
424 my ( $p_name, $pkg_version, $arch_neg,
425 $arch_str, $subsection, $available ) = @$rel_alt;
427 if ($arch_str ||= '') {
429 $arch_str = $cat->g("not %s", "$arch_str" );
431 $arch_str = $arch_str;
435 my %rel_alt_out = ( name => $p_name,
436 version => $pkg_version,
437 arch_str => $arch_str,
438 arch_neg => $arch_neg );
442 my $entry = $entries{$p_name} ||
443 read_entry_simple( $packages, $p_name, $opts->{h_archives}, $suite);
444 my $short_desc = $entry->[-1];
445 my $desc_md5 = $entry->[-2] || '';
446 my $arch = $entry->[3];
447 my $archive = $entry->[1];
448 my $p_suite = $entry->[2];
450 $rel_alt_out{desc} = $short_desc;
451 my $trans_desc = $desctrans{$desc_md5};
453 my %trans_desc = split /\000|\001/, $trans_desc;
455 while (my ($l, $d) = each %trans_desc) {
460 $rel_alt_out{trans_desc} = \%sdescs;
462 $rel_alt_out{suite} = $p_suite;
463 if ( $rel_out{is_old_pkgs} ) {
464 } elsif (defined $entry->[1]) {
465 $entries{$p_name} ||= $entry;
466 $rel_alt_out{providers} = providers( $p_suite,
468 1 ) if defined $entry->[0];
469 } elsif (defined $entry->[0]) {
470 $rel_alt_out{desc} = undef;
471 $rel_alt_out{providers} = providers( $p_suite,
473 #FIXME: we don't handle virtual packages from
474 # the fallback suite correctly here
475 $rel_alt_out{suite} = $suite;
477 } elsif ( $rel_out{is_old_pkgs} ) {
479 $rel_alt_out{desc} = $cat->g( "Package not available" );
480 $rel_alt_out{suite} = '';
482 push @{$rel_out{alternatives}}, \%rel_alt_out;
485 push @{$out{terms}}, \%rel_out;
488 $contents->{relations} ||= [];
489 push @{$contents->{relations}}, \%out if @{$out{terms}};
493 my ( $packages, $opts, $pkgs, $list ) = @_;
494 my $suite = $opts->{suite}[0];
496 foreach my $p ( sort @$pkgs ) {
498 # we don't deal with virtual packages here because for the
499 # current uses of this function this isn't needed
500 my $data = read_entry_simple( $packages, $p, $opts->{h_archives}, $suite);
501 my ($desc_md5, $short_desc) = ($data->[-2],$data->[-1]);
504 my $trans_desc = $desctrans{$desc_md5};
507 my %trans_desc = split /\000|\001/, $trans_desc;
508 while (my ($l, $d) = each %trans_desc) {
514 push @$list, { name => $p, desc => $short_desc,
515 trans_desc => \%sdescs, available => 1 };
517 push @$list, { name => $p,
518 desc => $opts->{cat}->g("Not available") };