From: Frank Lichtenheld Date: Sun, 5 Feb 2006 01:55:18 +0000 (+0000) Subject: show_package.pl Basic stuff works with still some rough edges and dirty X-Git-Tag: switch-to-templates~172 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=08852aab550de858d4e4956ea357dbc3ae713a26;p=deb%2Fpackages.git show_package.pl Basic stuff works with still some rough edges and dirty corners --- diff --git a/bin/parse-packages b/bin/parse-packages index 7a67e69..04bee3d 100755 --- a/bin/parse-packages +++ b/bin/parse-packages @@ -66,11 +66,14 @@ for my $archive (@archives) { $package_names{$data{'package'}} = 1; my $src = $data{'package'}; + my $src_version = ''; if ($data{'source'}) { $src = $data{'source'}; - $src =~ s/ .*//; # strip version info + $src_version = $1 + if $src =~ s/\s+\(\s*=\s*(.*)\).*//; # strip version info } $data{'source'} = $src; + $data{'source-version'} = $src_version; my $descr = $data{'description'}; my $did = undef; if (exists($descriptions{$descr})) { diff --git a/cgi-bin/show_package.pl b/cgi-bin/show_package.pl index 3461399..f6324d6 100755 --- a/cgi-bin/show_package.pl +++ b/cgi-bin/show_package.pl @@ -24,7 +24,7 @@ use Benchmark; use Deb::Versions; use Packages::CGI; use Packages::Search qw( :all ); -use Packages::HTML (); +use Packages::HTML; use Packages::Page (); &Packages::CGI::reset; @@ -68,6 +68,9 @@ if ($modtime > $config_read_time) { $Packages::HTML::SEARCH_PAGE = $1 if /^\s*searchpage="?([^\"]*)"?\s*$/o; $Packages::HTML::WEBMASTER_MAIL = $1 if /^\s*webmaster="?([^\"]*)"?\s*$/o; $Packages::HTML::CONTACT_MAIL = $1 if /^\s*contact="?([^\"]*)"?\s*$/o; + $Packages::HTML::BUG_URL = $1 if /^\s*bug_url="?([^\"]*)"?\s*$/o; + $Packages::HTML::SRC_BUG_URL = $1 if /^\s*src_bug_url="?([^\"]*)"?\s*$/o; + $Packages::HTML::QA_URL = $1 if /^\s*qa_url="?([^\"]*)"?\s*$/o; @SUITES = split(/\s+/, $1) if /^\s*suites="?([^\"]*)"?\s*$/o; @SECTIONS = split(/\s+/, $1) if /^\s*sections="?([^\"]*)"?\s*$/o; @ARCHIVES = split(/\s+/, $1) if /^\s*archives="?([^\"]*)"?\s*$/o; @@ -91,13 +94,13 @@ if (my $path = $input->param('path')) { foreach (@components) { if ($SUITES{$_}) { $input->param('suite', $_); - }# elsif ($SECTIONS{$_}) { -# $input->param('section', $_); -# } elsif ($ARCHIVES{$_}) { -# $input->param('archive', $_); -# } elsif ($ARCHITECTURES{$_}) { -# $input->param('arch', $_); -# } + } elsif ($SECTIONS{$_}) { + $input->param('section', $_); + } elsif ($ARCHIVES{$_}) { + $input->param('archive', $_); + } elsif ($ARCHITECTURES{$_}) { + $input->param('arch', $_); + } } } @@ -134,9 +137,15 @@ my $DL_URL = "$pkg/download"; my $FILELIST_URL = "$pkg/files"; my $DDPO_URL = "http://qa.debian.org/developer.php?email="; -our (%packages, %packages_all); +our (%packages, %packages_all, %sources_all, %descriptions); my (@results, @non_results); +my $page = new Packages::Page( $pkg ); +my $package_page = ""; +my ($short_desc, $version, $archive, $section, $subsection) = ("")x5; +sub gettext { return $_[0]; }; + +my $st0 = new Benchmark; unless (@Packages::CGI::fatal_errors) { my $dbmodtime = (stat("$DBDIR/packages_small.db"))[9]; if ($dbmodtime > $db_read_time) { @@ -146,6 +155,13 @@ unless (@Packages::CGI::fatal_errors) { tie %packages_all, 'DB_File', "$DBDIR/packages_all_$suite.db", O_RDONLY, 0666, $DB_BTREE or die "couldn't tie DB $DBDIR/packages_all_$suite.db: $!"; + tie %sources_all, 'DB_File', "$DBDIR/sources_all_$suite.db", + O_RDONLY, 0666, $DB_BTREE + or die "couldn't tie DB $DBDIR/sources_all_$suite.db: $!"; + tie %descriptions, 'DB_File', "$DBDIR/descriptions.db", + O_RDONLY, 0666, $DB_BTREE + or die "couldn't tie DB $DBDIR/descriptions.db: $!"; + debug( "tied databases ($dbmodtime > $db_read_time)" ); $db_read_time = $dbmodtime; } @@ -158,220 +174,212 @@ unless (@Packages::CGI::fatal_errors) { } else { unless (@results) { fatal_error( "Package not available in this suite" ); + } else { + for my $entry (@results) { + debug( join(":", @$entry), 1 ); + my (undef, $archive, undef, $arch, $section, $subsection, + $priority, $version) = @$entry; + + my $data = $packages_all{"$pkg $arch $version"}; + $page->merge_data($pkg, $version, $arch, $data) or debug( "Merging $pkg $arch $version FAILED", 2 ); + } + + $version = $page->{newest}; + my $source = $page->get_newest( 'source' ); + my $source_version = $page->get_newest( 'source-version' ) + || $version; + my $src_data = $sources_all{"$source $source_version"}; + unless ($src_data) { #fucking binNMUs + my $versions = $page->get_versions; + my $sources = $page->get_arch_field( 'source' ); + my $source_versions = $page->get_arch_field( 'source-version' ); + foreach (version_sort keys %$versions) { + $source = $sources->{$versions->{$_}[0]}; + $source = $source_versions->{$versions->{$_}[0]} + || $version; + $src_data = $sources_all{"$source $source_version"}; + last if $src_data; + } + error( "couldn't find source package" ) unless $src_data; + } + $page->add_src_data( $source, $source_version, $src_data ); + + my $st1 = new Benchmark; + my $std = timediff($st1, $st0); + debug( "Data search and merging took ".timestr($std) ); + + my $encodedpkg = uri_escape( $pkg ); + my ($v_str, $v_str_arch, $v_str_arr) = $page->get_version_string(); + my $did = $page->get_newest( 'description' ); + $archive = $page->get_newest( 'archive' ); + $section = $page->get_newest( 'section' ); + $subsection = $page->get_newest( 'subsection' ); + my $filenames = $page->get_arch_field( 'filename' ); + my $file_md5sums = $page->get_arch_field( 'md5sum' ); + my $archives = $page->get_arch_field( 'archive' ); + my $sizes_inst = $page->get_arch_field( 'installed-size' ); + my $sizes_deb = $page->get_arch_field( 'size' ); + my @archs = sort $page->get_architectures; + + # 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~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\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 %all_suites = map { $_->[2] => 1 } (@results, @non_results);
+	    foreach (suites_sort(keys %all_suites)) {
+		if ($suite eq $_) {
+		    $package_page .= "[ $_ ] ";
+		} else {
+		    $package_page .=
+			"[ $_ ] ";
+		}
+	    }
+
+ 	    $package_page .= simple_menu( [ gettext( "Distribution:" ),
+ 					    gettext( "Overview over this suite" ),
+ 					    "/$suite/",
+ 					    $suite ],
+ 					  [ gettext( "Section:" ),
+ 					    gettext( "All packages in this section" ),
+ 					    "/$suite/$subsection/",
+ 					    $subsection ],
+ 					  );
+
+ 	    my $title .= sprintf( gettext( "Package: %s (%s)" ), $pkg, $v_str );
+ 	    $title .=  " ".marker( $archive ) if $archive ne 'us';
+ 	    $title .=  " ".marker( $section ) if $section ne 'main';
+ 	    $package_page .= title( $title );
+	    
+ 	    $package_page .= "

".gettext( "Versions:" )." $v_str_arch

\n" + unless $version eq $v_str; + + if ($suite eq "experimental") { + $package_page .= note( gettext( "Experimental package"), + gettext( "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.")."

". + gettext( "Users of experimental packages are encouraged to contact the package maintainers directly in case of problems." ) + ); + } + if ($subsection eq "debian-installer") { + note( gettext( "debian-installer udeb package"), + gettext( "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 ); + + # + # display dependencies + # + my $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( "

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

\n", $pkg ); + if ($suite eq "experimental") { + note( gettext( "Note that the \"experimental\" distribution is not self-contained; missing dependencies are likely found in the \"unstable\" distribution." ) ); + } + + $package_page .= pdeplegend( [ 'dep', gettext( 'depends' ) ], + [ 'rec', gettext( 'recommends' ) ], + [ 'sug', gettext( 'suggests' ) ], ); + + $package_page .= $dep_list; + $package_page .= "
\n"; + + # + # Download package + # + my $encodedpack = uri_escape( $pkg ); + $package_page .= "
"; + $package_page .= sprintf( "

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

