]> git.deb.at Git - deb/packages.git/blob - bin/build-maintainerdb
Add mail stuff from old code
[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  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 # read the configuration
27 if (!open (C, "../config.sh")) {
28     printf "\nInternal Error: Cannot open configuration file.\n\n";
29     exit 0;
30 }
31 while (<C>) {
32     $topdir = $1 if (/^\s*topdir="?(.*)"?\s*$/);
33 }
34 close (C);
35
36 $maintainerfile = "$topdir/archive/Maintainers";
37 $maintainerdb = "$topdir/files/maintainerdb";
38 $overridefile = "$topdir/conf/maintainerdb.override";
39
40 sub package_maintainer
41 {
42     my $pkg = shift;
43     my $login = shift;
44     my $addr = shift;
45     my $home = "/debian/home/$login";
46
47     if (-d $home) {
48         if (-f "$home/.forward-$pkg") {
49             return "$login-$pkg\@master.debian.org";
50         }
51     }
52     return $addr;
53 }
54
55 sub read_maintainer
56 {
57     my $file = shift;
58     my $package;
59     my $maintainer;
60     my $maint;
61
62     open (F, "$file") || die "Can't open $file, $!";
63     printf "Reading %s\n", $file if ($opt_verbose);
64     while (<F>) {
65         next if (/^#/);
66         next if (/^$/);
67         /(\S+)\s+(.*)/;
68         $package=$1; $maint=$2;
69         if (! exists $maint{$package}) {
70             printf "  EVAL (%s, \"%s\")\n", $package, $maint if ($opt_verbose > 2);
71
72                 if (exists $maint{$package}) {
73                     $maint{$package} .= " ";
74                     printf "  EXPAND (%s)\n", $package if ($opt_verbose > 2);
75                 }
76                 if ($maint =~ /.*<(.*)>/) {
77                     $maint{$package} .= $1;
78                     printf "  ADD (%s, %s)\n", $package, $1 if ($opt_verbose > 2);
79                 } elsif ($maint =~ /\s*(\S+)\s+\(.*\)/) {
80                     $maint{$package} .= $1;
81                     printf "  ADD (%s, %s)\n", $package, $1 if ($opt_verbose > 2);
82                 } else {
83                     $maint{$package} .= $maint;
84                     printf "  ADD (%s, %s)\n", $package, $maint if ($opt_verbose > 2);
85                 }
86
87             printf "  %s: %s\n", $package, $maint{$package} if ($opt_verbose > 1);
88             $pkgshort = "";
89             if ($package =~ /(.*[^\d\.]+)([\d\.]*\d)$/) {
90                 $pkgshort = $1;
91                 $maint{$pkgshort} = $maint{$package} if (! exists $maint{$pkgshort});
92                 printf "  %s: %s\n", $pkgshort, $maint{$package} if ($opt_verbose > 1);
93             }
94             if ($maint{$package} =~ /([^\@]+)\@(master\.)?debian\.org/) {
95                 $addrsave = $maint{$package} if ($opt_verbose > 1);
96                 $maint{$package} = package_maintainer ($package, $1, $maint{$package});
97                 printf "  Changed to %s\n", $maint{$package} if ($opt_verbose > 1 && ($addrsave ne $maint{$package}));
98                 if (length ($pkgshort) > 0) {
99                     $maint{$pkgshort} = package_maintainer ($pkg, $1, $maint{$pkgshort});
100                 }
101             }
102         } else {
103             printf "Skipping double $package\n" if ($opt_verbose);
104             printf "LINE: $_" if ($opt_verbose > 2);
105         }
106     }
107     close (F);
108 }
109
110 sub write_maintainer
111 {
112     my $file = shift;
113
114     printf "Writing to %s.new\n", $file if ($opt_verbose > 0);
115     open (CONF, ">$file.new") || die "Can't open $file.new, $!";
116     foreach $package (sort(keys(%maint))) {
117         printf "%s -> %s\n", $package, $maint{$package} if ($opt_verbose > 1);
118         printf CONF "%s:%s\n", $package, $maint{$package};
119     }
120     close (CONF);
121     printf "Renaming to %s\n", $file if ($opt_verbose > 0);
122     system "mv -f $file.new $file";
123 }
124
125 sub help
126 {
127     print "build-maintainerdb - Build the maintainer db for packages.debian.org.\n";
128     print "-d     debug, changes output file to ./maintainerdb\n";
129     print "-h     This help\n";
130     print "-v     Increase verbosity by 1\n";
131     print "-vv    Increase verbosity by 2\n";
132     print "-vvv   Increase verbosity by 3\n";
133 }
134
135
136 # Main program
137 #
138 $opt_verbose = 0;
139 while ($#ARGV > -1) {
140     if ($ARGV[0] eq "-v") {
141         $opt_verbose++;
142     } elsif ($ARGV[0] eq "-vv") {
143         $opt_verbose+= 2;
144     } elsif ($ARGV[0] eq "-vvv") {
145         $opt_verbose+= 3;
146     } elsif ($ARGV[0] eq "-h") {
147         help();
148     } elsif ($ARGV[0] eq "-d") {
149         $maintainerdb = "./maintainerdb";
150     }
151     shift;
152 }
153
154 &read_maintainer ($overridefile);
155 &read_maintainer ($maintainerfile);
156
157 &write_maintainer ($maintainerdb);
158