]> git.deb.at Git - deb/packages.git/blob - bin/build-maintainerdb
- Merge in some changes by Joey
[deb/packages.git] / bin / build-maintainerdb
1 #! /usr/bin/perl
2
3 #   build-maintainerdb - convert several Packages files to maintainer database
4 #   Copyright (c) 1998,9,2001,3,4,6  Martin Schulze <joey@debian.org>
5 #
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2 of the License, or
9 #   (at your option) any later version.
10 #
11 #   This program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software
18 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 # $Id$
21
22 #   Todo:
23 #    . Read maintainer changes from overrides file(s), need to rub
24 #      out all existing entries
25
26 use strict;
27 use warnings;
28
29 # read the configuration
30 if (!open (C, "../config.sh")) {
31     print "\nInternal Error: Cannot open configuration file.\n\n";
32     exit 0;
33 }
34 my $topdir = "/org/packages.debian.org";
35 while (<C>) {
36     $topdir = $1 if (/^\s*topdir="?(.*)"?\s*$/);
37 }
38 close (C);
39
40 my $maildomain = "packages.debian.org";
41
42 my $maintainerfile = "$topdir/archive/Maintainers";
43 my $maintainerdb = "$topdir/conf/maintainer";
44 my $overridefile = "$topdir/conf/maintainerdb.override";
45 my @postcall = ( "/usr/sbin/postmap", $maintainerdb );
46 my $opt_verbose = 0;
47
48 my %maint;
49
50 sub package_maintainer
51 {
52     my $pkg = shift;
53     my $login = shift;
54     my $addr = shift;
55     my $home = "/debian/home/$login";
56
57     if (-d $home) {
58         if (-f "$home/.forward-$pkg") {
59             return "$login-$pkg\@master.debian.org";
60         }
61     }
62     return $addr;
63 }
64
65 sub read_maintainer
66 {
67     my $file = shift;
68     my $package;
69     my $maintainer;
70     my $maint;
71
72     open (F, "$file") || die "Can't open $file, $!";
73     printf "Reading %s\n", $file if ($opt_verbose);
74     while (<F>) {
75         next if (/^#/);
76         next if (/^$/);
77         /(\S+)\s+(.*)/;
78         $package=$1; $maint=$2;
79         if (! exists $maint{$package}) {
80             printf "  EVAL (%s, \"%s\")\n", $package, $maint if ($opt_verbose > 2);
81
82                 if (exists $maint{$package}) {
83                     $maint{$package} .= " ";
84                     printf "  EXPAND (%s)\n", $package if ($opt_verbose > 2);
85                 }
86                 if ($maint =~ /.*<(.*)>/) {
87                     $maint{$package} .= $1;
88                     printf "  ADD (%s, %s)\n", $package, $1 if ($opt_verbose > 2);
89                 } elsif ($maint =~ /\s*(\S+)\s+\(.*\)/) {
90                     $maint{$package} .= $1;
91                     printf "  ADD (%s, %s)\n", $package, $1 if ($opt_verbose > 2);
92                 } else {
93                     $maint{$package} .= $maint;
94                     printf "  ADD (%s, %s)\n", $package, $maint if ($opt_verbose > 2);
95                 }
96
97             printf "  %s: %s\n", $package, $maint{$package} if ($opt_verbose > 1);
98             my $pkgshort = "";
99             if ($package =~ /(.*[^\d\.]+)([\d\.]*\d)$/) {
100                 $pkgshort = $1;
101                 $maint{$pkgshort} = $maint{$package} if (! exists $maint{$pkgshort});
102                 printf "  %s: %s\n", $pkgshort, $maint{$package} if ($opt_verbose > 1);
103             }
104             if ($maint{$package} =~ /([^\@]+)\@(master\.)?debian\.org/) {
105                 my $addrsave = $maint{$package} if ($opt_verbose > 1);
106                 $maint{$package} = package_maintainer ($package, $1, $maint{$package});
107                 printf "  Changed to %s\n", $maint{$package} if ($opt_verbose > 1 && ($addrsave ne $maint{$package}));
108                 if (length ($pkgshort) > 0) {
109                     $maint{$pkgshort} = package_maintainer ($pkgshort, $1, $maint{$pkgshort});
110                 }
111             }
112         } else {
113             printf "Skipping double $package\n" if ($opt_verbose);
114             printf "LINE: $_" if ($opt_verbose > 2);
115         }
116     }
117     close (F);
118 }
119
120 sub write_maintainer
121 {
122     my $file = shift;
123
124     printf "Writing to %s.new\n", $file if ($opt_verbose > 0);
125     open (CONF, ">$file.new") || die "Can't open $file.new, $!";
126     foreach my $package (sort(keys(%maint))) {
127         printf "%s -> %s\n", $package, $maint{$package} if ($opt_verbose > 1);
128         printf CONF "%s@%s\t%s\n", $package, $maildomain, $maint{$package};
129     }
130     close (CONF);
131     printf "Renaming to %s\n", $file if ($opt_verbose > 0);
132     system "mv -f $file.new $file";
133     printf "Executing @postcall\n" if ($opt_verbose > 0);
134     system @postcall;
135 }
136
137 sub help
138 {
139     print "build-maintainerdb - Build the maintainer db for packages.debian.org.\n";
140     print "-d     debug, changes output file to ./maintainerdb\n";
141     print "-h     This help\n";
142     print "-v     Increase verbosity by 1\n";
143     print "-vv    Increase verbosity by 2\n";
144     print "-vvv   Increase verbosity by 3\n";
145 }
146
147
148 # Main program
149 #
150 while ($#ARGV > -1) {
151     if ($ARGV[0] eq "-v") {
152         $opt_verbose++;
153     } elsif ($ARGV[0] eq "-vv") {
154         $opt_verbose+= 2;
155     } elsif ($ARGV[0] eq "-vvv") {
156         $opt_verbose+= 3;
157     } elsif ($ARGV[0] eq "-h") {
158         help();
159     } elsif ($ARGV[0] eq "-d") {
160         $maintainerdb = "./maintainerdb";
161     }
162     shift;
163 }
164
165 &read_maintainer ($overridefile);
166 &read_maintainer ($maintainerfile);
167
168 &write_maintainer ($maintainerdb);
169