", + $pkg ) ; + $package_page .= "\n"; + $package_page .= "\n"; + $package_page .= "\n"; + $package_page .= "\n"; + foreach my $a ( @archs ) { + $package_page .= "\n"; + $package_page .= "\n"; + $package_page .= "\n\n\n"; + } + $package_page .= "
".gettext("Download for all available architectures")."
".gettext("Architecture")."".gettext("Files")."".gettext( "Package Size")."".gettext("Installed Size")."
{$a}); + $package_page .= "&md5sum=$file_md5sums->{$a}"; + $package_page .= "&arch=$a"; + # there was at least one package with two + # different source packages on different + # archs where one had a security update + # and the other one not + for ($archives->{$a}) { + /security/o && do { + $package_page .= "&type=security"; last }; + /volatile/o && do { + $package_page .= "&type=volatile"; last }; + /non-us/io && do { + $package_page .= "&type=nonus"; last }; + $package_page .= "&type=main"; + } + $package_page .= "\">$a"; + if ( $suite ne "experimental" ) { + $package_page .= sprintf( "[".gettext( "list of files" )."]\n", "$FILELIST_URL$encodedpkg&version=$suite&arch=$a", $pkg ); + } else { + $package_page .= gettext( "no current information" ); + } + $package_page .= ""; + $package_page .= floor(($sizes_deb->{$a}/102.4)+0.5)/10; + $package_page .= ""; + $package_page .= $sizes_inst->{$a}; + $package_page .= "

