X-Git-Url: https://git.deb.at/?p=deb%2Fpackages.git;a=blobdiff_plain;f=lib%2FPackages%2FDoShow.pm;h=01590653cf64edcddb1d8e7f9446e26e22fa05e1;hp=6852c13a657c9033c00b913385f6d060761893f4;hb=1a21b74ad9ccf9572750caaed6d5e22cd395fa47;hpb=ab47ae363dddbc35743572c62fae6350dcb7cf96 diff --git a/lib/Packages/DoShow.pm b/lib/Packages/DoShow.pm index 6852c13..0159065 100644 --- a/lib/Packages/DoShow.pm +++ b/lib/Packages/DoShow.pm @@ -1,6 +1,7 @@ package Packages::DoShow; use strict; +use warnings; use POSIX; use URI::Escape; @@ -10,13 +11,12 @@ use Benchmark ':hireswallclock'; use Exporter; use Deb::Versions; -use Packages::Config qw( $DBDIR $ROOT @SUITES @ARCHIVES @SECTIONS - @ARCHITECTURES %FTP_SITES $SEARCH_URL ); -use Packages::I18N::Locale; -use Packages::CGI; +use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @SECTIONS + @ARCHITECTURES %FTP_SITES + @LANGUAGES @DDTP_LANGUAGES); +use Packages::CGI qw( :DEFAULT make_url make_search_url ); use Packages::DB; use Packages::Search qw( :all ); -use Packages::HTML; use Packages::Page (); use Packages::SrcPage (); @@ -24,32 +24,34 @@ our @ISA = qw( Exporter ); our @EXPORT = qw( do_show ); sub do_show { - my ($params, $opts, $html_header, $menu, $page_content) = @_; + my ($params, $opts, $page_contents) = @_; + my $cat = $opts->{cat}; if ($params->{errors}{package}) { - fatal_error( _g( "package not valid or not specified" ) ); + fatal_error( $cat->g( "package not valid or not specified" ) ); } if ($params->{errors}{suite}) { - fatal_error( _g( "suite not valid or not specified" ) ); + fatal_error( $cat->g( "suite not valid or not specified" ) ); } if (@{$opts->{suite}} > 1) { - fatal_error( sprintf( _g( "more than one suite specified for show (%s)" ), "@{$opts->{suite}}" ) ); + fatal_error( $cat->g( "more than one suite specified for show (%s)", + "@{$opts->{suite}}" ) ); } + my %contents; + $contents{make_url} = sub { return &Packages::CGI::make_url(@_) }; + my $pkg = $opts->{package}; - my $encodedpkg = uri_escape( $pkg ); + $contents{pkg} = $pkg; my $suite = $opts->{suite}[0]; + $contents{suite} = $suite; my $archive = $opts->{archive}[0] ||''; - my $DL_URL = "$pkg/download"; - my $FILELIST_URL = "$pkg/files"; - our (%packages_all, %sources_all); my (@results, @non_results); my $page = $opts->{source} ? new Packages::SrcPage( $pkg ) : new Packages::Page( $pkg ); - my $package_page = ""; my ($short_desc, $version, $section, $subsection) = ("")x5; my $st0 = new Benchmark; @@ -68,8 +70,8 @@ sub do_show { } unless (@results || @non_results ) { - fatal_error( _g( "No such package." )."
". - sprintf( _g( 'Search for the package' ), "$SEARCH_URL/$pkg" ) ); + fatal_error( $cat->g( "No such package.") ); + #sprintf( _g( 'Search for the package' ), make_search_url('','keywords='.uri_escape($pkg)) ) ); } else { my %all_suites; foreach (@results, @non_results) { @@ -77,23 +79,18 @@ sub do_show { my $s = $_->[2]; $all_suites{$s}++; } - foreach (suites_sort(keys %all_suites)) { - if ($suite eq $_) { - $$menu .= "[ $_ ] "; - } else { - $$menu .= "[ $suite})."\">$_ ] "; - } - } - $$menu .= '
'; - + $contents{suites} = [ suites_sort(keys %all_suites) ]; + unless (@results) { - fatal_error( _g( "Package not available in this suite." ) ); + fatal_error( $cat->g( "Package not available in this suite." ) ); } else { + $contents{page} = $page; unless ($opts->{source}) { + for my $entry (@results) { debug( join(":", @$entry), 1 ) if DEBUG; my (undef, $archive, undef, $arch, $section, $subsection, - $priority, $version, $provided_by) = @$entry; + $priority, $version, undef, $provided_by) = @$entry; if ($arch ne 'virtual') { my %data = split /\000/, $packages_all{"$pkg $arch $version"}; @@ -106,13 +103,18 @@ sub do_show { $page->add_provided_by([split /\s+/, $provided_by]); } } - + unless ($page->is_virtual()) { $version = $page->{newest}; + $contents{version} = $version; my $source = $page->get_newest( 'source' ); $archive = $page->get_newest( 'archive' ); + $contents{archive} = $archive; + debug( "find source package: source=$source", 1) if DEBUG; my $src_data = $sources_all{"$archive $suite $source"}; + #FIXME: should be $main_archive or similar, not hardcoded "us" + $src_data = $sources_all{"us $suite $source"} unless $src_data; $page->add_src_data( $source, $src_data ) if $src_data; @@ -120,11 +122,29 @@ sub do_show { my $std = timediff($st1, $st0); debug( "Data search and merging took ".timestr($std) ) if DEBUG; + my @similar = find_similar( $pkg, "$DBDIR/xapian/", + \%did2pkg ); + $contents{similar} = \@similar; + my $did = $page->get_newest( 'description' ); + my $desc_md5 = $page->get_newest( 'description-md5' ); + my @complete_tags = split(/, /, $page->get_newest( 'tag' )||'' ); + my @tags; + foreach (@complete_tags) { + my ($facet, $tag) = split( /::/, $_, 2); + next if $facet =~ /^special/; + next if $tag =~ /^special:/; + push @tags, [ $facet, $tag ]; + } + + $contents{tags} = \@tags; + $contents{debtags_voc} = \%debtags; + $section = $page->get_newest( 'section' ); + $contents{section} = $section; $subsection = $page->get_newest( 'subsection' ); - my $filenames = $page->get_arch_field( 'filename' ); - my $file_md5sums = $page->get_arch_field( 'md5sum' ); + $contents{subsection} = $subsection; + my $archives = $page->get_arch_field( 'archive' ); my $versions = $page->get_arch_field( 'version' ); my $sizes_inst = $page->get_arch_field( 'installed-size' ); @@ -133,318 +153,373 @@ sub do_show { # process description # + sub process_description { + my ($desc) = @_; + + my $short_desc = encode_entities( $1, "<>&\"" ) + if $desc =~ s/^(.*)$//m; + my $long_desc = encode_entities( $desc, "<>&\"" ); + + $long_desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),$1$3,go; # syntax highlighting -> ']; + $long_desc =~ s/\A //o; + $long_desc =~ s/\n /\n/sgo; + $long_desc =~ s/\n.\n/\n

