]> git.deb.at Git - deb/packages.git/blob - bin/parse-sources
- Add working debugging mode (1 as parameter -> do only non-free)
[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 my $what = $ARGV[0] ? "non-free" : "*";
25
26 use DB_File;
27 my %sources_small = ();
28
29 my @suites = ('oldstable', 'stable', 'testing', 'unstable', 'experimental');
30
31 $/ = "";
32
33 for my $suite (@suites) {
34
35         print "Reading $suite...\n";
36         my %sources_all_db;
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|";
41         while (<PKG>) {
42                 next if /^\s*$/;
43                 my $data = "";
44                 my %data = ();
45                 chomp;
46                 s/\n /\377/g;
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];
52                         $data{$key} = $value;
53                 }
54                 $sources_all_db{"$data{'package'} $data{'version'}"}
55                         = $data;
56                 my $section = 'main';
57                 my $subsection = $data{section};
58                 if ($data{section} && ($data{section} =~ m=/=o)) {
59                     ($section, $subsection) = split m=/=o, $data{section}, 2;
60                 }
61                 $sources_small{$data{'package'}} .=
62                         "$suite $section $subsection $data{'priority'} $data{'version'}\000";
63         }
64
65         untie %sources_all_db;
66 }
67
68 print "Writing databases...\n";
69 my %sources_small_db;
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)) {
74         $v =~ s/.$//s;
75         $sources_small_db{$k} = $v;
76 }
77 untie %sources_small_db;
78
79 for my $suite (@suites) {
80         rename("sources_all_$suite.db.new", "sources_all_$suite.db");
81 }
82 rename("sources_small.db.new", "sources_small.db");