]> git.deb.at Git - deb/packages.git/blobdiff - bin/parse-packages
Change _small.db layout a bit, to include virtual packages consisely at the
[deb/packages.git] / bin / parse-packages
index 38c83e988fbfcc8e890d44a30bbe47b5030c5708..b3aab25fff2ee63b7e779edb86a2928023cba511 100755 (executable)
 use strict;
 use lib './lib';
 
+$| = 1;
+
 my $what = $ARGV[0] ? "non-free" : "*";
 # max. distinct results for a given package postfix
 my $MAX_PACKAGE_POSTFIXES = 100;
 
 use DB_File;
 use Storable;
+use Deb::Versions;
 use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES );
 &Packages::Config::init( './' );
 my %packages_small = ();
+my %virtual_packages = ();
 my %package_names = ();
 my %package_postfixes = ();
 my %sources_packages = ();
@@ -48,7 +52,6 @@ $/ = "";
 for my $archive (@ARCHIVES) {
     for my $suite (@SUITES) {
 
-       my %virtual_packages = ();
        print "Reading $archive/$suite...\n";
        my %packages_all_db;
        tie %packages_all_db, "DB_File", "$DBDIR/packages_all_$suite.db.new",
@@ -72,7 +75,7 @@ for my $archive (@ARCHIVES) {
 
                if ($data{'provides'}) {
                    foreach (split /\s*,\s*/, $data{'provides'}) {
-                       $virtual_packages{$_}{$data{'package'}}++;
+                       $virtual_packages{$_}{$suite}{$data{'package'}}++;
                    }
                }
                $package_names{$data{'package'}} = 1;
@@ -112,8 +115,16 @@ for my $archive (@ARCHIVES) {
                $sections{$suite}{$archive}{$section}++;
                $subsections{$suite}{$archive}{$subsection}++;
                $priorities{$suite}{$archive}{$data{priority}}++;
-               $packages_small{$data{'package'}} .= "$archive $suite $data{'architecture'} ".
-                       "$section $subsection $data{'priority'} $data{'version'} $sdescr\000";
+               my $pkgitem = "$archive $suite $data{'architecture'} ".
+                       "$section $subsection $data{'priority'} $data{'version'} $sdescr\0";
+               my $previtem = $packages_small{$data{'package'}}{$suite}{$data{'architecture'}}
+                   || $pkgitem;
+               $packages_small{$data{'package'}}{$suite}{$data{'architecture'}} = $pkgitem
+                   if version_cmp($data{'version'}, (split /\s/o, $previtem)[6]) >= 0;
+               $previtem = $packages_small{$data{'package'}}{$suite}{'any'}
+                   || $pkgitem;
+               $packages_small{$data{'package'}}{$suite}{'any'} = $pkgitem
+                   if version_cmp($data{'version'}, (split /\s/o, $previtem)[6]) >= 0;
                $sources_packages{$src} .=
                        "$archive $suite $data{'package'} $data{'version'} $data{'architecture'}\000";
                $data{archive} = $archive;
@@ -128,11 +139,6 @@ for my $archive (@ARCHIVES) {
                        = $data;
        }
 
-       foreach (keys %virtual_packages) {
-           my @provided_by = keys %{$virtual_packages{$_}};
-           $packages_small{$_} .= "$archive $suite virtual v v v v @provided_by\000";
-       }
-
        untie %packages_all_db;
     }
 }
@@ -142,9 +148,28 @@ my %packages_small_db;
 tie %packages_small_db, "DB_File", "$DBDIR/packages_small.db.new",
        O_RDWR|O_CREAT, 0666, $DB_BTREE
        or die "Error creating DB: $!";
-while (my ($k, $v) = each(%packages_small)) {
-       $v =~ s/.$//s;
-       $packages_small_db{$k} = $v;
+while (my ($pkg, $v) = each(%packages_small)) {
+       my ($res1, $res2, $res3) = ("", "", "");
+       while (my ($suite, $v2) = each %$v) {
+           $res2 .= $v2->{'any'};
+           while (my ($arch, $v3) = each %$v2) {
+               next if $arch eq 'any' or $v3 eq $v2->{'any'};
+               $res3 .= $v3;
+           }
+       }
+       
+       if (exists $virtual_packages{$pkg}) {
+               while (my ($suite, $v2) = each %{$virtual_packages{$pkg}}) {
+                       $res1 .= "$suite\01".(join ' ', keys %$v2)."\01";
+               }
+       } else {
+               $res1 .= "-\01-\01";
+       }
+       $res1 =~ s/.$/\0/s;
+
+       my $res = "$res1$res2$res3";
+       $res =~ s/.$//s;
+       $packages_small_db{$pkg} = $res;
 }
 untie %packages_small_db;
 
@@ -184,8 +209,13 @@ tie %descriptions_db, "DB_File", "$DBDIR/descriptions.db.new",
 open DESCR, ">", "$DBDIR/descriptions.txt" or die "Error creating descriptions textfile";
 for (my $i=1; $i<= $#descriptions; $i++) {
        my $plain_description = $descriptions[$i];
-       $plain_description =~ s/\n .\n/ /og;
-       $plain_description =~ s/[\n \t]+/ /og;
+# WARNING: This needs to correspond with what happens in
+# Packages/Search.pm:do_fulltext_search
+       $plain_description =~ tr [A-Z] [a-z];
+       # ensure one space on both ends
+       $plain_description = " $plain_description ";
+       $plain_description =~ s/[(),.-]+//og;
+       $plain_description =~ s#[^a-z0-9_/+]+# #og;
        print DESCR "$plain_description\n";
        $descriptions_db{$i} = $descriptions[$i];
 }