\n/go; + $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n

$1\n<\/pre>/sgo;
+
+			    return ($short_desc, $long_desc);
+			}
+
 			my $desc = $descriptions{$did};
-			$short_desc = encode_entities( $1, "<>&\"" )
-			    if $desc =~ s/^(.*)$//m;
-			my $long_desc = encode_entities( $desc, "<>&\"" );
-			
-			$long_desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),$1$3,go; # syntax highlighting -> '];
-			$long_desc =~ s/\A //o;
-			$long_desc =~ s/\n /\n/sgo;
-			$long_desc =~ s/\n.\n/\n

\n/go; - $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n

$1\n<\/pre>/sgo;
-# 	    $long_desc = conv_desc( $lang, $long_desc );
-# 	    $short_desc = conv_desc( $lang, $short_desc );
-			my @menu = ( [ _g( "Distribution:" ),
-				       _g( "Overview over this suite" ),
-				       make_url("/",''),
-				       $suite ],
-				     [ _g( "Section:" ),
-				       _g( "All packages in this section" ),
-				       make_url("$subsection/",''),
-				       $subsection ], );
-			my $source = $page->get_src('package');
-			push @menu, [ _g( "Source:" ),
-				      _g( "Source package building this package" ),
-				      make_url($source,'',{source=>'source'}),
-				      $source ] if $source;
-			$$menu .= simple_menu( @menu );
+			my $long_desc;
+			($short_desc, $long_desc) = process_description($desc);
+
+			$contents{desc}{en} = { short => $short_desc,
+						long => $long_desc, };
+
+			debug( "desc_md5=$desc_md5", 2)
+			    if DEBUG;
+			my $trans_desc = $desctrans{$desc_md5};
+			if ($trans_desc) {
+			    my %trans_desc = split /\000|\001/, $trans_desc;
+			    my %all_langs = map { $_ => 1 } (@LANGUAGES, keys %trans_desc);
+			    $contents{used_langs} = [ keys %all_langs ];
+			    debug( "TRANSLATIONS: ".join(" ",keys %trans_desc), 2)
+				if DEBUG;
+			    while (my ($l, $d) = each %trans_desc) {
+				my ($short_t, $long_t) = process_description($d);
+
+				$contents{desc}{$l} = { short => $short_t,
+							long => $long_t, };
+			    }
+			}
 
 			my $v_str = $version;
 			my $multiple_versions = grep { $_ ne $version } values %$versions;
