From: Frank Lichtenheld Date: Sat, 4 Feb 2006 21:00:17 +0000 (+0000) Subject: A minimal working version of show_package.pl (essentially porting yesterday's X-Git-Tag: switch-to-templates~173 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=91edc66c5f872b41114dc61bdefc6d89c205a183;p=deb%2Fpackages.git A minimal working version of show_package.pl (essentially porting yesterday's search_packages changes over) --- diff --git a/cgi-bin/show_package.pl b/cgi-bin/show_package.pl index bfcb905..3461399 100755 --- a/cgi-bin/show_package.pl +++ b/cgi-bin/show_package.pl @@ -21,452 +21,365 @@ use HTML::Entities; use DB_File; use Benchmark; -use lib "../lib"; - use Deb::Versions; +use Packages::CGI; use Packages::Search qw( :all ); use Packages::HTML (); use Packages::Page (); -my $HOME = "http://www.debian.org"; -my $ROOT = ""; -my $SEARCHPAGE = "http://packages.debian.org/"; -my @SUITES = qw( oldstable stable testing unstable experimental ); -my @DISTS = @SUITES; -my @SECTIONS = qw( main contrib non-free ); -my @ARCHIVES = qw( us security installer ); -my @ARCHITECTURES = qw( alpha amd64 arm hppa hurd-i386 i386 ia64 - kfreebsd-i386 mips mipsel powerpc s390 sparc ); -my %SUITES = map { $_ => 1 } @SUITES; -my %SECTIONS = map { $_ => 1 } @SECTIONS; -my %ARCHIVES = map { $_ => 1 } @ARCHIVES; -my %ARCHITECTURES = map { $_ => 1 } @ARCHITECTURES; - +&Packages::CGI::reset; $ENV{PATH} = "/bin:/usr/bin"; # Read in all the variables set by the form my $input; -if ($ARGV[0] eq 'php') { +if ($ARGV[0] && ($ARGV[0] eq 'php')) { $input = new CGI(\*STDIN); } else { $input = new CGI; } my $pet0 = new Benchmark; +my $tet0 = new Benchmark; # use this to disable debugging in production mode completly my $debug_allowed = 1; my $debug = $debug_allowed && $input->param("debug"); -$debug = 0 if not defined($debug); -$Packages::Search::debug = 1 if $debug > 1; +$debug = 0 if !defined($debug) || $debug !~ /^\d+$/o; +$Packages::CGI::debug = $debug; -# If you want, just print out a list of all of the variables and exit. -print $input->header if $debug; -# print $input->dump; -# exit; +# read the configuration +our $config_read_time ||= 0; +our $db_read_time ||= 0; +our ( $topdir, $ROOT, @SUITES, @SECTIONS, @ARCHIVES, @ARCHITECTURES ); + +# FIXME: move to own module +my $modtime = (stat( "../config.sh" ))[9]; +if ($modtime > $config_read_time) { + if (!open (C, '<', "../config.sh")) { + error( "Internal: Cannot open configuration file." ); + } + while () { + next if /^\s*\#/o; + chomp; + $topdir = $1 if /^\s*topdir="?([^\"]*)"?\s*$/o; + $ROOT = $1 if /^\s*root="?([^\"]*)"?\s*$/o; + $Packages::HTML::HOME = $1 if /^\s*home="?([^\"]*)"?\s*$/o; + $Packages::HTML::SEARCH_CGI = $1 if /^\s*searchcgi="?([^\"]*)"?\s*$/o; + $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; + @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; + @ARCHITECTURES = split(/\s+/, $1) if /^\s*architectures="?([^\"]*)"?\s*$/o; + } + close (C); + debug( "read config ($modtime > $config_read_time)" ); + $config_read_time = $modtime; +} +my $DBDIR = $topdir . "/files/db"; +my $thisscript = $Packages::HTML::SEARCH_CGI; + +if (my $path = $input->param('path')) { + my @components = map { lc $_ } split /\//, $path; + + my %SUITES = map { $_ => 1 } @SUITES; + my %SECTIONS = map { $_ => 1 } @SECTIONS; + my %ARCHIVES = map { $_ => 1 } @ARCHIVES; + my %ARCHITECTURES = map { $_ => 1 } @ARCHITECTURES; + + foreach (@components) { + if ($SUITES{$_}) { + $input->param('suite', $_); + }# elsif ($SECTIONS{$_}) { +# $input->param('section', $_); +# } elsif ($ARCHIVES{$_}) { +# $input->param('archive', $_); +# } elsif ($ARCHITECTURES{$_}) { +# $input->param('arch', $_); +# } + } +} -my %params_def = ( package => { default => undef, match => '^([a-z0-9.+-]+)$' }, - suite => { default => undef, match => '^(\w+)$' }, - #format => { default => 'html', match => '^(\w+)$' } +my ( $pkg, $suite, $format ); +my %params_def = ( package => { default => undef, match => '^([a-z0-9.+-]+)$', + var => \$pkg }, + suite => { default => undef, match => '^(\w+)$', + var => \$suite }, + format => { default => 'html', match => '^(\w+)$', + var => \$format } ); -my %params = Packages::Search::parse_params( $input, \%params_def ); +my %opts; +my %params = Packages::Search::parse_params( $input, \%params_def, \%opts ); + +$opts{h_suites} = { $suite => 1 }; +$opts{h_archs} = { map { $_ => 1 } @ARCHITECTURES }; +$opts{h_sections} = { map { $_ => 1 } @SECTIONS }; +$opts{h_archives} = { map { $_ => 1 } @ARCHIVES }; -my $format = $params{values}{format}{final}; #XXX: Don't use alternative output formats yet $format = 'html'; - if ($format eq 'html') { print $input->header; -} elsif ($format eq 'xml') { -# print $input->header( -type=>'application/rdf+xml' ); - print $input->header( -type=>'text/plain' ); } if ($params{errors}{package}) { - print "Error: package not valid or not specified" if $format eq 'html'; - exit 0; + fatal_error( "package not valid or not specified" ); } if ($params{errors}{suite}) { - print "Error: package not valid or not specified" if $format eq 'html'; - exit 0; + fatal_error( "suite not valid or not specified" ); } -my $package = $params{values}{package}{final}; -my $suite = $params{values}{suite}{final}; -# for output -if ($format eq 'html') { -print Packages::HTML::header( title => "Details of package $package in $suite" , - lang => 'en', - title_tag => "Details of package $package in $suite", - print_title_above => 1 - ); -} - -# read the configuration -my $topdir; -if (!open (C, "../config.sh")) { - print "\nInternal Error: Cannot open configuration file.\n\n" -if $format eq 'html'; - exit 0; -} -while () { - $topdir = $1 if (/^\s*topdir="?(.*)"?\s*$/); - $ROOT = $1 if /^\s*root="?(.*)"?\s*$/; -} -close (C); - -my $DBDIR = $topdir . "/files/db"; -my $DL_URL = "$package/download"; -my $FILELIST_URL = "$package/files"; +my $DL_URL = "$pkg/download"; +my $FILELIST_URL = "$pkg/files"; my $DDPO_URL = "http://qa.debian.org/developer.php?email="; +our (%packages, %packages_all); +my (@results, @non_results); + +unless (@Packages::CGI::fatal_errors) { + my $dbmodtime = (stat("$DBDIR/packages_small.db"))[9]; + if ($dbmodtime > $db_read_time) { + tie %packages, 'DB_File', "$DBDIR/packages_small.db", + O_RDONLY, 0666, $DB_BTREE + or die "couldn't tie DB $DBDIR/packages_small.db: $!"; + 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: $!"; + debug( "tied databases ($dbmodtime > $db_read_time)" ); + $db_read_time = $dbmodtime; + } -my $obj1 = tie my %packages, 'DB_File', "$DBDIR/packages_small.db", O_RDONLY, 0666, $DB_BTREE - or die "couldn't tie DB $DBDIR/packages_small.db: $!"; -my $obj2 = tie my %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: $!"; -my %allsuites = (); -my @results = (); - - -&read_entry( $package, \@results, \%allsuites ); - -if (keys %allsuites == 0) { - print "No such package"; - print "{insert link to search page with substring search}"; - exit; -} + read_entry_all( \%packages, $pkg, \@results, \@non_results, \%opts ); -# sort is gross -- only fails for experimental though -for (sort keys %allsuites) { - if ($suite eq $_) { - print "$_ | "; + unless (@results || @non_results ) { + fatal_error( "No such package". + "{insert link to search page with substring search}" ); } else { - print "$_ | "; + unless (@results) { + fatal_error( "Package not available in this suite" ); + } } } -print "
"; -if (not exists $allsuites{$suite}) { - print "Package not available in this suite"; - exit; -} -for my $entry (@results) { - print join ":", @$entry; - print "
\n"; - my ($foo, $arch, $section, $subsection, - $priority, $version) = @$entry; - print "
".$packages_all{"$package $arch $version"}."
"; -} +print Packages::HTML::header( title => "Details of package $pkg in $suite" , + lang => 'en', + title_tag => "Details of package $pkg in $suite", + print_title_above => 1 + ); -&showpackage($package); +print_errors(); +print_hints(); +print_msgs(); +print_debug(); -sub showpackage { - my ( $pkg ) = @_; +unless (@Packages::CGI::fatal_errors) { - my $env; - - my $name = $pkg->get_name; - - if ( $pkg->is_virtual ) { - print_virt_pack( @_ ); - return; +my %all_suites = map { $_->[2] => 1 } (@results, @non_results); + foreach (suites_sort(keys %all_suites)) { + if ($suite eq $_) { + print "$_ | "; + } else { + print "$_ | "; + } } + print "
"; - my @all_archs = ( @{$env->{archs}}, 'all' ); - - my $page = new Packages::Page( $name, - { architectures => $env->{archs} } ); - my $d = $page->set_data( $env->{db}, $pkg ); - - 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 );
+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"}."
"; + } - $package_page .= "

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