".gettext ( "Size is measured in kBytes." )."

\n"; + $package_page .= "
\n"; + + # + # more information + # + $package_page .= pmoreinfo( name => $pkg, data => $page, + bugreports => 1, sourcedownload => 1, + changesandcopy => 0, maintainers => 1, + search => 1 ); + } } } } +use Data::Dumper; +debug( "Final page object:\n".Dumper($page), 3 ); + print Packages::HTML::header( title => "Details of package $pkg in $suite" , lang => 'en', + desc => $short_desc, + keywords => "$suite, $archive, $section, $subsection, $version", title_tag => "Details of package $pkg in $suite", - print_title_above => 1 ); print_errors(); print_hints(); print_msgs(); print_debug(); +print_notes(); unless (@Packages::CGI::fatal_errors) { - -my %all_suites = map { $_->[2] => 1 } (@results, @non_results); - foreach (suites_sort(keys %all_suites)) { - if ($suite eq $_) { - print "$_ | "; - } else { - print "$_ | "; - } - } - print "
"; - -my $page = new Packages::Page( $pkg ); - - for my $entry (@results) { - print join ":", @$entry; - print "
\n"; - my (undef, $archive, undef, $arch, $section, $subsection, - $priority, $version) = @$entry; - print "
".$packages_all{"$pkg $arch $version"}."
"; - } - -# my %versions = $pkg->get_arch_versions( $env->{archs} ); -# my %subsuites = $pkg->get_arch_fields( 'subdistribution', -# $env->{archs} ); -# my %filenames = $pkg->get_arch_fields( 'filename', -# $env->{archs} ); -# my %file_md5s = $pkg->get_arch_fields( 'md5sum', -# $env->{archs} ); - -# my $subsuite_kw = $d->{subsuite} || $env->{distribution}; -# my $size_kw = exists $d->{sizes_deb}{i386} ? $d->{sizes_deb}{i386} : first_val($d->{sizes_deb}); - - -# foreach my $lang (@{$env->{langs}}) { -# &Generated::Strings::string_lang($lang); - -# my $dirname = "$env->{dest_dir}/$d->{subsection}"; -# my $filename = "$dirname/$name.$lang.html"; - -# unless (( $lang eq 'en' ) -# || $env->{db}->is_translated( $name, $d->{version}, -# ${$versions{v2a}{$d->{version}}}[0], -# $lang )) { -# next; -# } -# progress() if $env->{opts}{progress}; - -# # -# # process description -# # -# my $short_desc = encode_entities( $env->{db}->get_short_desc( $d->{desc_md5}, -# $lang ), "<>&\"" ); -# my $long_desc = encode_entities( $env->{db}->get_long_desc( $d->{desc_md5}, -# $lang ), "<>&\"" ); - -# $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 );
-	    
-# 	    #
-# 	    # begin output
-# 	    #
-# 	    my $package_page = header( title => $name, lang => $lang,
-# 				       desc => $short_desc,
-# 				       keywords => "$env->{distribution}, $subsuite_kw, $d->{section}, $d->{subsection}, size:$size_kw $d->{version}" );
-# 	    $package_page .= simple_menu( [ gettext( "Distribution:" ),
-# 					    gettext( "Overview over this distribution" ),
-# 					    "../",
-# 					    $env->{distribution} ],
-# 					  [ gettext( "Section:" ),
-# 					    gettext( "All packages in this section" ),
-# 					    "../$d->{subsection}/",
-# 					    $d->{subsection} ],
-# 					  );
-	    
-# 	    my $title .= sprintf( gettext( "Package: %s (%s)" ), $name, $d->{v_str_simple} );
-# 	    $title .=  " ".marker( $d->{subsuite} ) if $d->{subsuite};
-# 	    $title .=  " ".marker( $d->{section} ) if $d->{section} ne 'main';
-# 	    $package_page .= title( $title );
-	    
-# 	    $package_page .= "

".gettext( "Versions:" )." $d->{v_str_arch}

\n" -# unless $d->{version} eq $d->{v_str_simple}; - -# if ($env->{distribution} eq "experimental") { -# $package_page .= note( gettext( "Experimental package"), -# gettext( "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.")."

