X-Git-Url: https://git.deb.at/?p=deb%2Fpackages.git;a=blobdiff_plain;f=bin%2Fparse-sources;h=658e2c10daf60f8b3d9e31886c5e052bed62baf1;hp=82716b3c35216d54728cf03fa423377ef546786b;hb=89c17478db69effd1c96f4e284ad46f5b4d72c17;hpb=f7dae3f81707c8cab707df20ba2742a0087baf33 diff --git a/bin/parse-sources b/bin/parse-sources index 82716b3..658e2c1 100755 --- a/bin/parse-sources +++ b/bin/parse-sources @@ -2,8 +2,6 @@ # Convert Sources.gz files into Sleepycat db files for efficient usage of # data # -# $Id$ -# # Copyright (C) 2006 Jeroen van Wolffelaar # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,33 +15,43 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; +use lib './lib'; + +$| = 1; my $what = $ARGV[0] ? "non-free" : "*"; # max. distinct results for a given package postfix my $MAX_SOURCE_POSTFIXES = 100; use DB_File; +use File::Path; +use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES ); +&Packages::Config::init( './' ); my %sources_small = (); my %source_names = (); my %source_postfixes = (); -my @archives = ( 'us', 'non-US', 'security', 'volatile', 'backports' ); -my @suites = ('oldstable', 'stable', 'testing', 'unstable', 'experimental'); - $/ = ""; -for my $archive (@archives) { - for my $suite (@suites) { +-d $DBDIR || mkpath( $DBDIR ); + +for my $archive (@ARCHIVES) { + for my $suite (@SUITES) { print "Reading $archive/$suite...\n"; + my %source_names_suite = (); my %sources_all_db; - tie %sources_all_db, "DB_File", "sources_all_$suite.db.new", + tie %sources_all_db, "DB_File", "$DBDIR/sources_all_$suite.db.new", O_RDWR|O_CREAT, 0666, $DB_BTREE or die "Error creating DB: $!"; - open PKG, "zcat /org/packages.debian.org/archive/$archive/$suite/$what/source/Sources.gz|"; + if (!-d "$TOPDIR/archive/$archive/$suite/") { + print "\tseems not to exist, skipping...\n"; + next; + } + open PKG, "zcat $TOPDIR/archive/$archive/$suite/$what/source/Sources.gz|"; while () { next if /^\s*$/; my $data = ""; @@ -53,25 +61,42 @@ for my $archive (@archives) { while (/^(\S+):\s*(.*)\s*$/mg) { my ($key, $value) = ($1, $2); $value =~ s/\377/\n /g; - $data .= "$key: $value\n"; $key =~ tr [A-Z] [a-z]; $data{$key} = $value; } - $data .= "Archive: $archive\n"; - $sources_all_db{"$data{'package'} $data{'version'}"} - = $data; - $source_names{$data{'package'}} = 1; + $source_names_suite{$data{'package'}} = 1; + delete $data{'binary'}; + + $data{files} =~ s/\s*\n\s*/\01/sog; + $data{files} =~ s/^\01//sg; 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'}); + $data{'section'} = $section; + $data{'subsection'} = $subsection; + $data{'priority'} ||= "-"; $sources_small{$data{'package'}} .= "$archive $suite $section $subsection $data{'priority'} $data{'version'}\000"; + + while (my ($key, $value) = each (%data)) { + next if $key eq 'package' or $key eq 'archive' or $key eq 'suite'; + print STDERR "WARN: $key ($suite/$archive/$data{package}/$data{architecture}\n" unless defined $value; + $data .= "$key\00$value\00"; + } + $data =~ s/.$//so; + $sources_all_db{"$archive $suite $data{'package'}"} + = $data; + } + open NAMES, '>>', "$DBDIR/source_names_$suite.txt.new" + or die "Error creating source names list: $!"; + foreach (sort keys %source_names_suite) { + print NAMES "$_\n"; } + close NAMES; untie %sources_all_db; } @@ -79,7 +104,7 @@ for my $archive (@archives) { print "Writing databases...\n"; my %sources_small_db; -tie %sources_small_db, "DB_File", "sources_small.db.new", +tie %sources_small_db, "DB_File", "$DBDIR/sources_small.db.new", O_RDWR|O_CREAT, 0666, $DB_BTREE or die "Error creating DB: $!"; while (my ($k, $v) = each(%sources_small)) { @@ -98,23 +123,23 @@ for my $pkg (keys %source_names) { } } my %source_postfixes_db; -tie %source_postfixes_db, "DB_File", "source_postfixes.db.new", +tie %source_postfixes_db, "DB_File", "$DBDIR/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 + my $nr = ($v =~ tr/\000/\000/) + 1; if ($nr > $MAX_SOURCE_POSTFIXES) { - $v = "\001" . $nr; + $v = ($v =~ /\^/) ? "^\001" . $nr + : "\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"); +for my $suite (@SUITES) { + rename("$DBDIR/sources_all_$suite.db.new", "$DBDIR/sources_all_$suite.db"); + rename("$DBDIR/source_names_$suite.txt.new", "$DBDIR/source_names_$suite.txt"); } -rename("sources_small.db.new", "sources_small.db"); -rename("source_postfixes.db.new", "source_postfixes.db"); +rename("$DBDIR/sources_small.db.new", "$DBDIR/sources_small.db"); +rename("$DBDIR/source_postfixes.db.new", "$DBDIR/source_postfixes.db");