-			$v_str .= _g(" and others") if $multiple_versions;
-			my $title .= sprintf( _g( "Package: %s (%s)" ), $pkg, $v_str );
-			$title .=  " ".marker( $archive ) if $archive ne 'us';
-			$title .=  " ".marker( $subsection ) if $subsection eq 'non-US'
-			    and $archive ne 'non-US'; # non-US/security
-			$title .=  " ".marker( $section ) if $section ne 'main';
-			$package_page .= title( $title );
-			
-			if (my $provided_by = $page->{provided_by}) {
-			    note( _g( "This is also a virtual package provided by ").join( ', ', map { "$_"  } @$provided_by) );
-			}
-			
-			if ($suite eq "experimental") {
-			    note( _g( "Experimental package"),
-				  _g( "Warning: This package is from the experimental distribution. That means it is likely unstable or buggy, and it may even cause data loss. If you ignore this warning and install it nevertheless, you do it on your own risk.")."

" - ); - } - if ($subsection eq "debian-installer") { - note( _g( "debian-installer udeb package"), - _g( 'Warning: This package is intended for the use in building debian-installer images only. Do not install it on a normal Debian system.' ) - ); - } - $package_page .= pdesc( $short_desc, $long_desc ); + $v_str .= $cat->g(" and others") if $multiple_versions; + $contents{versions} = { short => $v_str, + multiple => $multiple_versions }; + + my $provided_by = $page->{provided_by}; + $contents{providers} = []; + pkg_list( \%packages, $opts, $provided_by, 'en', $contents{providers} ) if $provided_by; # # display dependencies # - my $dep_list; - $dep_list = print_deps( \%packages, $opts, $pkg, - $page->get_dep_field('depends'), - 'depends' ); - $dep_list .= print_deps( \%packages, $opts, $pkg, - $page->get_dep_field('recommends'), - 'recommends' ); - $dep_list .= print_deps( \%packages, $opts, $pkg, - $page->get_dep_field('suggests'), - 'suggests' ); - - if ( $dep_list ) { - $package_page .= "
\n"; - $package_page .= sprintf( "

"._g( "Other Packages Related to %s" )."

\n", $pkg ); - - $package_page .= pdeplegend( [ 'dep', _g( 'depends' ) ], - [ 'rec', _g( 'recommends' ) ], - [ 'sug', _g( 'suggests' ) ], ); - - $package_page .= $dep_list; - $package_page .= "
\n"; - } + build_deps( \%packages, $opts, $pkg, + $page->get_dep_field('pre-depends'), + 'depends', \%contents ); + build_deps( \%packages, $opts, $pkg, + $page->get_dep_field('depends'), + 'depends', \%contents ); + build_deps( \%packages, $opts, $pkg, + $page->get_dep_field('recommends'), + 'recommends', \%contents ); + build_deps( \%packages, $opts, $pkg, + $page->get_dep_field('suggests'), + 'suggests', \%contents ); # # Download package # - my $encodedpack = uri_escape( $pkg ); - $package_page .= "
"; - $package_page .= sprintf( "

"._g( "Download %s\n" )."

", - $pkg ) ; - $package_page .= "\n"; - $package_page .= "\n"; - $package_page .= "\n"; - $package_page .= ""; - $package_page .= "" - if $multiple_versions; - $package_page .= "\n"; + my @downloads; foreach my $a ( @archs ) { - $package_page .= "\n"; - $package_page .= "\n"; - $package_page .= "" - if $multiple_versions; - $package_page .= '\n\n"; + push @downloads, \%d; } - $package_page .= "
"._g("Download for all available architectures")."
"._g("Architecture").""._g("Version").""._g( "Package Size").""._g("Installed Size").""._g("Files")."
$a".$versions->{$a}."'; - $package_page .= floor(($sizes_deb->{$a}/102.4)+0.5)/10 . " kB"; - $package_page .= ''; - $package_page .= $sizes_inst->{$a} . " kB"; - $package_page .= ""; - if ( $suite ne "experimental" ) { - $package_page .= sprintf( "["._g( "list of files" )."]\n", - make_url("$encodedpkg/$a/filelist",''), $pkg ); - } else { - $package_page .= _g( "no current information" ); + my %d = ( arch => $a, + pkgsize => floor(($sizes_deb->{$a}/102.4)+0.5)/10, + instsize => $sizes_inst->{$a}, ); + + $d{version} = $versions->{$a} if $multiple_versions; + $d{archive} = $archives->{$a}; + if ( ($suite ne "experimental") + && ($subsection ne 'debian-installer')) { + $d{contents_avail} = 1; } - $package_page .= "
\n"; - $package_page .= "
\n"; - + $contents{downloads} = \@downloads; + # # more information # - $package_page .= pmoreinfo( name => $pkg, data => $page, - opts => $opts, - env => \%FTP_SITES, - bugreports => 1, sourcedownload => 1, - changesandcopy => 1, maintainers => 1, - search => 1 ); + moreinfo( name => $pkg, data => $page, vars => \%contents, + opts => $opts, + env => \%FTP_SITES, + bugreports => 1, sourcedownload => 1, + changesandcopy => 1, maintainers => 1, + search => 1 ); } else { # unless $page->is_virtual - $short_desc = _g( "virtual package" ); - - $$menu .= simple_menu( [ _g( "Distribution:" ), - _g( "Overview over this distribution" ), - make_url('/',''), - $suite ], - [ _g( "Section:" ), - _g( "All packages in this section" ), - make_url("virtual/",''), - - 'virtual' ], ); - - $package_page .= title( sprintf( _g( "Virtual Package: %s" ), - $pkg ) ); - - my $policy_url = 'http://www.debian.org/doc/debian-policy/'; - note( sprintf( _g( 'This is a virtual package. See the Debian policy for a definition of virtual packages.' ), - $policy_url, $policy_url )); - - $package_page .= sprintf( "

"._g( "Packages providing %s" )."

", $pkg ); + $contents{is_virtual} = 1; + $contents{desc}{short} = $cat->g( "virtual package" ); + $contents{subsection} = 'virtual'; + my $provided_by = $page->{provided_by}; - $package_page .= pkg_list( \%packages, $opts, $provided_by, 'en'); + $contents{providers} = []; + pkg_list( \%packages, $opts, $provided_by, 'en', $contents{providers} ); } # else (unless $page->is_virtual) } else { # unless $opts->{source} + $contents{is_source} = 1; + for my $entry (@results) { debug( join(":", @$entry), 1 ) if DEBUG; my (undef, $archive, undef, $section, $subsection, $priority, $version) = @$entry; - + my $data = $sources_all{"$archive $suite $pkg"}; $page->merge_data($pkg, $suite, $archive, $data) or debug( "Merging $pkg $version FAILED", 2 ) if DEBUG; } $version = $page->{version}; + $contents{version} = $version; my $st1 = new Benchmark; my $std = timediff($st1, $st0); debug( "Data search and merging took ".timestr($std) ) if DEBUG; $archive = $page->get_newest( 'archive' ); + $contents{archive} = $archive; $section = $page->get_newest( 'section' ); + $contents{section} = $section; $subsection = $page->get_newest( 'subsection' ); - - $$menu .= simple_menu( [ _g( "Distribution:" ), - _g( "Overview over this suite" ), - make_url('/',''), - $suite ], - [ _g( "Section:" ), - _g( "All packages in this section" ), - make_url("$subsection/",''), - $subsection ], - ); - - my $title .= sprintf( _g( "Source Package: %s (%s)" ), - $pkg, $version ); - $title .= " ".marker( $archive ) if $archive ne 'us'; - $title .= " ".marker( $subsection ) if $subsection eq 'non-US' - and $archive ne 'non-US'; # non-US/security - $title .= " ".marker( $section ) if $section ne 'main'; - $package_page .= title( $title ); - - if ($suite eq "experimental") { - note( _g( "Experimental package"), - _g( "Warning: This package is from the experimental distribution. That means it is likely unstable or buggy, and it may even cause data loss. If you ignore this warning and install it nevertheless, you do it on your own risk.")."

" - ); - } - if ($subsection eq "debian-installer") { - note( _g( "debian-installer udeb package"), - _g( 'Warning: This package is intended for the use in building debian-installer images only. Do not install it on a normal Debian system.' ) - ); - } + $contents{subsection} = $subsection; my $binaries = find_binaries( $pkg, $archive, $suite, \%src2bin ); if ($binaries && @$binaries) { - $package_page .= '
'; - $package_page .= _g( "The following binary packages are built from this source package:" ); - $package_page .= pkg_list( \%packages, $opts, $binaries, 'en' ); - $package_page .= '
'; + $contents{binaries} = []; + pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} ); } - + # # display dependencies # - my $dep_list; - $dep_list = print_deps( \%packages, $opts, $pkg, - $page->get_dep_field('build-depends'), - 'build-depends' ); - $dep_list .= print_deps( \%packages, $opts, $pkg, - $page->get_dep_field('build-depends-indep'), - 'build-depends-indep' ); - - if ( $dep_list ) { - $package_page .= "
\n"; - $package_page .= sprintf( "

"._g( "Other Packages Related to %s" )."

\n", $pkg ); - - $package_page .= pdeplegend( [ 'adep', _g( 'build-depends' ) ], - [ 'idep', _g( 'build-depends-indep' ) ], - ); - - $package_page .= $dep_list; - $package_page .= "
\n"; - } + build_deps( \%packages, $opts, $pkg, + $page->get_dep_field('build-depends'), + 'build-depends', \%contents ); + build_deps( \%packages, $opts, $pkg, + $page->get_dep_field('build-depends-indep'), + 'build-depends-indep', \%contents ); # # Source package download # - $package_page .= "
\n"; - $package_page .= sprintf( "

"._g( "Download %s" )."

\n", - $pkg ) ; - my $source_files = $page->get_src( 'files' ); my $source_dir = $page->get_src( 'directory' ); - - $package_page .= sprintf( ''. - "", - _g("File"), - _g("Size (in kB)"), - _g("md5sum") ); + + $contents{srcfiles} = []; foreach( @$source_files ) { my ($src_file_md5, $src_file_size, $src_file_name) = split /\s+/, $_; - my $src_url; - for ("$suite/$archive") { - /security/o && do { - $src_url = $FTP_SITES{security}; last }; - /volatile/o && do { - $src_url = $FTP_SITES{volatile}; last }; - /backports/o && do { - - $src_url = $FTP_SITES{backports}; last }; - /non-us/io && do { - $src_url = $FTP_SITES{'non-US'}; last }; - $src_url = $FTP_SITES{us}; - } - $src_url .= "/$source_dir/$src_file_name"; - - $package_page .= "\n" - ."\n" - .""; + my $server = $FTP_SITES{lc $archive} + || $FTP_SITES{us}; + my $path = "/$source_dir/$src_file_name"; + + push @{$contents{srcfiles}}, { server => $server, path => $path, filename => $src_file_name, + size => floor(($src_file_size/102.4)+0.5)/10, + md5sum => $src_file_md5 }; } - $package_page .= "
%s%s%s
$src_file_name".sprintf("%.1f", (floor(($src_file_size/102.4)+0.5)/10))."$src_file_md5
\n"; - $package_page .= "
\n"; # # more information # - $package_page .= pmoreinfo( name => $pkg, data => $page, - opts => $opts, - env => \%FTP_SITES, - bugreports => 1, - changesandcopy => 1, maintainers => 1, - search => 1, is_source => 1 ); - + moreinfo( name => $pkg, data => $page, vars => \%contents, + opts => $opts, + env => \%FTP_SITES, + bugreports => 1, + changesandcopy => 1, maintainers => 1, + search => 1, is_source => 1 ); + } # else (unless $opts->{source}) } # else (unless @results) } # else (unless (@results || @non_results )) } # use Data::Dumper; -# debug( "Final page object:\n".Dumper($page), 3 ) if DEBUG; - - my $title = $opts->{source} ? - _g( "Details of source package %s in %s" ) : - _g( "Details of package %s in %s" ) ; - my $title_tag = $opts->{source} ? - _g( "Details of source package %s in %s" ) : - _g( "Details of package %s in %s" ) ; - %$html_header = ( title => sprintf( $title, $pkg, $suite ) , - lang => $opts->{lang}, - desc => $short_desc, - keywords => "$suite, $archive, $section, $subsection, $version", - title_tag => sprintf( $title_tag, $pkg, $suite ), - print_search_field => 'packages', - search_field_values => { - keywords => '', - searchon => $opts->{source} ? 'sourcenames' : 'names', - arch => 'any', - suite => 'all', - section => 'all', - exact => 0, - debug => $opts->{debug}, - }, - ); - - $$page_content = $package_page; +# debug( "Final page object:\n".Dumper(\%contents), 3 ) if DEBUG; + + %$page_contents = %contents; } +sub moreinfo { + my %info = @_; + + my $name = $info{name} or return; + my $env = $info{env} or return; + my $opts = $info{opts} or return; + my $page = $info{data} or return; + my $contents = $info{vars} or return; + my $is_source = $info{is_source}; + my $suite = $opts->{suite}[0]; + + my $source = $page->get_src( 'package' ); + my $source_version = $page->get_src( 'version' ); + my $src_dir = $page->get_src('directory'); + if ($info{sourcedownload}) { + $contents->{src}{url} = make_url($source,'',{source=>'source'}); + $contents->{src}{pkg} = $source; + + my @downloads; + my $files = $page->get_src( 'files' ); + if (defined($files) and @$files) { + foreach( @$files ) { + my ($src_file_md5, $src_file_size, $src_file_name) = split /\s/o, $_; + my ($server, $path); + $server = $env->{lc $page->get_newest('archive')}||$env->{us}; + $path = "/$src_dir/$src_file_name"; + push @downloads, { name => $src_file_name, server => $server, path => $path }; + } + } + $contents->{src}{downloads} = \@downloads; + } + + if ($info{changesandcopy}) { + if ( $src_dir ) { + (my $src_basename = $source_version) =~ s,^\d+:,,; # strip epoche + $src_basename = "${source}_$src_basename"; + $src_dir =~ s,pool/updates,pool,o; + + $contents->{files}{changelog}{path} = "$src_dir/$src_basename/changelog"; + $contents->{files}{copyright}{path} = "$src_dir/$src_basename/".( $is_source ? 'copyright' : "$name.copyright" ); + } + } + + if ($info{maintainers}) { + my $uploaders = $page->get_src( 'uploaders' ); + if ($uploaders && @$uploaders) { + my @maintainers = map { { name => $_->[0], mail => $_->[1] } } @$uploaders; + $contents->{maintainers} = \@maintainers; + } + } + +} + +sub providers { + my ($suite, $entry, $also) = @_; + my %tmp = map { $_ => 1 } split /\s/, $entry; + my @provided_by = keys %tmp; # weed out duplicates + my %out = ( also => $also, + pkgs => \@provided_by ); + return \%out; +} + +sub build_deps { + my ( $packages, $opts, $pkg, $relations, $type, $contents) = @_; + my %dep_type = ('depends' => 'dep', 'recommends' => 'rec', + 'suggests' => 'sug', 'build-depends' => 'adep', + 'build-depends-indep' => 'idep' ); + my $suite = $opts->{suite}[0]; + my $cat = $opts->{cat}; + + my %out = ( id => $dep_type{$type}, terms => [] ); + +# use Data::Dumper; +# debug( "print_deps called:\n".Dumper( $pkg, $relations, \$type ), 3 ) if DEBUG; + + foreach my $rel (@$relations) { + my %rel_out; + $rel_out{is_old_pkgs} = $rel->[0]; + $rel_out{alternatives} = []; + + foreach my $rel_alt ( @$rel ) { + next unless ref($rel_alt); + my ( $p_name, $pkg_version, $arch_neg, + $arch_str, $subsection, $available ) = @$rel_alt; + + if ($arch_str ||= '') { + if ($arch_neg) { + $arch_str = $cat->g("not %s", "$arch_str" ); + } else { + $arch_str = $arch_str; + } + } + + my %rel_alt_out = ( name => $p_name, + version => $pkg_version, + arch_str => $arch_str, + arch_neg => $arch_neg ); + + my @results; + my %entries; + my $entry = $entries{$p_name} || + read_entry_simple( $packages, $p_name, $opts->{h_archives}, $suite); + my $short_desc = $entry->[-1]; + my $desc_md5 = $entry->[-2] || ''; + my $arch = $entry->[3]; + my $archive = $entry->[1]; + my $p_suite = $entry->[2]; + if ( $short_desc ) { + $rel_alt_out{desc} = $short_desc; + my $trans_desc = $desctrans{$desc_md5}; + if ($trans_desc) { + my %trans_desc = split /\000|\001/, $trans_desc; + my %sdescs; + while (my ($l, $d) = each %trans_desc) { + $d =~ s/\n.*//os; + + $sdescs{$l} = $d; + } + $rel_alt_out{trans_desc} = \%sdescs; + } + $rel_alt_out{suite} = $p_suite; + if ( $rel_out{is_old_pkgs} ) { + } elsif (defined $entry->[1]) { + $entries{$p_name} ||= $entry; + $rel_alt_out{providers} = providers( $p_suite, + $entry->[0], + 1 ) if defined $entry->[0]; + } elsif (defined $entry->[0]) { + $rel_alt_out{desc} = undef; + $rel_alt_out{providers} = providers( $p_suite, + $entry->[0] ); + #FIXME: we don't handle virtual packages from + # the fallback suite correctly here + $rel_alt_out{suite} = $suite; + } + } elsif ( $rel_out{is_old_pkgs} ) { + } else { + $rel_alt_out{desc} = $cat->g( "Package not available" ); + $rel_alt_out{suite} = ''; + } + push @{$rel_out{alternatives}}, \%rel_alt_out; + } + + push @{$out{terms}}, \%rel_out; + } + + $contents->{relations} ||= []; + push @{$contents->{relations}}, \%out if @{$out{terms}}; +} # end print_deps + +sub pkg_list { + my ( $packages, $opts, $pkgs, $lang, $list ) = @_; + my $suite = $opts->{suite}[0]; + + foreach my $p ( sort @$pkgs ) { + + # we don't deal with virtual packages here because for the + # current uses of this function this isn't needed + my $data = read_entry_simple( $packages, $p, $opts->{h_archives}, $suite); + my ($desc_md5, $short_desc) = ($data->[-2],$data->[-1]); + + if ( $short_desc ) { + my $trans_desc = $desctrans{$desc_md5}; + my %sdescs; + if ($trans_desc) { + my %trans_desc = split /\000|\001/, $trans_desc; + while (my ($l, $d) = each %trans_desc) { + $d =~ s/\n.*//os; + + $sdescs{$l} = $d; + } + } + push @$list, { name => $p, desc => $short_desc, + trans_desc => \%sdescs, available => 1 }; + } else { + push @$list, { name => $p, + desc => $opts->{cat}->g("Not available") }; + } + } +} + + 1;