]> git.deb.at Git - deb/packages.git/blobdiff - cgi-bin/search_packages.pl
Make it more obvious what are static strings and what are parameters
[deb/packages.git] / cgi-bin / search_packages.pl
index 5a31a1c961e82075a9b192d158560b5871372426..c74ffc27689007cb035b47133d18287a4f5ffc15 100755 (executable)
@@ -25,6 +25,7 @@ use Deb::Versions;
 use Packages::Config qw( $DBDIR $ROOT $SEARCH_CGI $SEARCH_PAGE
                         @SUITES @SECTIONS @ARCHIVES @ARCHITECTURES );
 use Packages::CGI;
+use Packages::DB;
 use Packages::Search qw( :all );
 use Packages::HTML ();
 
@@ -48,10 +49,8 @@ my $debug = $debug_allowed && $input->param("debug");
 $debug = 0 if !defined($debug) || $debug !~ /^\d+$/o;
 $Packages::CGI::debug = $debug;
 
-# read the configuration
-our $db_read_time ||= 0;
-
 &Packages::Config::init( '../' );
+&Packages::DB::init();
 
 if (my $path = $input->param('path')) {
     my @components = map { lc $_ } split /\//, $path;
@@ -114,7 +113,7 @@ my %params = Packages::Search::parse_params( $input, \%params_def, \%opts );
 #XXX: Don't use alternative output formats yet
 $format = 'html';
 if ($format eq 'html') {
-    print $input->header;
+    print $input->header( -charset => 'utf-8' );
 }
 
 if ($params{errors}{keywords}) {
@@ -148,36 +147,8 @@ debug( "Parameter evaluation took ".timestr($petd) );
 my $st0 = new Benchmark;
 my @results;
 
-our ($obj, $s_obj, $p_obj, $sp_obj,
-     %packages, %sources, %postf, %spostf, %src2bin, %did2pkg );
-
 unless (@Packages::CGI::fatal_errors) {
 
-    my $dbmodtime = (stat("$DBDIR/packages_small.db"))[9];
-    if ($dbmodtime > $db_read_time) {
-       $obj = tie %packages, 'DB_File', "$DBDIR/packages_small.db",
-       O_RDONLY, 0666, $DB_BTREE
-           or die "couldn't tie DB $DBDIR/packages_small.db: $!";
-       $s_obj = tie %sources, 'DB_File', "$DBDIR/sources_small.db",
-       O_RDONLY, 0666, $DB_BTREE
-           or die "couldn't tie DB $DBDIR/sources_small.db: $!";
-       $p_obj = tie %postf, 'DB_File', "$DBDIR/package_postfixes.db",
-       O_RDONLY, 0666, $DB_BTREE
-           or die "couldn't tie postfix db $DBDIR/package_postfixes.db: $!";
-       $sp_obj = tie %spostf, 'DB_File', "$DBDIR/source_postfixes.db",
-       O_RDONLY, 0666, $DB_BTREE
-           or die "couldn't tie postfix db $DBDIR/source_postfixes.db: $!";
-       tie %src2bin, 'DB_File', "$DBDIR/sources_packages.db",
-       O_RDONLY, 0666, $DB_BTREE
-           or die "couldn't open $DBDIR/sources_packages.db: $!";
-       tie %did2pkg, 'DB_File', "$DBDIR/descriptions_packages.db",
-       O_RDONLY, 0666, $DB_BTREE
-           or die "couldn't tie DB $DBDIR/descriptions_packages.db: $!";
-       
-       debug( "tied databases ($dbmodtime > $db_read_time)" );
-       $db_read_time = $dbmodtime;
-    }
-
     if ($searchon eq 'names') {
        push @results, @{ do_names_search( $keyword, \%packages,
                                           $p_obj,
@@ -186,6 +157,9 @@ unless (@Packages::CGI::fatal_errors) {
        push @results, @{ do_names_search( $keyword, \%sources,
                                           $sp_obj,
                                           \&read_src_entry, \%opts ) };
+    } elsif ($searchon eq 'contents') {
+       require "./search_contents.pl";
+       &contents($input);
     } else {
        push @results, @{ do_names_search( $keyword, \%packages,
                                           $p_obj,
@@ -281,7 +255,7 @@ print_errors();
 print_hints();
 print_debug();
 if (@results) {
-    my (%pkgs, %subsect, %sect, %desc, %binaries);
+    my (%pkgs, %subsect, %sect, %desc, %binaries, %provided_by);
 
     unless ($opts{searchon} eq 'sourcenames') {
        foreach (@results) {
@@ -289,40 +263,56 @@ if (@results) {
                $priority, $version, $desc) = @$_;
        
            my ($pkg) = $pkg_t =~ m/^(.+)/; # untaint
-           $pkgs{$pkg}{$suite}{$archive}{$version}{$arch} = 1;
-           $subsect{$pkg}{$suite}{$archive}{$version} = $subsection;
-           $sect{$pkg}{$suite}{$archive}{$version} = $section
-               unless $section eq 'main';
-           
-           $desc{$pkg}{$suite}{$archive}{$version} = $desc;
+           if ($arch ne 'virtual') {
+               $pkgs{$pkg}{$suite}{$archive}{$version}{$arch} = 1;
+               $subsect{$pkg}{$suite}{$archive}{$version} = $subsection;
+               $sect{$pkg}{$suite}{$archive}{$version} = $section
+                   unless $section eq 'main';
+               
+               $desc{$pkg}{$suite}{$archive}{$version} = $desc;
+           } else {
+               $provided_by{$pkg}{$suite}{$archive} = [ split /\s+/, $desc ];
+           }
        }
 
+my @pkgs = sort(keys %pkgs, keys %provided_by);
        if ($opts{format} eq 'html') {
-           my ($start, $end) = multipageheader( $input, scalar keys %pkgs, \%opts );
-           my $count = 0;
+           #my ($start, $end) = multipageheader( $input, scalar @pkgs, \%opts );
+           print "<p>Found <em>".(scalar @pkgs)."</em> matching packages,";
+           #my $count = 0;
        
-           foreach my $pkg (sort keys %pkgs) {
-               $count++;
-               next if $count < $start or $count > $end;
+           foreach my $pkg (@pkgs) {
+               #$count++;
+               #next if $count < $start or $count > $end;
                printf "<h3>Package %s</h3>\n", $pkg;
                print "<ul>\n";
                foreach my $suite (@SUITES) {
                    foreach my $archive (@ARCHIVES) {
+                       my $path = $suite.(($archive ne 'us')?"/$archive":'');
                        if (exists $pkgs{$pkg}{$suite}{$archive}) {
                            my @versions = version_sort keys %{$pkgs{$pkg}{$suite}{$archive}};
                            my $origin_str = "";
                            if ($sect{$pkg}{$suite}{$archive}{$versions[0]}) {
-                               $origin_str .= " [<span style=\"color:red\">$sect{$pkg}{$suite}{$versions[0]}</span>]";
+                               $origin_str .= " [<span style=\"color:red\">$sect{$pkg}{$suite}{$archive}{$versions[0]}</span>]";
                            }
                            printf "<li><a href=\"$ROOT/%s/%s\">%s</a> (%s): %s   %s\n",
-                           $suite.(($archive ne 'us')?"/$archive":''), $pkg, $suite.(($archive ne 'us')?"/$archive":''), $subsect{$pkg}{$suite}{$archive}{$versions[0]},
+                           $path, $pkg, $path, $subsect{$pkg}{$suite}{$archive}{$versions[0]},
                            $desc{$pkg}{$suite}{$archive}{$versions[0]}, $origin_str;
                            
                            foreach my $v (@versions) {
                                printf "<br>%s: %s\n",
                                $v, join (" ", (sort keys %{$pkgs{$pkg}{$suite}{$archive}{$v}}) );
                            }
+                           if (my $provided_by =  $provided_by{$pkg}{$suite}{$archive}) {
+                               print '<br>also provided by: ',
+                               join( ', ', map { "<a href=\"$ROOT/$path/$_\">$_</a>"  } @$provided_by);
+                           }
                            print "</li>\n";
+                       } elsif (my $provided_by =  $provided_by{$pkg}{$suite}{$archive}) {
+                           printf "<li><a href=\"$ROOT/%s/%s\">%s</a>: Virtual package<br>",
+                           $path, $pkg, $path;
+                           print 'provided by: ',
+                           join( ', ', map { "<a href=\"$ROOT/$path/$_\">$_</a>"  } @$provided_by);
                        }
                    }
                }
@@ -343,12 +333,13 @@ if (@results) {
        }
 
        if ($opts{format} eq 'html') {
-           my ($start, $end) = multipageheader( $input, scalar keys %pkgs, \%opts );
-           my $count = 0;
+           #my ($start, $end) = multipageheader( $input, scalar keys %pkgs, \%opts );
+           print "<p>Found <em>".(scalar keys %pkgs)."</em> matching packages,";
+           #my $count = 0;
            
            foreach my $pkg (sort keys %pkgs) {
-               $count++;
-               next if ($count < $start) or ($count > $end);
+               #$count++;
+               #next if ($count < $start) or ($count > $end);
                printf "<h3>Source package %s</h3>\n", $pkg;
                print "<ul>\n";
                foreach my $suite (@SUITES) {
@@ -378,7 +369,7 @@ if (@results) {
            }
        }
     }
-    printindexline( $input, scalar keys %pkgs, \%opts );
+    #printindexline( $input, scalar keys %pkgs, \%opts );
 }
 #print_results(\@results, \%opts) if @results;;
 my $tet1 = new Benchmark;