\n" - unless $d->{version} eq $d->{v_str_simple}; +# 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} ); - 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 ); +# my $subsuite_kw = $d->{subsuite} || $env->{distribution}; +# my $size_kw = exists $d->{sizes_deb}{i386} ? $d->{sizes_deb}{i386} : first_val($d->{sizes_deb}); - # - # 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." ) ); - } +# foreach my $lang (@{$env->{langs}}) { +# &Generated::Strings::string_lang($lang); - $package_page .= pdeplegend( [ 'dep', gettext( 'depends' ) ], - [ 'rec', gettext( 'recommends' ) ], - [ 'sug', gettext( 'suggests' ) ], ); +# my $dirname = "$env->{dest_dir}/$d->{subsection}"; +# my $filename = "$dirname/$name.$lang.html"; - $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 ); - - # - # create data sheet - # - if($lang eq 'en') { - my $data_sheet = header( title => "$name -- Data sheet", - lang => "en", - desc => $short_desc, - keywords => "$env->{distribution}, $subsuite_kw, $d->{section}, $d->{subsection}, size:$size_kw $d->{version}" ); +# unless (( $lang eq 'en' ) +# || $env->{db}->is_translated( $name, $d->{version}, +# ${$versions{v2a}{$d->{version}}}[0], +# $lang )) { +# next; +# } +# progress() if $env->{opts}{progress}; - my $ds_title = $name; - if ( $d->{subsuite} ) { - $ds_title .= " ".marker( $d->{subsuite} ); - } - if ( $d->{section} ne 'main' ) { - $ds_title .= " ".marker( $d->{section} ); - } - $data_sheet .= title( $ds_title ); - - $data_sheet .= ds_begin; - $data_sheet .= ds_item(gettext( "Version" ), $d->{v_str_arch}); +# # +# # 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 ), "<>&\"" ); - my @uploaders = @{$d->{uploaders}}; - my ( $maint_name, $maint_email ) = @{shift @uploaders}; - $data_sheet .= ds_item(gettext( "Maintainer" ), - "".encode_entities($maint_name, '&<>')."" ); - if (@uploaders) { - my @uploaders_str; - foreach (@uploaders) { - push @uploaders_str, "[1])."\">".encode_entities($_->[0], '&<>').""; - } - $data_sheet .= ds_item(gettext( "Uploaders" ), - join( ",\n ", @uploaders_str )); - } - $data_sheet .= ds_item(gettext( "Section" ), - "{subsection}/\">$d->{subsection}"); - $data_sheet .= ds_item(gettext( "Priority" ), - "{priority}\">$d->{priority}"); - $data_sheet .= ds_item(gettext( "Essential" ), - "". - gettext("yes")."") - if $d->{essential} =~ /yes/i; - $data_sheet .= ds_item(gettext( "Source package" ), - "{src_name}\">$d->{src_name}"); - $data_sheet .= print_deps_ds( $env, $pkg, $d->{depends}, 'Depends' ); - $data_sheet .= print_deps_ds( $env, $pkg, $d->{recommends}, 'Recommends' ); - $data_sheet .= print_deps_ds( $env, $pkg, $d->{suggests}, 'Suggests' ); - $data_sheet .= print_deps_ds( $env, $pkg, $d->{enhances}, 'Enhances' ); - $data_sheet .= print_deps_ds( $env, $pkg, $d->{conflicts}, 'Conflicts' ); - $data_sheet .= print_deps_ds( $env, $pkg, $d->{provides}, 'Provides' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Depends' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Recommends' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Suggests' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Enhances' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Provides' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Conflicts' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Build-Depends' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Build-Depends-Indep' ); -# $data_sheet .= print_reverse_rel_ds( $env, $pkg, \%versions, 'Build-Conflicts' ); - -# if ( $name eq 'libc6' ) { -# use Data::Dumper; -# print STDERR Dumper( $pkg ); -# } - - $data_sheet .= ds_end; +# $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;
 	    
