]> git.decadent.org.uk Git - dak.git/blob - dak/make_maintainers.py
Merge commit 'stew/categorize-bts' into merge
[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 apt_pkg
30 from daklib import database
31 from daklib import utils
32 from daklib.regexes import re_comments
33
34 ################################################################################
35
36 projectB = None
37 Cnf = None
38 maintainer_from_source_cache = {}
39 packages = {}
40 fixed_maintainer_cache = {}
41
42 ################################################################################
43
44 def usage (exit_code=0):
45     print """Usage: dak make-maintainers [OPTION] EXTRA_FILE[...]
46 Generate an index of packages <=> Maintainers.
47
48   -h, --help                 show this help and exit
49 """
50     sys.exit(exit_code)
51
52 ################################################################################
53
54 def fix_maintainer (maintainer):
55     global fixed_maintainer_cache
56
57     if not fixed_maintainer_cache.has_key(maintainer):
58         fixed_maintainer_cache[maintainer] = utils.fix_maintainer(maintainer)[0]
59
60     return fixed_maintainer_cache[maintainer]
61
62 def get_maintainer (maintainer):
63     return fix_maintainer(database.get_maintainer(maintainer))
64
65 def get_maintainer_from_source (source_id):
66     global maintainer_from_source_cache
67
68     if not maintainer_from_source_cache.has_key(source_id):
69         q = projectB.query("SELECT m.name FROM maintainer m, source s WHERE s.id = %s and s.maintainer = m.id" % (source_id))
70         maintainer = q.getresult()[0][0]
71         maintainer_from_source_cache[source_id] = fix_maintainer(maintainer)
72
73     return maintainer_from_source_cache[source_id]
74
75 ################################################################################
76
77 def main():
78     global Cnf, projectB
79
80     Cnf = utils.get_conf()
81
82     Arguments = [('h',"help","Make-Maintainers::Options::Help")]
83     if not Cnf.has_key("Make-Maintainers::Options::Help"):
84         Cnf["Make-Maintainers::Options::Help"] = ""
85
86     extra_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
87     Options = Cnf.SubTree("Make-Maintainers::Options")
88
89     if Options["Help"]:
90         usage()
91
92     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
93     database.init(Cnf, projectB)
94
95     for suite in Cnf.SubTree("Suite").List():
96         suite = suite.lower()
97         suite_priority = int(Cnf["Suite::%s::Priority" % (suite)])
98
99         # Source packages
100         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))
101         sources = q.getresult()
102         for source in sources:
103             package = source[0]
104             version = source[1]
105             maintainer = fix_maintainer(source[2])
106             if packages.has_key(package):
107                 if packages[package]["priority"] <= suite_priority:
108                     if apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
109                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version }
110             else:
111                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version }
112
113         # Binary packages
114         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))
115         binaries = q.getresult()
116         for binary in binaries:
117             package = binary[0]
118             source_id = binary[1]
119             version = binary[3]
120             # Use the source maintainer first; falling back on the binary maintainer as a last resort only
121             if source_id:
122                 maintainer = get_maintainer_from_source(source_id)
123             else:
124                 maintainer = get_maintainer(binary[2])
125             if packages.has_key(package):
126                 if packages[package]["priority"] <= suite_priority:
127                     if apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
128                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version }
129             else:
130                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version }
131
132     # Process any additional Maintainer files (e.g. from pseudo packages)
133     for filename in extra_files:
134         extrafile = utils.open_file(filename)
135         for line in extrafile.readlines():
136             line = re_comments.sub('', line).strip()
137             if line == "":
138                 continue
139             split = line.split()
140             lhs = split[0]
141             maintainer = fix_maintainer(" ".join(split[1:]))
142             if lhs.find('~') != -1:
143                 (package, version) = lhs.split('~', 1)
144             else:
145                 package = lhs
146                 version = '*'
147             # A version of '*' overwhelms all real version numbers
148             if not packages.has_key(package) or version == '*' \
149                or apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
150                 packages[package] = { "maintainer": maintainer, "version": version }
151         extrafile.close()
152
153     package_keys = packages.keys()
154     package_keys.sort()
155     for package in package_keys:
156         lhs = "~".join([package, packages[package]["version"]])
157         print "%-30s %s" % (lhs, packages[package]["maintainer"])
158
159 ################################################################################
160
161 if __name__ == '__main__':
162     main()