]> git.deb.at Git - deb/packages.git/blobdiff - bin/parse-sources
In postfixes db's, store empty prefix as '^' to work around weird split
[deb/packages.git] / bin / parse-sources
index 4a419058c93e647f2154409d00c69174ec9df47b..63eda09c28878304aa56ec937a66b4bf99007c26 100755 (executable)
 
 use strict;
 
+my $what = $ARGV[0] ? "non-free" : "*";
+# max. distinct results for a given package postfix
+my $MAX_SOURCE_POSTFIXES = 100;
+
 use DB_File;
+my %sources_small = ();
+my %source_names = ();
+my %source_postfixes = ();
 
 my @suites = ('oldstable', 'stable', 'testing', 'unstable', 'experimental');
 
@@ -34,7 +41,7 @@ for my $suite (@suites) {
        tie %sources_all_db, "DB_File", "sources_all_$suite.db.new",
                O_RDWR|O_CREAT, 0666, $DB_BTREE
                or die "Error creating DB: $!";
-       open PKG, "zcat /org/ftp.debian.org/ftp/dists/$suite/*/source/Sources.gz|";
+       open PKG, "zcat /org/ftp.debian.org/ftp/dists/$suite/$what/source/Sources.gz|";
        while (<PKG>) {
                next if /^\s*$/;
                my $data = "";
@@ -50,11 +57,60 @@ for my $suite (@suites) {
                }
                $sources_all_db{"$data{'package'} $data{'version'}"}
                        = $data;
+
+               $source_names{$data{'package'}} = 1;
+
+               my $section = 'main';
+               my $subsection = $data{section};
+               if ($data{section} && ($data{section} =~ m=/=o)) {
+                   ($section, $subsection) = split m=/=o, $data{section}, 2;
+               }
+               $data{'priority'} = "-" if not exists($data{'priority'});
+               $sources_small{$data{'package'}} .=
+                       "$suite $section $subsection $data{'priority'} $data{'version'}\000";
        }
 
        untie %sources_all_db;
 }
 
+print "Writing databases...\n";
+my %sources_small_db;
+tie %sources_small_db, "DB_File", "sources_small.db.new",
+       O_RDWR|O_CREAT, 0666, $DB_BTREE
+       or die "Error creating DB: $!";
+while (my ($k, $v) = each(%sources_small)) {
+       $v =~ s/.$//s;
+       $sources_small_db{$k} = $v;
+}
+untie %sources_small_db;
+
+# package names stuff:
+for my $pkg (keys %source_names) {
+       for (my $i=0;$i<length($pkg)-1;$i++) {
+               my $before = substr($pkg, 0, $i);
+               my $after = substr($pkg, $i);
+               $before = "^" if $before eq ""; # otherwise split doesn't work properly
+               $source_postfixes{$after} .= "$before\0";
+       }
+}
+my %source_postfixes_db;
+tie %source_postfixes_db, "DB_File", "source_postfixes.db.new",
+       O_RDWR|O_CREAT, 0666, $DB_BTREE
+       or die "Error creating DB: $!";
+while (my ($k, $v) = each(%source_postfixes)) {
+       $v =~ s/.$//s;
+       my $nr = $v;
+       $nr =~ s/[^\000]//g;
+       $nr = length($nr) + 1; # < number of hits
+       if ($nr > $MAX_SOURCE_POSTFIXES) {
+               $v = "\001" . $nr;
+       }
+       $source_postfixes_db{$k} = $v;
+}
+untie %source_postfixes_db;
+
 for my $suite (@suites) {
        rename("sources_all_$suite.db.new", "sources_all_$suite.db");
 }
+rename("sources_small.db.new", "sources_small.db");
+rename("source_postfixes.db.new", "source_postfixes.db");