-	    $data_sheet .= trailer( '../..', $name );
-
-	    my $ds_filename = "$dirname/ds_$name.$lang.html";
-	    #
-	    # write file
-	    #
-	    print $data_sheet;
-	}
-    }
-}
-
-&printfooter;
-
-sub read_entry {
-    my ($key, $results, $allsuites) = @_;
-    my $result = $packages{$key};
-    foreach (split /\000/, $result) {
-	my @data = split ( /\s/, $_, 7 );
-	print "DEBUG: Considering entry ".join( ':', @data)."
" if $debug > 2; - if ($suite eq $data[0]) { - print "DEBUG: Using entry ".join( ':', @data)."
" if $debug > 2; - push @$results, [@data]; - } - $allsuites->{$data[0]} = 1; - } -} - -# TODO: move to common lib: -sub printfooter { - print < - -
-

Packages search page

- - -END - - my $pete = new Benchmark; - my $petd = timediff($pete, $pet0); - print "Total page evaluation took ".timestr($petd)."
" - if $debug_allowed; - - print $input->end_html; +# $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 ); +# } +# } } +my $tet1 = new Benchmark; +my $tetd = timediff($tet1, $tet0); +print "Total page evaluation took ".timestr($tetd)."
" + if $debug_allowed; + +my $trailer = Packages::HTML::trailer( $ROOT ); +$trailer =~ s/LAST_MODIFIED_DATE/gmtime()/e; #FIXME +print $trailer; # vim: ts=8 sw=4 diff --git a/lib/Deb/Versions.pm b/lib/Deb/Versions.pm index 4e0d99b..dbd5ba8 100644 --- a/lib/Deb/Versions.pm +++ b/lib/Deb/Versions.pm @@ -66,7 +66,7 @@ use strict; use Exporter; our @ISA = qw( Exporter ); -our @EXPORT = qw( version_cmp version_sort ); +our @EXPORT = qw( version_cmp version_sort suites_cmp suites_sort ); our $VERSION = v1.0.0; @@ -152,6 +152,22 @@ sub _lcmp { return length( $v1 ) <=> length( $v2 ); } +our @SUITES_SORT = qw( woody oldstable sarge stable stable-proposed-updates + etch testing testing-proposed-updates sid unstable + experimental warty hoary hoary-backports breezy + breezy-backports dapper ); +my $i = 100; +our %suites_sort = map { $_ => $i-- } @SUITES_SORT; + +sub suites_cmp { + return ($suites_sort{$_[0]} <=> $suites_sort{$_[1]}); +} + +sub suites_sort { + return sort { suites_cmp( $b, $a ) } @_; +} + + 1; __END__ diff --git a/lib/Packages/Page.pm b/lib/Packages/Page.pm new file mode 100644 index 0000000..999826f --- /dev/null +++ b/lib/Packages/Page.pm @@ -0,0 +1,250 @@ +package Packages::Page; + +use Deb::Versions; + +our $ARCHIVE_DEFAULT = ''; +our $SECTION_DEFAULT = 'main'; +our $SUBSECTION_DEFAULT = 'unknown'; +our $PRIORITY_DEFAULT = 'unknown'; +our $ESSENTIAL_DEFAULT = 'no'; +our $MAINTAINER_DEFAULT = 'unknown '; + +sub new { + my $classname = shift; + my $name = shift || ''; + my $config = shift || {}; + + my $self = {}; + bless( $self, $classname ); + + $self->{package} = $name; + $self->{config} = $config; + + return $self; +} + +sub merge_data { + my ($self, $data) = @_; + + local $/ = ""; + open DATA, '<', \$data + or return; + my $merged = 0; + while () { + next if /^\s*$/; + my %data = (); + chomp; + 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; + } + $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 + 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; + + unless ($self->{newest}) { + foreach my $key (@TAKE_NEWEST) { + $self->{data}{$key} = $data->{$key}; + } + foreach my $key (@STORE_ALL) { + $self->{versions}{$data->{architecture}}{$key} + = $data->{$key}; + } + foreach my $key (@DEP_FIELDS) { + $self->normalize_dependencies($key, $data); + } + $self->{newest} = $data->{version}; + + return 1; + } + + if (my $is_newest = + (version_cmp( $data->{version}, $self->{newest} ) > 0)) { + $self->{newest} = $data->{version}; + foreach my $key (@TAKE_NEWEST) { + $self->{data}{$key} = $data->{$key}; + } + } + if (!$self->{versions}{$data->{architecture}} + || $is_newest + || (version_cmp( $data->{version}, + $self->{versions}{$data->{architecture}} ) > 0)) { + foreach my $key (@STORE_ALL) { + $self->{versions}{$data->{architecture}}{$key} + = $data->{$key}; + } + foreach my $key (@DEP_FIELDS) { + $self->normalize_dependencies($key, $data); + } + } + +} + +sub normalize_dependencies { + my ($self, $dep_field, $data) = @_; + + my ($deps_norm, $deps) = parse_deps( $data->{$dep_field}||'' ); + $self->{dep_fields}{$data->{architecture}}{$dep_field} = + [ $deps_norm, $deps ]; +} + +sub parse_deps { + my ($dep_str) = @_; + + my (@dep_and_norm, @dep_and); + foreach my $dep_and (split( /\s*,\s*/m, $dep_str )) { + next if $dep_and =~ /^\s*$/; + my (@dep_or_norm, @dep_or); + foreach my $dep_or (split( /\s*\|\s*/m, $dep_and )) { + my ($pkg, $relation, $version, @arches) = ('','',''); + $pkg = $1 if $dep_or =~ s/^([a-zA-Z0-9][a-zA-Z0-9+._-]*)\s*//m; + ($relation, $version) = ($1, $2) + if $dep_or =~ s/^\(\s*(=|<=|>=|<>?)\s*([^\)]+).*\)\s*//m; + @arches = split(/\s+/m, $1) if $dep_or =~ s/^\[([^\]]+)\]\s*//m; + push @dep_or_norm, "$pkg($relation$version)[". + join(" ",sort(@arches))."]"; + push @dep_or, [ $pkg, $relation, $version, \@arches ]; + } + push @dep_and_norm, join('|',@dep_or_norm); + push @dep_and, \@dep_or; + } + return (\@dep_and_norm, \@dep_and); +} + +sub get_arch_field { + my ($self, $field) = @_; + + my @result; + foreach (sort keys %{$self->{versions}}) { + push(@result, $self->{versions}{$_}{$field}) + if $self->{versions}{$_}{$field}; + } + + return \@result; +} + +sub get_version_string { + my ($self) = @_; + + my %versions; + foreach (keys %{$self->{versions}}) { + my $version = $self->{versions}{$_}{version}; + $versions{$version} ||= []; + push @{$versions{$version}}, $_; + } + + my @versions = version_sort keys %versions; + if ( scalar @versions == 1 ) { + @v_str = ( [ $versions[0], undef ] ); + $v_str = $versions[0]; + $v_str_arch = $versions[0]; + } else { + my @v_str_arch; + foreach ( @versions ) { + push @v_str, [ $_, $versions{$_} ]; + push @v_str_arch, "$_ [".join(', ', @{$versions{$_}})."]"; + } + $v_str_arch = join( ", ", @v_str_arch ); + $v_str = join( ", ", @versions ); + } + + return ($v_str, $v_str_arch, \@v_str); +} + +sub get_dep_field { + my ($self, $dep_field) = @_; + + my @architectures = ( keys %{$self->{versions}} ); + + 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]}++; + } + } + @architectures = sort keys %arch_deps; +# print Dumper( \%dep_pkgs, \%arch_deps ); + + my @deps; + if ( %dep_pkgs ) { + my $old_pkgs = ''; + my $is_old_pkgs = 0; + foreach my $dp ( sort keys %dep_pkgs ) { + my @dp_alts = @{$dep_pkgs{$dp}}; + my ( @pkgs, $pkgs ); + foreach (@dp_alts) { push @pkgs, $_->[0]; } + $pkgs = "@pkgs"; + + unless ( $is_old_pkgs = ($pkgs eq $old_pkgs) ) { + $old_pkgs = $pkgs; + } + + my ($arch_neg, $arch_str) = _compute_arch_str ( $dp, \%arch_deps, + \@architectures ); + + my @res_pkgs; my $pkg_ix = 0; + foreach my $p_name ( @pkgs ) { + if ( $pkg_ix > 0 ) { $arch_str = ""; } + + my $pkg_version = ""; + $pkg_version = "$dep_pkgs{$dp}[$pkg_ix][1] $dep_pkgs{$dp}[$pkg_ix][2]" + if $dep_pkgs{$dp}[$pkg_ix][1]; + + + push @res_pkgs, [ $p_name, $pkg_version, $arch_neg, + $arch_str ]; + $pkg_ix++; + } + push @deps, [ $is_old_pkgs, @res_pkgs ]; + } + } + return @deps; +} + +sub _compute_arch_str { + my ( $dp, $arch_deps, $all_archs, $is_src_dep ) = @_; + + my ( @dependend_archs, @not_dependend_archs ); + my $arch_str; + foreach my $a ( @$all_archs ) { + if ( exists $arch_deps->{$a}{$dp} ) { + push @dependend_archs, $a; + } else { + push @not_dependend_archs, $a; + } + } + my $arch_neg = 0; + if ( @dependend_archs == @$all_archs ) { + $arch_str = ""; + } else { + if ( @dependend_archs > (@$all_archs/2) ) { + $arch_neg = 1; + $arch_str = join( ", ", @not_dependend_archs); + } else { + $arch_str = join( ", ", @dependend_archs); + } + } + return my @ret = ( $arch_neg, $arch_str ); +} + +1; diff --git a/lib/Packages/Search.pm b/lib/Packages/Search.pm index 31fe9d7..000dc60 100644 --- a/lib/Packages/Search.pm +++ b/lib/Packages/Search.pm @@ -56,7 +56,7 @@ our @ISA = qw( Exporter ); our @EXPORT_OK = qw( nextlink prevlink indexline resperpagelink - read_entry read_src_entry find_binaries + read_entry read_entry_all read_src_entry find_binaries do_names_search do_fulltext_search printindexline multipageheader ); our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); @@ -338,8 +338,8 @@ sub multipageheader { return ( $start, $end ); } -sub read_entry { - my ($hash, $key, $results, $opts) = @_; +sub read_entry_all { + my ($hash, $key, $results, $non_results, $opts) = @_; my $result = $hash->{$key} || ''; foreach (split /\000/, $result) { my @data = split ( /\s/, $_, 8 ); @@ -349,9 +349,16 @@ sub read_entry { && $opts->{h_sections}{$data[3]}) { debug( "Using entry ".join( ':', @data), 2); push @$results, [ $key, @data ]; + } else { + push @$non_results, [ $key, @data ]; } } } +sub read_entry { + my ($hash, $key, $results, $opts) = @_; + my @non_results; + read_entry_all( $hash, $key, $results, \@non_results, $opts ); +} sub read_src_entry { my ($hash, $key, $results, $opts) = @_; my $result = $hash->{$key} || '';