1 package Packages::DoShow;
10 use Benchmark ':hireswallclock';
14 use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @SECTIONS
15 @ARCHITECTURES %FTP_SITES );
16 use Packages::I18N::Locale;
17 use Packages::CGI qw( :DEFAULT make_url make_search_url note );
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, $html_header, $page_contents) = @_;
29 if ($params->{errors}{package}) {
30 fatal_error( _g( "package not valid or not specified" ) );
32 if ($params->{errors}{suite}) {
33 fatal_error( _g( "suite not valid or not specified" ) );
35 if (@{$opts->{suite}} > 1) {
36 fatal_error( sprintf( _g( "more than one suite specified for show (%s)" ), "@{$opts->{suite}}" ) );
40 $contents{make_url} = sub { return &Packages::CGI::make_url(@_) };
42 my $pkg = $opts->{package};
43 $contents{pkg} = $pkg;
44 my $suite = $opts->{suite}[0];
45 $contents{suite} = $suite;
46 my $archive = $opts->{archive}[0] ||'';
48 our (%packages_all, %sources_all);
49 my (@results, @non_results);
50 my $page = $opts->{source} ?
51 new Packages::SrcPage( $pkg ) :
52 new Packages::Page( $pkg );
53 my ($short_desc, $version, $section, $subsection) = ("")x5;
55 my $st0 = new Benchmark;
56 unless (@Packages::CGI::fatal_errors) {
57 tie %packages_all, 'DB_File', "$DBDIR/packages_all_$suite.db",
58 O_RDONLY, 0666, $DB_BTREE
59 or die "couldn't tie DB $DBDIR/packages_all_$suite.db: $!";
60 tie %sources_all, 'DB_File', "$DBDIR/sources_all_$suite.db",
61 O_RDONLY, 0666, $DB_BTREE
62 or die "couldn't tie DB $DBDIR/sources_all_$suite.db: $!";
64 unless ($opts->{source}) {
65 read_entry_all( \%packages, $pkg, \@results, \@non_results, $opts );
67 read_src_entry_all( \%sources, $pkg, \@results, \@non_results, $opts );
70 unless (@results || @non_results ) {
71 fatal_error( _g( "No such package." )."<br>".
72 sprintf( _g( '<a href="%s">Search for the package</a>' ), make_search_url('','keywords='.uri_escape($pkg)) ) );
75 foreach (@results, @non_results) {
80 $contents{suites} = [ suites_sort(keys %all_suites) ];
83 fatal_error( _g( "Package not available in this suite." ) );
85 $contents{page} = $page;
86 unless ($opts->{source}) {
88 for my $entry (@results) {
89 debug( join(":", @$entry), 1 ) if DEBUG;
90 my (undef, $archive, undef, $arch, $section, $subsection,
91 $priority, $version, $provided_by) = @$entry;
93 if ($arch ne 'virtual') {
94 my %data = split /\000/, $packages_all{"$pkg $arch $version"};
95 $data{package} = $pkg;
96 $data{architecture} = $arch;
97 $data{version} = $version;
98 $page->merge_package(\%data)
99 or debug( "Merging $pkg $arch $version FAILED", 2 ) if DEBUG;
101 $page->add_provided_by([split /\s+/, $provided_by]);
105 unless ($page->is_virtual()) {
106 $version = $page->{newest};
107 $contents{version} = $version;
108 my $source = $page->get_newest( 'source' );
109 $archive = $page->get_newest( 'archive' );
110 $contents{archive} = $archive;
112 debug( "find source package: source=$source", 1) if DEBUG;
113 my $src_data = $sources_all{"$archive $suite $source"};
114 $page->add_src_data( $source, $src_data )
117 my $st1 = new Benchmark;
118 my $std = timediff($st1, $st0);
119 debug( "Data search and merging took ".timestr($std) ) if DEBUG;
121 my $did = $page->get_newest( 'description' );
122 my @complete_tags = split(/, /, $page->get_newest( 'tag' ));
124 foreach (@complete_tags) {
125 my ($facet, $tag) = split( /::/, $_, 2);
126 # handle tags like devel::{lang:c,lang:c++}
127 if ($tag =~ s/^\{(.+)\}$/$1/) {
128 foreach (split( /,/, $tag )) {
129 next if $tag =~ /^special:/;
130 push @tags, [ $facet, $_ ];
133 next if $tag =~ /^special:/;
134 push @tags, [ $facet, $tag ];
138 $contents{tags} = \@tags;
139 $contents{debtags_voc} = \%debtags;
141 $section = $page->get_newest( 'section' );
142 $contents{section} = $section;
143 $subsection = $page->get_newest( 'subsection' );
144 $contents{subsection} = $subsection;
146 my $archives = $page->get_arch_field( 'archive' );
147 my $versions = $page->get_arch_field( 'version' );
148 my $sizes_inst = $page->get_arch_field( 'installed-size' );
149 my $sizes_deb = $page->get_arch_field( 'size' );
150 my @archs = sort $page->get_architectures;
152 # process description
154 my $desc = $descriptions{$did};
155 $short_desc = encode_entities( $1, "<>&\"" )
156 if $desc =~ s/^(.*)$//m;
157 my $long_desc = encode_entities( $desc, "<>&\"" );
159 $long_desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
160 $long_desc =~ s/\A //o;
161 $long_desc =~ s/\n /\n/sgo;
162 $long_desc =~ s/\n.\n/\n<p>\n/go;
163 $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$1\n<\/pre>/sgo;
165 $contents{desc} = { short => $short_desc,
166 long => $long_desc, };
168 my $v_str = $version;
169 my $multiple_versions = grep { $_ ne $version } values %$versions;
170 $v_str .= _g(" and others") if $multiple_versions;
171 $contents{versions} = { short => $v_str,
172 multiple => $multiple_versions };
174 my $provided_by = $page->{provided_by};
175 $contents{providers} = [];
176 pkg_list( \%packages, $opts, $provided_by, 'en', $contents{providers} ) if $provided_by;
179 # display dependencies
181 build_deps( \%packages, $opts, $pkg,
182 $page->get_dep_field('pre-depends'),
183 'depends', \%contents );
184 build_deps( \%packages, $opts, $pkg,
185 $page->get_dep_field('depends'),
186 'depends', \%contents );
187 build_deps( \%packages, $opts, $pkg,
188 $page->get_dep_field('recommends'),
189 'recommends', \%contents );
190 build_deps( \%packages, $opts, $pkg,
191 $page->get_dep_field('suggests'),
192 'suggests', \%contents );
198 foreach my $a ( @archs ) {
199 my %d = ( arch => $a,
200 pkgsize => sprintf( '%.1f', floor(($sizes_deb->{$a}/102.4)+0.5)/10 ),
201 instsize => $sizes_inst->{$a}, );
203 $d{version} = $versions->{$a} if $multiple_versions;
204 if ( ($suite ne "experimental")
205 && ($subsection ne 'debian-installer')) {
206 $d{contents_avail} = 1;
208 push @downloads, \%d;
210 $contents{downloads} = \@downloads;
215 moreinfo( name => $pkg, data => $page, vars => \%contents,
218 bugreports => 1, sourcedownload => 1,
219 changesandcopy => 1, maintainers => 1,
221 } else { # unless $page->is_virtual
222 $contents{is_virtual} = 1;
223 $contents{desc}{short} = _g( "virtual package" );
224 $contents{subsection} = 'virtual';
226 my $provided_by = $page->{provided_by};
227 $contents{providers} = [];
228 pkg_list( \%packages, $opts, $provided_by, 'en', $contents{providers} );
230 } # else (unless $page->is_virtual)
231 } else { # unless $opts->{source}
232 $contents{is_source} = 1;
234 for my $entry (@results) {
235 debug( join(":", @$entry), 1 ) if DEBUG;
236 my (undef, $archive, undef, $section, $subsection,
237 $priority, $version) = @$entry;
239 my $data = $sources_all{"$archive $suite $pkg"};
240 $page->merge_data($pkg, $suite, $archive, $data)
241 or debug( "Merging $pkg $version FAILED", 2 ) if DEBUG;
243 $version = $page->{version};
244 $contents{version} = $version;
246 my $st1 = new Benchmark;
247 my $std = timediff($st1, $st0);
248 debug( "Data search and merging took ".timestr($std) ) if DEBUG;
250 $archive = $page->get_newest( 'archive' );
251 $contents{archive} = $archive;
252 $section = $page->get_newest( 'section' );
253 $contents{section} = $section;
254 $subsection = $page->get_newest( 'subsection' );
255 $contents{subsection} = $subsection;
257 my $binaries = find_binaries( $pkg, $archive, $suite, \%src2bin );
258 if ($binaries && @$binaries) {
259 $contents{binaries} = [];
260 pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
264 # display dependencies
266 build_deps( \%packages, $opts, $pkg,
267 $page->get_dep_field('build-depends'),
268 'build-depends', \%contents );
269 build_deps( \%packages, $opts, $pkg,
270 $page->get_dep_field('build-depends-indep'),
271 'build-depends-indep', \%contents );
274 # Source package download
276 my $source_files = $page->get_src( 'files' );
277 my $source_dir = $page->get_src( 'directory' );
279 $contents{srcfiles} = [];
280 foreach( @$source_files ) {
281 my ($src_file_md5, $src_file_size, $src_file_name)
283 (my $server = lc $archive) =~ s/-//go; # non-US hack
284 $server = $FTP_SITES{$server}
286 my $path = "/$source_dir/$src_file_name";
288 push @{$contents{srcfiles}}, { server => $server, path => $path, filename => $src_file_name,
289 size => sprintf("%.1f", (floor(($src_file_size/102.4)+0.5)/10)),
290 md5sum => $src_file_md5 };
296 moreinfo( name => $pkg, data => $page, vars => \%contents,
300 changesandcopy => 1, maintainers => 1,
301 search => 1, is_source => 1 );
303 } # else (unless $opts->{source})
304 } # else (unless @results)
305 } # else (unless (@results || @non_results ))
309 # debug( "Final page object:\n".Dumper(\%contents), 3 ) if DEBUG;
311 %$page_contents = %contents;
317 my $name = $info{name} or return;
318 my $env = $info{env} or return;
319 my $opts = $info{opts} or return;
320 my $page = $info{data} or return;
321 my $contents = $info{vars} or return;
322 my $is_source = $info{is_source};
323 my $suite = $opts->{suite}[0];
325 my $source = $page->get_src( 'package' );
326 my $source_version = $page->get_src( 'version' );
327 my $src_dir = $page->get_src('directory');
328 if ($info{sourcedownload}) {
329 $contents->{src}{url} = make_url($source,'',{source=>'source'});
330 $contents->{src}{pkg} = $source;
333 my $files = $page->get_src( 'files' );
334 if (defined($files) and @$files) {
336 my ($src_file_md5, $src_file_size, $src_file_name) = split /\s/o, $_;
337 my ($name, $server, $path);
339 ($server = lc $page->get_newest('archive')) =~ s/-//go;
340 $server = $env->{$server}||$env->{us};
341 $path = "$src_dir/$src_file_name";
342 if ($src_file_name =~ /dsc$/) {
345 $name = $src_file_name;
347 push @downloads, { name => $name, server => $server, path => $path };
350 $contents->{src}{downloads} = \@downloads;
353 if ($info{changesandcopy}) {
355 (my $src_basename = $source_version) =~ s,^\d+:,,; # strip epoche
356 $src_basename = "${source}_$src_basename";
357 $src_dir =~ s,pool/updates,pool,o;
358 $src_dir =~ s,pool/non-US,pool,o;
360 $contents->{files}{changelog}{path} = "$src_dir/$src_basename/changelog";
361 $contents->{files}{copyright}{path} = "$src_dir/$src_basename/".( $is_source ? 'copyright' : "$name.copyright" );
365 if ($info{maintainers}) {
366 my $uploaders = $page->get_src( 'uploaders' );
367 if ($uploaders && @$uploaders) {
368 my @maintainers = map { { name => $_->[0], mail => $_->[1] } } @$uploaders;
369 $contents->{maintainers} = \@maintainers;
376 my ($suite, $entry, $also) = @_;
377 my %tmp = map { $_ => 1 } split /\s/, $entry;
378 my @provided_by = keys %tmp; # weed out duplicates
379 my %out = ( also => $also,
380 pkgs => \@provided_by );
385 my ( $packages, $opts, $pkg, $relations, $type, $contents) = @_;
386 my %dep_type = ('depends' => 'dep', 'recommends' => 'rec',
387 'suggests' => 'sug', 'build-depends' => 'adep',
388 'build-depends-indep' => 'idep' );
389 my $suite = $opts->{suite}[0];
391 my %out = ( id => $dep_type{$type}, terms => [] );
394 # debug( "print_deps called:\n".Dumper( $pkg, $relations, \$type ), 3 ) if DEBUG;
396 foreach my $rel (@$relations) {
398 $rel_out{is_old_pkgs} = $rel->[0];
399 $rel_out{alternatives} = [];
401 foreach my $rel_alt ( @$rel ) {
402 next unless ref($rel_alt);
403 my ( $p_name, $pkg_version, $arch_neg,
404 $arch_str, $subsection, $available ) = @$rel_alt;
406 if ($arch_str ||= '') {
408 $arch_str = _g("not")." $arch_str";
410 $arch_str = $arch_str;
414 my %rel_alt_out = ( name => $p_name,
415 version => $pkg_version,
416 arch_str => $arch_str,
417 arch_neg => $arch_neg );
421 my $entry = $entries{$p_name} ||
422 read_entry_simple( $packages, $p_name, $opts->{h_archives}, $suite);
423 my $short_desc = $entry->[-1];
424 my $arch = $entry->[3];
425 my $archive = $entry->[1];
426 my $p_suite = $entry->[2];
428 $rel_alt_out{desc} = $short_desc;
429 $rel_alt_out{suite} = $p_suite;
430 if ( $rel_out{is_old_pkgs} ) {
431 } elsif (defined $entry->[1]) {
432 $entries{$p_name} ||= $entry;
433 $rel_alt_out{providers} = providers( $p_suite,
435 1 ) if defined $entry->[0];
436 } elsif (defined $entry->[0]) {
437 $rel_alt_out{desc} = undef;
438 $rel_alt_out{providers} = providers( $p_suite,
440 #FIXME: we don't handle virtual packages from
441 # the fallback suite correctly here
442 $rel_alt_out{suite} = $suite;
444 } elsif ( $rel_out{is_old_pkgs} ) {
446 $rel_alt_out{desc} = _g( "Package not available" );
447 $rel_alt_out{suite} = '';
449 push @{$rel_out{alternatives}}, \%rel_alt_out;
452 push @{$out{terms}}, \%rel_out;
455 $contents->{relations} ||= [];
456 push @{$contents->{relations}}, \%out if @{$out{terms}};
460 my ( $packages, $opts, $pkgs, $lang, $list ) = @_;
461 my $suite = $opts->{suite}[0];
463 foreach my $p ( sort @$pkgs ) {
465 # we don't deal with virtual packages here because for the
466 # current uses of this function this isn't needed
467 my $short_desc = (read_entry_simple( $packages, $p, $opts->{h_archives}, $suite))->[-1];
470 push @$list, { name => $p, desc => $short_desc, available => 1 };
472 push @$list, { name => $p, desc => _g("Not available") };