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
27 my $what = $ARGV[0] ? "non-free" : "*";
28 # max. distinct results for a given package postfix
29 my $MAX_SOURCE_POSTFIXES = 100;
32 use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES );
33 &Packages::Config::init( './' );
34 my %sources_small = ();
35 my %source_names = ();
36 my %source_postfixes = ();
40 for my $archive (@ARCHIVES) {
41 for my $suite (@SUITES) {
43 print "Reading $archive/$suite...\n";
44 my %source_names_suite = ();
46 tie %sources_all_db, "DB_File", "$DBDIR/sources_all_$suite.db.new",
47 O_RDWR|O_CREAT, 0666, $DB_BTREE
48 or die "Error creating DB: $!";
49 open PKG, "zcat $TOPDIR/archive/$archive/$suite/$what/source/Sources.gz|";
56 while (/^(\S+):\s*(.*)\s*$/mg) {
57 my ($key, $value) = ($1, $2);
58 $value =~ s/\377/\n /g;
59 $key =~ tr [A-Z] [a-z];
62 $source_names{$data{'package'}} = 1;
63 $source_names_suite{$data{'package'}} = 1;
64 delete $data{'binary'};
66 $data{files} =~ s/\s*\n\s*/\01/sog;
67 $data{files} =~ s/^\01//sg;
70 my $subsection = $data{section} || '-';
71 if ($data{section} && ($data{section} =~ m=/=o)) {
72 ($section, $subsection) = split m=/=o, $data{section}, 2;
73 ($subsection, $section) = split m=/=o, $data{section}, 2
74 if $section eq 'non-US';
76 $data{'section'} = $section;
77 $data{'subsection'} = $subsection;
78 $data{'priority'} ||= "-";
79 $sources_small{$data{'package'}} .=
80 "$archive $suite $section $subsection $data{'priority'} $data{'version'}\000";
82 while (my ($key, $value) = each (%data)) {
83 next if $key eq 'package' or $key eq 'archive' or $key eq 'suite';
84 print STDERR "WARN: $key ($suite/$archive/$data{package}/$data{architecture}\n" unless defined $value;
85 $data .= "$key\00$value\00";
88 $sources_all_db{"$archive $suite $data{'package'}"}
91 open NAMES, '>>', "$DBDIR/source_names_$suite.txt.new"
92 or die "Error creating source names list: $!";
93 foreach (sort keys %source_names_suite) {
98 untie %sources_all_db;
102 print "Writing databases...\n";
103 my %sources_small_db;
104 tie %sources_small_db, "DB_File", "$DBDIR/sources_small.db.new",
105 O_RDWR|O_CREAT, 0666, $DB_BTREE
106 or die "Error creating DB: $!";
107 while (my ($k, $v) = each(%sources_small)) {
109 $sources_small_db{$k} = $v;
111 untie %sources_small_db;
113 # package names stuff:
114 for my $pkg (keys %source_names) {
115 for (my $i=0;$i<length($pkg)-1;$i++) {
116 my $before = substr($pkg, 0, $i);
117 my $after = substr($pkg, $i);
118 $before = "^" if $before eq ""; # otherwise split doesn't work properly
119 $source_postfixes{$after} .= "$before\0";
122 my %source_postfixes_db;
123 tie %source_postfixes_db, "DB_File", "$DBDIR/source_postfixes.db.new",
124 O_RDWR|O_CREAT, 0666, $DB_BTREE
125 or die "Error creating DB: $!";
126 while (my ($k, $v) = each(%source_postfixes)) {
130 $nr = length($nr) + 1; # < number of hits
131 if ($nr > $MAX_SOURCE_POSTFIXES) {
134 $source_postfixes_db{$k} = $v;
136 untie %source_postfixes_db;
138 for my $suite (@SUITES) {
139 rename("$DBDIR/sources_all_$suite.db.new", "$DBDIR/sources_all_$suite.db");
140 rename("$DBDIR/source_names_$suite.txt.new", "$DBDIR/source_names_$suite.txt");
142 rename("$DBDIR/sources_small.db.new", "$DBDIR/sources_small.db");
143 rename("$DBDIR/source_postfixes.db.new", "$DBDIR/source_postfixes.db");