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
24 my $what = $ARGV[0] ? "non-free" : "*";
25 # max. distinct results for a given package postfix
26 my $MAX_SOURCE_POSTFIXES = 100;
29 my %sources_small = ();
30 my %source_names = ();
31 my %source_postfixes = ();
33 my @suites = ('oldstable', 'stable', 'testing', 'unstable', 'experimental');
37 for my $suite (@suites) {
39 print "Reading $suite...\n";
41 tie %sources_all_db, "DB_File", "sources_all_$suite.db.new",
42 O_RDWR|O_CREAT, 0666, $DB_BTREE
43 or die "Error creating DB: $!";
44 open PKG, "zcat /org/ftp.debian.org/ftp/dists/$suite/$what/source/Sources.gz|";
51 while (/^(\S+):\s*(.*)\s*$/mg) {
52 my ($key, $value) = ($1, $2);
53 $value =~ s/\377/\n /g;
54 $data .= "$key: $value\n";
55 $key =~ tr [A-Z] [a-z];
58 $sources_all_db{"$data{'package'} $data{'version'}"}
61 $source_names{$data{'package'}} = 1;
64 my $subsection = $data{section};
65 if ($data{section} && ($data{section} =~ m=/=o)) {
66 ($section, $subsection) = split m=/=o, $data{section}, 2;
68 $data{'priority'} = "-" if not exists($data{'priority'});
69 $sources_small{$data{'package'}} .=
70 "$suite $section $subsection $data{'priority'} $data{'version'}\000";
73 untie %sources_all_db;
76 print "Writing databases...\n";
78 tie %sources_small_db, "DB_File", "sources_small.db.new",
79 O_RDWR|O_CREAT, 0666, $DB_BTREE
80 or die "Error creating DB: $!";
81 while (my ($k, $v) = each(%sources_small)) {
83 $sources_small_db{$k} = $v;
85 untie %sources_small_db;
87 # package names stuff:
88 for my $pkg (keys %source_names) {
89 for (my $i=0;$i<length($pkg)-1;$i++) {
90 my $before = substr($pkg, 0, $i);
91 my $after = substr($pkg, $i);
92 $before = "^" if $before eq ""; # otherwise split doesn't work properly
93 $source_postfixes{$after} .= "$before\0";
96 my %source_postfixes_db;
97 tie %source_postfixes_db, "DB_File", "source_postfixes.db.new",
98 O_RDWR|O_CREAT, 0666, $DB_BTREE
99 or die "Error creating DB: $!";
100 while (my ($k, $v) = each(%source_postfixes)) {
104 $nr = length($nr) + 1; # < number of hits
105 if ($nr > $MAX_SOURCE_POSTFIXES) {
108 $source_postfixes_db{$k} = $v;
110 untie %source_postfixes_db;
112 for my $suite (@suites) {
113 rename("sources_all_$suite.db.new", "sources_all_$suite.db");
115 rename("sources_small.db.new", "sources_small.db");
116 rename("source_postfixes.db.new", "source_postfixes.db");