". -# gettext( "Users of experimental packages are encouraged to contact the package maintainers directly in case of problems." ) -# ); -# } -# if ($d->{section} eq "debian-installer") { -# $package_page .= note( gettext( "debian-installer udeb package"), -# gettext( "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 ); - -# # -# # display dependencies -# # -# my $dep_list = print_deps( $env, $lang, $pkg, $d->{depends}, 'depends' ); -# $dep_list .= print_deps( $env, $lang, $pkg, $d->{recommends}, 'recommends' ); -# $dep_list .= print_deps( $env, $lang, $pkg, $d->{suggests}, 'suggests' ); - -# if ( $dep_list ) { -# $package_page .= "

\n"; -# $package_page .= sprintf( "

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

\n", $name ); -# if ($env->{distribution} eq "experimental") { -# $package_page .= note( gettext( "Note that the \"experimental\" distribution is not self-contained; missing dependencies are likely found in the \"unstable\" distribution." ) ); -# } - -# $package_page .= pdeplegend( [ 'dep', gettext( 'depends' ) ], -# [ 'rec', gettext( 'recommends' ) ], -# [ 'sug', gettext( 'suggests' ) ], ); - -# $package_page .= $dep_list; -# $package_page .= "
\n"; -# } - -# # -# # Download package -# # -# my $encodedpack = uri_escape( $name ); -# $package_page .= "
"; -# $package_page .= sprintf( "

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

", -# $name ) ; -# $package_page .= "\n"; -# $package_page .= "\n"; -# $package_page .= "\n"; -# $package_page .= "\n"; -# foreach my $a ( @all_archs ) { -# if ( exists $versions{a2v}{$a} ) { -# $package_page .= "\n"; -# $package_page .= "\n"; -# $package_page .= "\n\n\n"; -# } -# } -# $package_page .= "
".gettext("Download for all available architectures")."
".gettext("Architecture")."".gettext("Files")."".gettext( "Package Size")."".gettext("Installed Size")."
\n

"; -# $package_page .= "&file=".uri_escape($filenames{a2f}->{$a}); -# $package_page .= "&md5sum=$file_md5s{a2f}->{$a}"; -# $package_page .= "&arch=$a"; -# # there was at least one package with two -# # different source packages on different -# # archs where one had a security update -# # and the other one not -# if ($subsuites{a2f}{$a} -# && ($subsuites{a2f}{$a} =~ /security/o) ) { -# $package_page .= "&type=security"; -# } elsif ($subsuites{a2f}{$a} -# && ($subsuites{a2f}{$a} =~ /volatile/o) ) { -# $package_page .= "&type=volatile"; -# } elsif ($d->{is_nonus}) { -# $package_page .= "&type=nonus"; -# } else { -# $package_page .= "&type=main"; -# } -# $package_page .= "\">$a

"; -# if ( $env->{distribution} ne "experimental" ) { -# $package_page .= sprintf( "[".gettext( "list of files" )."]\n", "$FILELIST_URL$encodedpack&version=$env->{distribution}&arch=$a", $name ); -# } else { -# $package_page .= "no files"; -# } -# $package_page .= ""; -# my $size = $d->{sizes_deb}{$a}; -# $package_page .= "$size"; -# $package_page .= ""; -# my $inst_size = $d->{sizes_inst}{$a}; -# $package_page .= "$inst_size"; -# $package_page .= "

".gettext ( "Size is measured in kBytes." )."

\n"; -# $package_page .= "
\n"; - -# # -# # more information -# # -# $package_page .= pmoreinfo( name => $name, env => $env, data => $d, -# bugreports => 1, sourcedownload => 1, -# changesandcopy => 1, maintainers => 1, -# search => 1 ); - -# # -# # Trailer -# # -# my @tr_langs = (); -# foreach my $l (@{$env->{langs}}) { -# next if $l eq $lang; -# push @tr_langs, $l if ( $l eq 'en' ) -# || $env->{db}->is_translated( $name, $d->{version}, -# ${$versions{v2a}{$d->{version}}}[0], -# $l ); -# } -# $package_page .= trailer( '../..', $name, $lang, @tr_langs ); -# } -# } + print $package_page; } my $tet1 = new Benchmark; my $tetd = timediff($tet1, $tet0); diff --git a/config.sh b/config.sh index 85f35ac..2a3e945 100644 --- a/config.sh +++ b/config.sh @@ -37,6 +37,9 @@ searchcgi="/cgi-bin/search_packages.pl" webmaster=webmaster@debian.org contact=debian-www@lists.debian.org home="http://www.debian.org" +bug_url="http://bugs.debian.org/" +src_bug_url="http://bugs.debian.org/src:" +qa_url="http://packages.qa.debian.org/" # Architectures # diff --git a/lib/Packages/CGI.pm b/lib/Packages/CGI.pm index e9d834c..cac499f 100644 --- a/lib/Packages/CGI.pm +++ b/lib/Packages/CGI.pm @@ -2,15 +2,16 @@ package Packages::CGI; use Exporter; our @ISA = qw( Exporter ); -our @EXPORT = qw( fatal_error error hint debug msg - print_errors print_hints print_debug print_msgs ); +our @EXPORT = qw( fatal_error error hint debug msg note + print_errors print_hints print_debug print_msgs + print_notes ); our $debug = 0; -our (@fatal_errors, @errors, @debug, @msgs, @hints); +our (@fatal_errors, @errors, @debug, @msgs, @hints, @notes); sub reset { - @fatal_errors = @errors = @debug = @msgs = @hints = (); + @fatal_errors = @errors = @debug = @msgs = @hints = @notes = (); } sub fatal_error { @@ -29,6 +30,9 @@ sub debug { sub msg { push @msgs, $_[0]; } +sub notes { + push @notes, [ @_ ]; +} sub print_errors { return unless @fatal_errors || @errors; print '
'; @@ -45,7 +49,6 @@ sub print_debug { print "$_\n"; } print '
'; - } sub print_hints { return unless @hints; @@ -60,5 +63,19 @@ sub print_msgs { print "

