]> git.deb.at Git - deb/packages.git/blobdiff - lib/Packages/DoShow.pm
Packages::DoShow: Fix a "uninitialized value" warning
[deb/packages.git] / lib / Packages / DoShow.pm
index 62324a7c0ff682f91e51eec10f06aac948ab07e4..01590653cf64edcddb1d8e7f9446e26e22fa05e1 100644 (file)
@@ -12,9 +12,9 @@ use Exporter;
 
 use Deb::Versions;
 use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @SECTIONS
-                        @ARCHITECTURES %FTP_SITES );
-use Packages::I18N::Locale;
-use Packages::CGI qw( :DEFAULT make_url make_search_url note );
+                        @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::Page ();
@@ -24,16 +24,18 @@ our @ISA = qw( Exporter );
 our @EXPORT = qw( do_show );
 
 sub do_show {
-    my ($params, $opts, $html_header, $page_contents) = @_;
+    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;
@@ -68,8 +70,8 @@ sub do_show {
        }
 
        unless (@results || @non_results ) {
-           fatal_error( _g( "No such package." )."<br>".
-                        sprintf( _g( '<a href="%s">Search for the package</a>' ), make_search_url('','keywords='.uri_escape($pkg)) ) );
+           fatal_error( $cat->g( "No such package.") );
+           #sprintf( _g( '<a href="%s">Search for the package</a>' ), make_search_url('','keywords='.uri_escape($pkg)) ) );
        } else {
            my %all_suites;
            foreach (@results, @non_results) {
@@ -78,16 +80,17 @@ sub do_show {
                $all_suites{$s}++;
            }
            $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"};
@@ -100,7 +103,7 @@ sub do_show {
                            $page->add_provided_by([split /\s+/, $provided_by]);
                        }
                    }
-                   
+
                    unless ($page->is_virtual()) {
                        $version = $page->{newest};
                        $contents{version} = $version;
@@ -110,6 +113,8 @@ sub do_show {
 
                        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;
 
@@ -117,9 +122,23 @@ 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 @tags = split(/, /, $page->get_newest( 'tag' ));
+                       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;
@@ -134,25 +153,51 @@ sub do_show {
 
                        # process description
                        #
-                       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~-]+?/?)((\&gt\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
-                       $long_desc =~ s/\A //o;
-                       $long_desc =~ s/\n /\n/sgo;
-                       $long_desc =~ s/\n.\n/\n<p>\n/go;
-                       $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$1\n<\/pre>/sgo;
+                       sub process_description {
+                           my ($desc) = @_;
+
+                           my $short_desc = encode_entities( $1, "<>&\"" )
+                               if $desc =~ s/^(.*)$//m;
+                           my $long_desc = encode_entities( $desc, "<>&\"" );
 
-                       $contents{desc} = { short => $short_desc,
-                                           long => $long_desc, };
+                           $long_desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\&gt\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
+                           $long_desc =~ s/\A //o;
+                           $long_desc =~ s/\n /\n/sgo;
+                           $long_desc =~ s/\n.\n/\n<p>\n/go;
+                           $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$1\n<\/pre>/sgo;
+
+                           return ($short_desc, $long_desc);
+                       }
+
+                       my $desc = $descriptions{$did};
+                       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;
+                       $v_str .= $cat->g(" and others") if $multiple_versions;
                        $contents{versions} = { short => $v_str,
-                                               multiple => $multiple_versions };
+                                               multiple => $multiple_versions };
 
                        my $provided_by = $page->{provided_by};
                        $contents{providers} = [];
@@ -161,13 +206,16 @@ sub do_show {
                        #
                        # display dependencies
                        #
-                       build_deps( \%packages, $opts, $pkg,
+                       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,
+                       build_deps( \%packages, $opts, $pkg,
                                    $page->get_dep_field('recommends'),
                                    'recommends', \%contents );
-                       build_deps( \%packages, $opts, $pkg,
+                       build_deps( \%packages, $opts, $pkg,
                                    $page->get_dep_field('suggests'),
                                    'suggests', \%contents );
 
@@ -177,10 +225,11 @@ sub do_show {
                        my @downloads;
                        foreach my $a ( @archs ) {
                            my %d = ( arch => $a,
-                                     pkgsize => sprintf( '%.1f', floor(($sizes_deb->{$a}/102.4)+0.5)/10 ),
+                                     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;
@@ -188,7 +237,7 @@ sub do_show {
                            push @downloads, \%d;
                        }
                        $contents{downloads} = \@downloads;
-                       
+
                        #
                        # more information
                        #
@@ -200,13 +249,9 @@ sub do_show {
                                  search => 1 );
                    } else { # unless $page->is_virtual
                        $contents{is_virtual} = 1;
-                       $contents{desc}{short} = _g( "virtual package" );
+                       $contents{desc}{short} = $cat->g( "virtual package" );
                        $contents{subsection} = 'virtual';
 
-                       my $policy_url = 'http://www.debian.org/doc/debian-policy/';
-                       note( sprintf( _g( 'This is a <em>virtual package</em>. See the <a href="%s">Debian policy</a> for a <a href="%sch-binary.html#s-virtual_pkg">definition of virtual packages</a>.' ),
-                                      $policy_url, $policy_url ));
-
                        my $provided_by = $page->{provided_by};
                        $contents{providers} = [];
                        pkg_list( \%packages, $opts, $provided_by, 'en', $contents{providers} );
@@ -219,7 +264,7 @@ sub do_show {
                        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;
@@ -237,13 +282,13 @@ sub do_show {
                    $contents{section} = $section;
                    $subsection = $page->get_newest( 'subsection' );
                    $contents{subsection} = $subsection;
-                   
+
                    my $binaries = find_binaries( $pkg, $archive, $suite, \%src2bin );
                    if ($binaries && @$binaries) {
                        $contents{binaries} = [];
                        pkg_list( \%packages, $opts, $binaries, 'en', $contents{binaries} );
                    }
-                   
+
                    #
                    # display dependencies
                    #
@@ -259,18 +304,17 @@ sub do_show {
                    #
                    my $source_files = $page->get_src( 'files' );
                    my $source_dir = $page->get_src( 'directory' );
-                   
+
                    $contents{srcfiles} = [];
                    foreach( @$source_files ) {
                        my ($src_file_md5, $src_file_size, $src_file_name)
                            = split /\s+/, $_;
-                       (my $server = lc $archive) =~ s/-//go; # non-US hack
-                       $server = $FTP_SITES{$server}
+                       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 => sprintf("%.1f", (floor(($src_file_size/102.4)+0.5)/10)),
+                                                      size => floor(($src_file_size/102.4)+0.5)/10,
                                                       md5sum => $src_file_md5 };
                    }
 
@@ -283,7 +327,7 @@ sub do_show {
                              bugreports => 1,
                              changesandcopy => 1, maintainers => 1,
                              search => 1, is_source => 1 );
-                   
+
                } # else (unless $opts->{source})
            } # else (unless @results)
        } # else (unless (@results || @non_results ))
@@ -318,17 +362,10 @@ sub moreinfo {
        if (defined($files) and @$files) {
            foreach( @$files ) {
                my ($src_file_md5, $src_file_size, $src_file_name) = split /\s/o, $_;
-               my ($name, $server, $path);
-               # non-US hack
-               ($server = lc $page->get_newest('archive')) =~ s/-//go;
-               $server = $env->{$server}||$env->{us};
-               $path = "$src_dir/$src_file_name";
-               if ($src_file_name =~ /dsc$/) {
-                   $name = 'dsc'
-               } else {
-                   $name = $src_file_name;
-               }
-               push @downloads, { name => $name, server => $server, path => $path };
+               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;
@@ -339,7 +376,6 @@ sub moreinfo {
            (my $src_basename = $source_version) =~ s,^\d+:,,; # strip epoche
            $src_basename = "${source}_$src_basename";
            $src_dir =~ s,pool/updates,pool,o;
-           $src_dir =~ s,pool/non-US,pool,o;
 
            $contents->{files}{changelog}{path} = "$src_dir/$src_basename/changelog";
            $contents->{files}{copyright}{path} = "$src_dir/$src_basename/".( $is_source ? 'copyright' : "$name.copyright" );
@@ -371,6 +407,7 @@ sub build_deps {
                    '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 => [] );
 
@@ -389,7 +426,7 @@ sub build_deps {
 
            if ($arch_str ||= '') {
                if ($arch_neg) {
-                   $arch_str = _g("not")." $arch_str";
+                   $arch_str = $cat->g("not %s", "$arch_str" );
                } else {
                    $arch_str = $arch_str;
                }
@@ -405,11 +442,23 @@ sub build_deps {
            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]) {
@@ -427,7 +476,7 @@ sub build_deps {
                }
            } elsif ( $rel_out{is_old_pkgs} ) {
            } else {
-               $rel_alt_out{desc} = _g( "Package not available" );
+               $rel_alt_out{desc} = $cat->g( "Package not available" );
                $rel_alt_out{suite} = '';
            }
            push @{$rel_out{alternatives}}, \%rel_alt_out;
@@ -448,12 +497,25 @@ sub pkg_list {
 
        # we don't deal with virtual packages here because for the
        # current uses of this function this isn't needed
-       my $short_desc = (read_entry_simple( $packages, $p, $opts->{h_archives}, $suite))->[-1];
+       my $data = read_entry_simple( $packages, $p, $opts->{h_archives}, $suite);
+       my ($desc_md5, $short_desc) = ($data->[-2],$data->[-1]);
 
        if ( $short_desc ) {
-           push @$list, { name => $p, desc => $short_desc, available => 1 };
+           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 => _g("Not available") };
+           push @$list, { name => $p,
+                          desc => $opts->{cat}->g("Not available") };
        }
     }
 }