]> git.decadent.org.uk Git - dak.git/blob - dak/make_maintainers.py
Enmasse adaptation for removal of silly names.
[dak.git] / dak / make_maintainers.py
1 #!/usr/bin/env python
2
3 # Generate Maintainers file used by e.g. the Debian Bug Tracking System
4 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006  James Troup <james@nocrew.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 ################################################################################
21
22 # ``As opposed to "Linux sucks. Respect my academic authoritah, damn
23 #   you!" or whatever all this hot air amounts to.''
24 #                             -- ajt@ in _that_ thread on debian-devel@
25
26 ################################################################################
27
28 import pg, sys
29 import dak.lib.database, dak.lib.utils
30 import apt_pkg
31
32 ################################################################################
33
34 projectB = None
35 Cnf = None
36 maintainer_from_source_cache = {}
37 packages = {}
38 fixed_maintainer_cache = {}
39
40 ################################################################################
41
42 def usage (exit_code=0):
43     print """Usage: dak make-maintainers [OPTION] EXTRA_FILE[...]
44 Generate an index of packages <=> Maintainers.
45
46   -h, --help                 show this help and exit
47 """
48     sys.exit(exit_code)
49
50 ################################################################################
51
52 def fix_maintainer (maintainer):
53     global fixed_maintainer_cache
54
55     if not fixed_maintainer_cache.has_key(maintainer):
56         fixed_maintainer_cache[maintainer] = dak.lib.utils.fix_maintainer(maintainer)[0]
57
58     return fixed_maintainer_cache[maintainer]
59
60 def get_maintainer (maintainer):
61     return fix_maintainer(dak.lib.database.get_maintainer(maintainer))
62
63 def get_maintainer_from_source (source_id):
64     global maintainer_from_source_cache
65
66     if not maintainer_from_source_cache.has_key(source_id):
67         q = projectB.query("SELECT m.name FROM maintainer m, source s WHERE s.id = %s and s.maintainer = m.id" % (source_id))
68         maintainer = q.getresult()[0][0]
69         maintainer_from_source_cache[source_id] = fix_maintainer(maintainer)
70
71     return maintainer_from_source_cache[source_id]
72
73 ################################################################################
74
75 def main():
76     global Cnf, projectB
77
78     Cnf = dak.lib.utils.get_conf()
79
80     Arguments = [('h',"help","Make-Maintainers::Options::Help")]
81     if not Cnf.has_key("Make-Maintainers::Options::Help"):
82         Cnf["Make-Maintainers::Options::Help"] = ""
83
84     extra_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
85     Options = Cnf.SubTree("Make-Maintainers::Options")
86
87     if Options["Help"]:
88         usage()
89
90     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
91     dak.lib.database.init(Cnf, projectB)
92
93     for suite in Cnf.SubTree("Suite").List():
94         suite = suite.lower()
95         suite_priority = int(Cnf["Suite::%s::Priority" % (suite)])
96
97         # Source packages
98         q = projectB.query("SELECT s.source, s.version, m.name FROM src_associations sa, source s, suite su, maintainer m WHERE su.suite_name = '%s' AND sa.suite = su.id AND sa.source = s.id AND m.id = s.maintainer" % (suite))
99         sources = q.getresult()
100         for source in sources:
101             package = source[0]
102             version = source[1]
103             maintainer = fix_maintainer(source[2])
104             if packages.has_key(package):
105                 if packages[package]["priority"] <= suite_priority:
106                     if apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
107                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version }
108             else:
109                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version }
110
111         # Binary packages
112         q = projectB.query("SELECT b.package, b.source, b.maintainer, b.version FROM bin_associations ba, binaries b, suite s WHERE s.suite_name = '%s' AND ba.suite = s.id AND ba.bin = b.id" % (suite))
113         binaries = q.getresult()
114         for binary in binaries:
115             package = binary[0]
116             source_id = binary[1]
117             version = binary[3]
118             # Use the source maintainer first; falling back on the binary maintainer as a last resort only
119             if source_id:
120                 maintainer = get_maintainer_from_source(source_id)
121             else:
122                 maintainer = get_maintainer(binary[2])
123             if packages.has_key(package):
124                 if packages[package]["priority"] <= suite_priority:
125                     if apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
126                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version }
127             else:
128                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version }
129
130     # Process any additional Maintainer files (e.g. from non-US or pseudo packages)
131     for filename in extra_files:
132         file = dak.lib.utils.open_file(filename)
133         for line in file.readlines():
134             line = dak.lib.utils.re_comments.sub('', line).strip()
135             if line == "":
136                 continue
137             split = line.split()
138             lhs = split[0]
139             maintainer = fix_maintainer(" ".join(split[1:]))
140             if lhs.find('~') != -1:
141                 (package, version) = lhs.split('~')
142             else:
143                 package = lhs
144                 version = '*'
145             # A version of '*' overwhelms all real version numbers
146             if not packages.has_key(package) or version == '*' \
147                or apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
148                 packages[package] = { "maintainer": maintainer, "version": version }
149         file.close()
150
151     package_keys = packages.keys()
152     package_keys.sort()
153     for package in package_keys:
154         lhs = "~".join([package, packages[package]["version"]])
155         print "%-30s %s" % (lhs, packages[package]["maintainer"])
156
157 ################################################################################
158
159 if __name__ == '__main__':
160     main()
161