2 # Convert Sources.gz files into Sleepycat db files for efficient usage of
7 # Copyright (C) 2006 Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 my $what = $ARGV[0] ? "non-free" : "*";
26 # max. distinct results for a given package postfix
27 my $MAX_SOURCE_POSTFIXES = 100;
30 use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES );
31 &Packages::Config::init( './' );
32 my %sources_small = ();
33 my %source_names = ();
34 my %source_postfixes = ();
38 for my $archive (@ARCHIVES) {
39 for my $suite (@SUITES) {
41 print "Reading $archive/$suite...\n";
43 tie %sources_all_db, "DB_File", "$DBDIR/sources_all_$suite.db.new",
44 O_RDWR|O_CREAT, 0666, $DB_BTREE
45 or die "Error creating DB: $!";
46 open PKG, "zcat $TOPDIR/archive/$archive/$suite/$what/source/Sources.gz|";
53 while (/^(\S+):\s*(.*)\s*$/mg) {
54 my ($key, $value) = ($1, $2);
55 $value =~ s/\377/\n /g;
56 $data .= "$key: $value\n";
57 $key =~ tr [A-Z] [a-z];
60 $data .= "Archive: $archive\n";
61 $sources_all_db{"$data{'package'} $data{'version'}"}
64 $source_names{$data{'package'}} = 1;
67 my $subsection = $data{section} || '-';
68 if ($data{section} && ($data{section} =~ m=/=o)) {
69 ($section, $subsection) = split m=/=o, $data{section}, 2;
71 $data{'priority'} = "-" if not exists($data{'priority'});
72 $sources_small{$data{'package'}} .=
73 "$archive $suite $section $subsection $data{'priority'} $data{'version'}\000";
76 untie %sources_all_db;
80 print "Writing databases...\n";
82 tie %sources_small_db, "DB_File", "$DBDIR/sources_small.db.new",
83 O_RDWR|O_CREAT, 0666, $DB_BTREE
84 or die "Error creating DB: $!";
85 while (my ($k, $v) = each(%sources_small)) {
87 $sources_small_db{$k} = $v;
89 untie %sources_small_db;
91 # package names stuff:
92 for my $pkg (keys %source_names) {
93 for (my $i=0;$i<length($pkg)-1;$i++) {
94 my $before = substr($pkg, 0, $i);
95 my $after = substr($pkg, $i);
96 $before = "^" if $before eq ""; # otherwise split doesn't work properly
97 $source_postfixes{$after} .= "$before\0";
100 my %source_postfixes_db;
101 tie %source_postfixes_db, "DB_File", "$DBDIR/source_postfixes.db.new",
102 O_RDWR|O_CREAT, 0666, $DB_BTREE
103 or die "Error creating DB: $!";
104 while (my ($k, $v) = each(%source_postfixes)) {
108 $nr = length($nr) + 1; # < number of hits
109 if ($nr > $MAX_SOURCE_POSTFIXES) {
112 $source_postfixes_db{$k} = $v;
114 untie %source_postfixes_db;
116 for my $suite (@SUITES) {
117 rename("$DBDIR/sources_all_$suite.db.new", "$DBDIR/sources_all_$suite.db");
119 rename("$DBDIR/sources_small.db.new", "$DBDIR/sources_small.db");
120 rename("$DBDIR/source_postfixes.db.new", "$DBDIR/source_postfixes.db");