$_

"; } } +sub print_notes { + foreach (@notes) { + my ( $title, $note ) = @$_; + my $str = ""; + + if ($note) { + $str .= "

$title

"; + } else { + $note = $title; + } + $str .= "

$note

"; + return $str; + } +} 1; diff --git a/lib/Packages/HTML.pm b/lib/Packages/HTML.pm index 873a7ea..38bfb58 100644 --- a/lib/Packages/HTML.pm +++ b/lib/Packages/HTML.pm @@ -6,6 +6,9 @@ use warnings; use URI::Escape; use HTML::Entities; +use Packages::CGI; +use Packages::Search qw( read_entry ); + #use Packages::Util; #use Packages::I18N::Locale; #use Packages::I18N::Languages; @@ -20,7 +23,7 @@ our @ISA = qw( Exporter ); our @EXPORT = qw( header title trailer file_changed time_stamp read_md5_hash write_md5_hash simple_menu ds_begin ds_item ds_end note title marker pdesc - pdeplegend pkg_list pmoreinfo ); + pdeplegend pkg_list pmoreinfo print_deps ); our ( $HOME, $ROOT, $CONTACT_MAIL, $WEBMASTER_MAIL, $SEARCH_PAGE, $SEARCH_CGI, $SEARCH_URL, @@ -55,19 +58,6 @@ sub marker { return "[$_[0]]"; } -sub note { - my ( $title, $note ) = @_; - my $str = ""; - - if ($note) { - $str .= "

$title

"; - } else { - $note = $title; - } - $str .= "

$note

