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 #FIXME: should be $main_archive or similar, not hardcoded "us"
115 $src_data = $sources_all{"us $suite $source"} unless $src_data;
116 $page->add_src_data( $source, $src_data )
119 my $st1 = new Benchmark;
120 my $std = timediff($st1, $st0);
121 debug( "Data search and merging took ".timestr($std) ) if DEBUG;
123 my $did = $page->get_newest( 'description' );
124 my @complete_tags = split(/, /, $page->get_newest( 'tag' ));
126 foreach (@complete_tags) {
127 my ($facet, $tag) = split( /::/, $_, 2);
128 # handle tags like devel::{lang:c,lang:c++}
129 if ($tag =~ s/^\{(.+)\}$/$1/) {
130 foreach (split( /,/, $tag )) {
131 next if $tag =~ /^special:/;
132 push @tags, [ $facet, $_ ];
135 next if $tag =~ /^special:/;
136 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 my $desc = $descriptions{$did};
157 $short_desc = encode_entities( $1, "<>&\"" )
158 if $desc =~ s/^(.*)$//m;
159 my $long_desc = encode_entities( $desc, "<>&\"" );
161 $long_desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
162 $long_desc =~ s/\A //o;
163 $long_desc =~ s/\n /\n/sgo;
164 $long_desc =~ s/\n.\n/\n<p>\n/go;
165 $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$1\n<\/pre>/sgo;
167 $contents{desc} = { short => $short_desc,
168 long => $long_desc, };
170 my $v_str = $version;
171 my $multiple_versions = grep { $_ ne $version } values %$versions;
172 $v_str .= _g(" and others") if $multiple_versions;
173 $contents{versions} = { short => $v_str,
174 multiple => $multiple_versions };
176 my $provided_by = $page->{provided_by};
177 $contents{providers} = [];
178 pkg_list( \%packages, $opts, $provided_by, 'en', $contents{providers} ) if $provided_by;
181 # display dependencies
183 build_deps( \%packages, $opts, $pkg,
184 $page->get_dep_field('pre-depends'),
185 'depends', \%contents );
186 build_deps( \%packages, $opts, $pkg,
187 $page->get_dep_field('depends'),
188 'depends', \%contents );
189 build_deps( \%packages, $opts, $pkg,
190 $page->get_dep_field('recommends'),
191 'recommends', \%contents );
192 build_deps( \%packages, $opts, $pkg,
193 $page->get_dep_field('suggests'),
194 'suggests', \%contents );
200 foreach my $a ( @archs ) {
201 my %d = ( arch => $a,
202 pkgsize => sprintf( '%.1f', floor(($sizes_deb->{$a}/102.4)+0.5)/10 ),
203 instsize => $sizes_inst->{$a}, );
205 $d{version} = $versions->{$a} if $multiple_versions;
206 $d{archive} = $archives->{$a};
207 if ( ($suite ne "experimental")
208 && ($subsection ne 'debian-installer')) {
209 $d{contents_avail} = 1;
211 push @downloads, \%d;
213 $contents{downloads} = \@downloads;
218 moreinfo( name => $pkg, data => $page, vars => \%contents,
221 bugreports => 1, sourcedownload => 1,
222 changesandcopy => 1, maintainers => 1,
224 } else { # unless $page->is_virtual
225 $contents{is_virtual} = 1;
226 $contents{desc}{short} = _g( "virtual package" );
227 $contents{subsection} = 'virtual';
229 my $provided_by = $page->{provided_by};
230 $contents{providers} = [];
231 pkg_list( \%packages, $opts, $provided_by, 'en', $contents{providers} );
233 } # else (unless $page->is_virtual)
234 } else { # unless $opts->{source}
235 $contents{is_source} = 1;
237 for my $entry (@results) {
238 debug( join(":", @$entry), 1 ) if DEBUG;
239 my (undef, $archive, undef, $section, $subsection,
240 $priority, $version) = @$entry;
242 my $data = $sources_all{"$archive $suite $pkg"};
243 $page->merge_data($pkg, $suite, $archive, $data)
244 or debug( "Merging $pkg $version FAILED", 2 ) if DEBUG;
246 $version = $page->{version};
247 $contents{version} = $version;
249 my $st1 = new Benchmark;
250 my $std = timediff($st1, $st0);
251 debug( "Data search and merging took ".timestr($std) ) if DEBUG;
253 $archive = $page->get_newest( 'archive' );
254 $contents{archive} = $archive;
255 $section = $page->get_newest( 'section' );
256 $contents{section} = $section;
257 $subsection = $page->get_newest( 'subsection' );
258 $contents{subsection} = $subsection;
260 my $binaries = find_binaries( $pkg, $archive, $suite, \%src2bin );
261 if ($binaries && @$binaries) {
262 $contents{binaries} = [];
263 pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
267 # display dependencies
269 build_deps( \%packages, $opts, $pkg,
270 $page->get_dep_field('build-depends'),
271 'build-depends', \%contents );
272 build_deps( \%packages, $opts, $pkg,
273 $page->get_dep_field('build-depends-indep'),
274 'build-depends-indep', \%contents );
277 # Source package download
279 my $source_files = $page->get_src( 'files' );
280 my $source_dir = $page->get_src( 'directory' );
282 $contents{srcfiles} = [];
283 foreach( @$source_files ) {
284 my ($src_file_md5, $src_file_size, $src_file_name)
286 (my $server = lc $archive) =~ s/-//go; # non-US hack
287 $server = $FTP_SITES{$server}
289 my $path = "/$source_dir/$src_file_name";
291 push @{$contents{srcfiles}}, { server => $server, path => $path, filename => $src_file_name,
292 size => sprintf("%.1f", (floor(($src_file_size/102.4)+0.5)/10)),
293 md5sum => $src_file_md5 };
299 moreinfo( name => $pkg, data => $page, vars => \%contents,
303 changesandcopy => 1, maintainers => 1,
304 search => 1, is_source => 1 );
306 } # else (unless $opts->{source})
307 } # else (unless @results)
308 } # else (unless (@results || @non_results ))
312 # debug( "Final page object:\n".Dumper(\%contents), 3 ) if DEBUG;
314 %$page_contents = %contents;
320 my $name = $info{name} or return;
321 my $env = $info{env} or return;
322 my $opts = $info{opts} or return;
323 my $page = $info{data} or return;
324 my $contents = $info{vars} or return;
325 my $is_source = $info{is_source};
326 my $suite = $opts->{suite}[0];
328 my $source = $page->get_src( 'package' );
329 my $source_version = $page->get_src( 'version' );
330 my $src_dir = $page->get_src('directory');
331 if ($info{sourcedownload}) {
332 $contents->{src}{url} = make_url($source,'',{source=>'source'});
333 $contents->{src}{pkg} = $source;
336 my $files = $page->get_src( 'files' );
337 if (defined($files) and @$files) {
339 my ($src_file_md5, $src_file_size, $src_file_name) = split /\s/o, $_;
342 ($server = lc $page->get_newest('archive')) =~ s/-//go;
343 $server = $env->{$server}||$env->{us};
344 $path = "/$src_dir/$src_file_name";
345 push @downloads, { name => $src_file_name, server => $server, path => $path };
348 $contents->{src}{downloads} = \@downloads;
351 if ($info{changesandcopy}) {
353 (my $src_basename = $source_version) =~ s,^\d+:,,; # strip epoche
354 $src_basename = "${source}_$src_basename";
355 $src_dir =~ s,pool/updates,pool,o;
356 $src_dir =~ s,pool/non-US,pool,o;
358 $contents->{files}{changelog}{path} = "$src_dir/$src_basename/changelog";
359 $contents->{files}{copyright}{path} = "$src_dir/$src_basename/".( $is_source ? 'copyright' : "$name.copyright" );
363 if ($info{maintainers}) {
364 my $uploaders = $page->get_src( 'uploaders' );
365 if ($uploaders && @$uploaders) {
366 my @maintainers = map { { name => $_->[0], mail => $_->[1] } } @$uploaders;
367 $contents->{maintainers} = \@maintainers;
374 my ($suite, $entry, $also) = @_;
375 my %tmp = map { $_ => 1 } split /\s/, $entry;
376 my @provided_by = keys %tmp; # weed out duplicates
377 my %out = ( also => $also,
378 pkgs => \@provided_by );
383 my ( $packages, $opts, $pkg, $relations, $type, $contents) = @_;
384 my %dep_type = ('depends' => 'dep', 'recommends' => 'rec',
385 'suggests' => 'sug', 'build-depends' => 'adep',
386 'build-depends-indep' => 'idep' );
387 my $suite = $opts->{suite}[0];
389 my %out = ( id => $dep_type{$type}, terms => [] );
392 # debug( "print_deps called:\n".Dumper( $pkg, $relations, \$type ), 3 ) if DEBUG;
394 foreach my $rel (@$relations) {
396 $rel_out{is_old_pkgs} = $rel->[0];
397 $rel_out{alternatives} = [];
399 foreach my $rel_alt ( @$rel ) {
400 next unless ref($rel_alt);
401 my ( $p_name, $pkg_version, $arch_neg,
402 $arch_str, $subsection, $available ) = @$rel_alt;
404 if ($arch_str ||= '') {
406 $arch_str = _g("not")." $arch_str";
408 $arch_str = $arch_str;
412 my %rel_alt_out = ( name => $p_name,
413 version => $pkg_version,
414 arch_str => $arch_str,
415 arch_neg => $arch_neg );
419 my $entry = $entries{$p_name} ||
420 read_entry_simple( $packages, $p_name, $opts->{h_archives}, $suite);
421 my $short_desc = $entry->[-1];
422 my $arch = $entry->[3];
423 my $archive = $entry->[1];
424 my $p_suite = $entry->[2];
426 $rel_alt_out{desc} = $short_desc;
427 $rel_alt_out{suite} = $p_suite;
428 if ( $rel_out{is_old_pkgs} ) {
429 } elsif (defined $entry->[1]) {
430 $entries{$p_name} ||= $entry;
431 $rel_alt_out{providers} = providers( $p_suite,
433 1 ) if defined $entry->[0];
434 } elsif (defined $entry->[0]) {
435 $rel_alt_out{desc} = undef;
436 $rel_alt_out{providers} = providers( $p_suite,
438 #FIXME: we don't handle virtual packages from
439 # the fallback suite correctly here
440 $rel_alt_out{suite} = $suite;
442 } elsif ( $rel_out{is_old_pkgs} ) {
444 $rel_alt_out{desc} = _g( "Package not available" );
445 $rel_alt_out{suite} = '';
447 push @{$rel_out{alternatives}}, \%rel_alt_out;
450 push @{$out{terms}}, \%rel_out;
453 $contents->{relations} ||= [];
454 push @{$contents->{relations}}, \%out if @{$out{terms}};
458 my ( $packages, $opts, $pkgs, $lang, $list ) = @_;
459 my $suite = $opts->{suite}[0];
461 foreach my $p ( sort @$pkgs ) {
463 # we don't deal with virtual packages here because for the
464 # current uses of this function this isn't needed
465 my $short_desc = (read_entry_simple( $packages, $p, $opts->{h_archives}, $suite))->[-1];
468 push @$list, { name => $p, desc => $short_desc, available => 1 };
470 push @$list, { name => $p, desc => _g("Not available") };