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" : "*";
27 my %sources_small = ();
29 my @suites = ('oldstable', 'stable', 'testing', 'unstable', 'experimental');
33 for my $suite (@suites) {
35 print "Reading $suite...\n";
37 tie %sources_all_db, "DB_File", "sources_all_$suite.db.new",
38 O_RDWR|O_CREAT, 0666, $DB_BTREE
39 or die "Error creating DB: $!";
40 open PKG, "zcat /org/ftp.debian.org/ftp/dists/$suite/$what/source/Sources.gz|";
47 while (/^(\S+):\s*(.*)\s*$/mg) {
48 my ($key, $value) = ($1, $2);
49 $value =~ s/\377/\n /g;
50 $data .= "$key: $value\n";
51 $key =~ tr [A-Z] [a-z];
54 $sources_all_db{"$data{'package'} $data{'version'}"}
57 my $subsection = $data{section};
58 if ($data{section} && ($data{section} =~ m=/=o)) {
59 ($section, $subsection) = split m=/=o, $data{section}, 2;
61 $sources_small{$data{'package'}} .=
62 "$suite $section $subsection $data{'priority'} $data{'version'}\000";
65 untie %sources_all_db;
68 print "Writing databases...\n";
70 tie %sources_small_db, "DB_File", "sources_small.db.new",
71 O_RDWR|O_CREAT, 0666, $DB_BTREE
72 or die "Error creating DB: $!";
73 while (my ($k, $v) = each(%sources_small)) {
75 $sources_small_db{$k} = $v;
77 untie %sources_small_db;
79 for my $suite (@suites) {
80 rename("sources_all_$suite.db.new", "sources_all_$suite.db");
82 rename("sources_small.db.new", "sources_small.db");