]> git.deb.at Git - deb/packages.git/blob - bin/parse-sources
4a419058c93e647f2154409d00c69174ec9df47b
[deb/packages.git] / bin / parse-sources
1 #!/usr/bin/perl -w
2 # Convert Sources.gz files into Sleepycat db files for efficient usage of
3 # data
4 #
5 # $Id$
6 #
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.
12
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.
17
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
21
22 use strict;
23
24 use DB_File;
25
26 my @suites = ('oldstable', 'stable', 'testing', 'unstable', 'experimental');
27
28 $/ = "";
29
30 for my $suite (@suites) {
31
32         print "Reading $suite...\n";
33         my %sources_all_db;
34         tie %sources_all_db, "DB_File", "sources_all_$suite.db.new",
35                 O_RDWR|O_CREAT, 0666, $DB_BTREE
36                 or die "Error creating DB: $!";
37         open PKG, "zcat /org/ftp.debian.org/ftp/dists/$suite/*/source/Sources.gz|";
38         while (<PKG>) {
39                 next if /^\s*$/;
40                 my $data = "";
41                 my %data = ();
42                 chomp;
43                 s/\n /\377/g;
44                 while (/^(\S+):\s*(.*)\s*$/mg) {
45                         my ($key, $value) = ($1, $2);
46                         $value =~ s/\377/\n /g;
47                         $data .= "$key: $value\n";
48                         $key =~ tr [A-Z] [a-z];
49                         $data{$key} = $value;
50                 }
51                 $sources_all_db{"$data{'package'} $data{'version'}"}
52                         = $data;
53         }
54
55         untie %sources_all_db;
56 }
57
58 for my $suite (@suites) {
59         rename("sources_all_$suite.db.new", "sources_all_$suite.db");
60 }