"; - return $str; -} - sub pdesc { my ( $short_desc, $long_desc ) = @_; my $str = ""; @@ -129,8 +119,8 @@ sub pmoreinfo { my %info = @_; my $name = $info{name} or return; - my $env = $info{env} or return; - my $d = $info{data} or return; +# my $env = $info{env} or return; + my $page = $info{data} or return; my $is_source = $info{is_source}; my $str = "
"; @@ -144,25 +134,27 @@ sub pmoreinfo { $bug_url.$name, $name ); } + my $source = $page->get_src( 'name' ); if ($info{sourcedownload}) { + my $files = $page->get_src( 'files' ); $str .= gettext( "Source Package:" ); - $str .= " {src_name}\">$d->{src_name}, ". + $str .= " $source, ". gettext( "Download" ).":\n"; - unless ($d->{src_files}) { + unless (@$files) { $str .= gettext( "Not found" ); } else { - foreach( @{$d->{src_files}} ) { + foreach( @$files ) { my ($src_file_md5, $src_file_size, $src_file_name) = @$_; - if ($d->{is_security}) { - $str .= "{opts}{security_site}/$d->{src_directory}/$src_file_name\">["; - } elsif ($d->{is_volatile}) { - $str .= "{opts}{volatile_site}/$d->{src_directory}/$src_file_name\">["; - } elsif ($d->{is_nonus}) { - $str .= "{opts}{nonus_site}/$d->{src_directory}/$src_file_name\">["; - } else { - $str .= "{opts}{debian_site}/$d->{src_directory}/$src_file_name\">["; - } +# if ($d->{is_security}) { +# $str .= "{opts}{security_site}/$d->{src_directory}/$src_file_name\">["; +# } elsif ($d->{is_volatile}) { +# $str .= "{opts}{volatile_site}/$d->{src_directory}/$src_file_name\">["; +# } elsif ($d->{is_nonus}) { +# $str .= "{opts}{nonus_site}/$d->{src_directory}/$src_file_name\">["; +# } else { +# $str .= "{opts}{debian_site}/$d->{src_directory}/$src_file_name\">["; +# } if ($src_file_name =~ /dsc$/) { $str .= "dsc"; } else { @@ -175,25 +167,25 @@ sub pmoreinfo { # if ($src_version ne $version) && !$src_version_given_in_control; } - if ($info{changesandcopy}) { - if ( $d->{src_directory} ) { - my $src_dir = $d->{src_directory}; - (my $src_basename = $d->{src_version}) =~ s,^\d+:,,; # strip epoche - $src_basename = "$d->{src_name}_$src_basename"; - $src_dir =~ s,pool/updates,pool,o; - $src_dir =~ s,pool/non-US,pool,o; - $str .= "
".sprintf( gettext( "View the
Debian changelog" ), - "$CHANGELOG_URL/$src_dir/$src_basename/changelog" )."
\n"; - my $copyright_url = "$CHANGELOG_URL/$src_dir/$src_basename/"; - $copyright_url .= ( $is_source ? 'copyright' : "$name.copyright" ); - - $str .= sprintf( gettext( "View the copyright file" ), - $copyright_url )."

"; - } - } +# if ($info{changesandcopy}) { +# if ( $d->{src_directory} ) { +# my $src_dir = $d->{src_directory}; +# (my $src_basename = $d->{src_version}) =~ s,^\d+:,,; # strip epoche +# $src_basename = "$d->{src_name}_$src_basename"; +# $src_dir =~ s,pool/updates,pool,o; +# $src_dir =~ s,pool/non-US,pool,o; +# $str .= "
".sprintf( gettext( "View the Debian changelog" ), +# "$CHANGELOG_URL/$src_dir/$src_basename/changelog" )."
\n"; +# my $copyright_url = "$CHANGELOG_URL/$src_dir/$src_basename/"; +# $copyright_url .= ( $is_source ? 'copyright' : "$name.copyright" ); + +# $str .= sprintf( gettext( "View the copyright file" ), +# $copyright_url )."

"; +# } +# } if ($info{maintainers}) { - my @uploaders = @{$d->{uploaders}}; + my @uploaders = @{$page->get_src( 'uploaders' )}; foreach (@uploaders) { $_->[0] = encode_entities( $_->[0], '&<>' ); } @@ -215,7 +207,7 @@ sub pmoreinfo { $str .= "

\n$up_str "; } - $str .= sprintf( gettext( "See the developer information for %s." )."

", $QA_URL.$d->{src_name}, $name ); + $str .= sprintf( gettext( "See the developer information for %s." )."

", $QA_URL.$source, $name ); } if ($info{search}) { @@ -228,6 +220,152 @@ sub pmoreinfo { return $str; } +sub dep_item { + my ( $link, $name, $info, $desc ) = @_; + my $post_link = ''; + if ($link) { + $link = ""; + $post_link = ''; + } else { + $link = ''; + } + if ($info) { + $info = " $info"; + } else { + $info = ''; + } + if ($desc) { + $desc = "
$desc
"; + } else { + $desc = ''; + } + + return "$link$name$post_link$info$desc"; +} # end dep_item + +sub print_deps { + my ( $packages, $opts, $pkg, $relations, $type) = @_; + my %dep_type = ('depends' => 'dep', 'recommends' => 'rec', + 'suggests' => 'sug'); + my $res = "
    \n"; + my $first = 1; + +# use Data::Dumper; +# debug( "print_deps called:\n".Dumper( $pkg, $relations, \$type ), 3 ); + + foreach my $rel (@$relations) { + my $is_old_pkgs = $rel->[0]; + my @res_pkgs = (); + + if ($is_old_pkgs) { + $res .= "
    "; + } else { + if ($first) { + $res .= "
  • "; + $first = 0; + } else { + $res .= "
  • \n
  • "; + } + $res .= "
    \"[$dep_type{$type}]\" "; + } + + 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 = " [".gettext("not")." $arch_str]"; + } else { + $arch_str = " [$arch_str]"; + } + } + $pkg_version = "($pkg_version)" if $pkg_version; + + my @results; + read_entry( $packages, $p_name, \@results, $opts); + if ( @results ) { + if ( $is_old_pkgs ) { + push @res_pkgs, dep_item( "/$opts->{suite}/$p_name", + $p_name, "$pkg_version$arch_str" ); + } else { + my $short_desc = encode_entities( $results[0][-1], "<>&\"" ); + push @res_pkgs, dep_item( "/$opts->{suite}/$p_name", + $p_name, "$pkg_version$arch_str", $short_desc ); + } + } elsif ( $is_old_pkgs ) { + push @res_pkgs, dep_item( undef, $p_name, "$pkg_version$arch_str" ); + } else { + my $short_desc = gettext( "Package not available" ); + push @res_pkgs, dep_item( undef, $p_name, "$pkg_version$arch_str", $short_desc ); + } + + } + + $res .= "\n".join( "
    ".gettext( "or" )." ", @res_pkgs )."\n"; + } + if (@$relations) { + $res .= "
  • \n"; + $res .= "
\n"; + } else { + $res = ""; + } + return $res; +} # end print_deps + +# sub print_src_deps { +# my ( $env, $lang, $pkg, $version, $type) = @_; +# my %dep_type = ('build-depends' => 'adep', 'build-depends-indep' => 'idep' ); +# my $found = 0; +# my $res = "
    \n"; +# foreach my $dep ( @{$pkg->{versions}{$version}{$type}} ) { +# $found = 1; +# my @res_pkgs; +# $res .= "
  • \"[$dep_type{$type}]\" "; +# foreach my $or_dep ( @$dep ) { +# my $p_name = $or_dep->[0]; +# my $p = $env->{db}->get_pkg( $p_name ); +# my $p_version = $or_dep->[1] ? "(".encode_entities( $or_dep->[1] ). +# " $or_dep->[2]) " : ""; +# my $not = gettext( "not" ); +# if ($or_dep->[3]) { +# $or_dep->[3] =~ s/\s+/, /go; +# # as either all or no archs have to be prepended with +# # exlamation marks, convert the first and delete the others +# $or_dep->[3] =~ s/!\s*/$not /o; +# $or_dep->[3] =~ s/!\s*//go; +# } +# my $arch_str = $or_dep->[3] ? " [$or_dep->[3]]" : ""; +# if ( $p ) { +# if ( $p->is_virtual ) { +# my $short_desc = gettext( "Virtual package" ); +# push @res_pkgs, dep_item( "../virtual/$p_name", $p_name, "$p_version$arch_str", $short_desc ); +# } else { +# my %sections = $p->get_arch_fields( 'section', +# $env->{archs} ); +# my $section = $sections{max_unique}; +# my %desc_md5s = $p->get_arch_fields( 'description-md5', +# $env->{archs} ); +# my $short_desc = conv_desc( $lang, encode_entities( $env->{db}->get_short_desc( $desc_md5s{max_unique}, $lang ), "<>&\"" ) ); +# push @res_pkgs, dep_item( "../$section/$p_name", $p_name, "$p_version$arch_str", $short_desc ); +# } +# } else { +# my $short_desc = gettext( "Package not available" ); +# push @res_pkgs, dep_item( undef, $p_name, "$p_version$arch_str", $short_desc ); +# } +# } +# $res .= "\n".join( "
    \n".gettext( "or" )." ", @res_pkgs )."
  • \n"; +# } +# if ($found) { +# $res .= "\n
"; +# } else { +# $res = ""; +# } +# return $res; +# } # end print_src_deps + + my $ds_begin = '
'; my $ds_item_desc = '
'; my $ds_item = ':
'; diff --git a/lib/Packages/Page.pm b/lib/Packages/Page.pm index 999826f..bd74688 100644 --- a/lib/Packages/Page.pm +++ b/lib/Packages/Page.pm @@ -1,6 +1,12 @@ package Packages::Page; +use strict; +use warnings; + +use Data::Dumper; use Deb::Versions; +use Packages::CGI; +use IO::String; our $ARCHIVE_DEFAULT = ''; our $SECTION_DEFAULT = 'main'; @@ -24,15 +30,16 @@ sub new { } sub merge_data { - my ($self, $data) = @_; + my ($self, $pkg, $version, $architecture, $data) = @_; local $/ = ""; - open DATA, '<', \$data - or return; + my $strio = IO::String->new($data); my $merged = 0; - while () { + while (<$strio>) { next if /^\s*$/; - my %data = (); + my %data = ( package => $pkg, + version => $version, + architecture => $architecture ); chomp; s/\n /\377/g; while (/^(\S+):\s*(.*)\s*$/mg) { @@ -41,25 +48,96 @@ sub merge_data { $key =~ tr [A-Z] [a-z]; $data{$key} = $value; } +# debug( "Merge package:\n".Dumper(\%data), 3 ); $merged += $self->merge_package( \%data ); } close DATA; return $merged; } -our @TAKE_NEWEST = qw( description essential priority section subsection tags ); -our @STORE_ALL = qw( version source installed-size size filename md5sum +sub gettext { return $_[0]; } +sub split_name_mail { + my $string = shift; + my ( $name, $email ); + if ($string =~ /(.*?)\s*<(.*)>/o) { + $name = $1; + $email = $2; + } elsif ($string =~ /^[\w.-]*@[\w.-]*$/o) { + $name = $string; + $email = $string; + } else { + $name = gettext( 'package has bad maintainer field' ); + $email = ''; + } + $name =~ s/\s+$//o; + return ($name, $email); +} + +sub add_src_data { + my ($self, $src, $version, $data) = @_; + + local $/ = ""; + my $strio = IO::String->new($data); + my %data; + while (<$strio>) { + next if /^\s*$/; + chomp; + %data = (); + s/\n /\377/g; + while (/^(\S+):\s*(.*)\s*$/mg) { + my ($key, $value) = ($1, $2); + $value =~ s/\377/\n /g; + $key =~ tr [A-Z] [a-z]; + $data{$key} = $value; + } + } + close DATA; + + $self->{src}{name} = $src; + $self->{src}{version} = $version; + if ($data{files}) { + $data{files} =~ s/\A\s*//o; # remove leading spaces + $self->{src}{files} = []; + foreach my $sf ( split( /\n\s*/, $data{files} ) ) { + # md5, size, name + push @{$self->{src}{files}}, [ split( /\s+/, $sf) ]; + } + } + my @uploaders; + if ($data{maintainer} ||= '') { + push @uploaders, [ split_name_mail( $data{maintainer} ) ]; + } + if ($data{uploaders}) { + my @up_tmp = split( /\s*,\s*/, + $data{uploaders} ); + foreach my $up (@up_tmp) { + if ($up ne $data{maintainer}) { # weed out duplicates + push @uploaders, [ split_name_mail( $up ) ]; + } + } + } + $self->{src}{uploaders} = \@uploaders; + + return 1; +} + +our @TAKE_NEWEST = qw( description essential priority section subsection tag + archive source source-version ); +our @STORE_ALL = qw( version source source-version installed-size size + filename md5sum origin bugs suite archive section ); our @DEP_FIELDS = qw( depends pre-depends recommends suggests enhances provides conflicts ); sub merge_package { my ($self, $data) = @_; - ($data{package} && $data{version} && $data{architecture}) || return; - $self->{package} ||= $data{package}; - ($self->{package} eq $data{package}) || return; + ($data->{package} && $data->{version} && $data->{architecture}) || return; + $self->{package} ||= $data->{package}; + ($self->{package} eq $data->{package}) || return; + debug( "merge package $data->{package}/$data->{version}/$data->{architecture} into $self (".($self->{newest}||'').")", 2 ); unless ($self->{newest}) { + debug( "package $data->{package}/$data->{version}/$data->{architecture} is first to merge", 3 ); foreach my $key (@TAKE_NEWEST) { $self->{data}{$key} = $data->{$key}; } @@ -75,13 +153,16 @@ sub merge_package { return 1; } - if (my $is_newest = + debug( "package $data->{package}/$data->{version}/$data->{architecture} is subsequent merge", 3 ); + my $is_newest; + if ($is_newest = (version_cmp( $data->{version}, $self->{newest} ) > 0)) { $self->{newest} = $data->{version}; foreach my $key (@TAKE_NEWEST) { $self->{data}{$key} = $data->{$key}; } } + debug( "is_newest= ".($is_newest||0), 3 ); if (!$self->{versions}{$data->{architecture}} || $is_newest || (version_cmp( $data->{version}, @@ -95,6 +176,7 @@ sub merge_package { } } + return 1; } sub normalize_dependencies { @@ -128,19 +210,36 @@ sub parse_deps { return (\@dep_and_norm, \@dep_and); } +sub get_newest { + my ($self, $field) = @_; + + return $self->{data}{$field}; +} +sub get_src { + my ($self, $field) = @_; + + return $self->{src}{$field}; +} + +sub get_architectures { + my ($self) = @_; + + return keys %{$self->{versions}}; +} + sub get_arch_field { my ($self, $field) = @_; - my @result; + my %result; foreach (sort keys %{$self->{versions}}) { - push(@result, $self->{versions}{$_}{$field}) - if $self->{versions}{$_}{$field}; + $result{$_} = $self->{versions}{$_}{$field} + if $self->{versions}{$_}{$field}; } - return \@result; + return \%result; } -sub get_version_string { +sub get_versions { my ($self) = @_; my %versions; @@ -150,7 +249,15 @@ sub get_version_string { push @{$versions{$version}}, $_; } - my @versions = version_sort keys %versions; + return \%versions; +} + +sub get_version_string { + my ($self) = @_; + + my $versions = $self->get_versions; + my @versions = version_sort keys %$versions; + my (@v_str, $v_str, $v_str_arch); if ( scalar @versions == 1 ) { @v_str = ( [ $versions[0], undef ] ); $v_str = $versions[0]; @@ -158,8 +265,8 @@ sub get_version_string { } else { my @v_str_arch; foreach ( @versions ) { - push @v_str, [ $_, $versions{$_} ]; - push @v_str_arch, "$_ [".join(', ', @{$versions{$_}})."]"; + push @v_str, [ $_, $versions->{$_} ]; + push @v_str_arch, "$_ [".join(', ', @{$versions->{$_}})."]"; } $v_str_arch = join( ", ", @v_str_arch ); $v_str = join( ", ", @versions ); @@ -171,19 +278,20 @@ sub get_version_string { sub get_dep_field { my ($self, $dep_field) = @_; - my @architectures = ( keys %{$self->{versions}} ); + my @architectures = $self->get_architectures; my ( %dep_pkgs, %arch_deps ); foreach my $a ( @architectures ) { next unless exists $self->{dep_fields}{$a}{$dep_field}; - my (@a_deps_norm, @a_deps) = @{$self->{dep_fields}{$a}{$type}}; - for ( my $i=0; $i < $#a_deps; $i++ ) { # splitted by , - $dep_pkgs{$a_deps_norm[$i]} = $a_deps[$i]; - $arch_deps{$a}{$a_deps_norm[$i]}++; + my ($a_deps_norm, $a_deps) = @{$self->{dep_fields}{$a}{$dep_field}}; +# debug( "get_dep_field: $dep_field/$a: ".Dumper($a_deps_norm,$a_deps), 3 ); + for ( my $i=0; $i < @$a_deps; $i++ ) { # splitted by , + $dep_pkgs{$a_deps_norm->[$i]} = $a_deps->[$i]; + $arch_deps{$a}{$a_deps_norm->[$i]}++; } } @architectures = sort keys %arch_deps; -# print Dumper( \%dep_pkgs, \%arch_deps ); + # debug( "get_dep_field called:\n ".Dumper( \%dep_pkgs, \%arch_deps ), 3 ); my @deps; if ( %dep_pkgs ) { @@ -218,7 +326,7 @@ sub get_dep_field { push @deps, [ $is_old_pkgs, @res_pkgs ]; } } - return @deps; + return \@deps; } sub _compute_arch_str {