]> git.decadent.org.uk Git - dak.git/blob - charisma
a982e44345e4eeb7e2caa9fdd9fe0e8f74b2592a
[dak.git] / charisma
1 #!/usr/bin/env python
2
3 # Generate Maintainers file used by e.g. the Debian Bug Tracking System
4 # Copyright (C) 2000, 2001  James Troup <james@nocrew.org>
5 # $Id: charisma,v 1.5 2001-03-15 01:59:18 troup Exp $
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ####################################################################################################################################
22
23 # ``As opposed to "Linux sucks. Respect my academic authoritah, damn
24 #   you!" or whatever all this hot air amounts to.''
25 #                             -- ajt@ in _that_ thread on debian-devel@
26
27 ####################################################################################################################################
28
29 import os, pg, re, string, sys
30 import apt_pkg
31 import utils
32
33 ####################################################################################################################################
34
35 projectB = None
36 Cnf = None
37 maintainer_cache = {}
38 maintainer_from_source_cache = {}
39 packages = {}
40 fixed_maintainer_cache = {}
41
42 re_split = re.compile(r"(\S+)\s+(\S+.*)")
43
44 ####################################################################################################################################
45
46 def fix_maintainer (maintainer):
47     global fixed_maintainer_cache;
48
49     if not fixed_maintainer_cache.has_key(maintainer):
50         fixed_maintainer_cache[maintainer] = utils.fix_maintainer(maintainer)[0]
51
52     return fixed_maintainer_cache[maintainer]
53
54 def get_maintainer_from_source (source_id):
55     global maintainer_from_source_cache
56     
57     if not maintainer_from_source_cache.has_key(source_id):
58         q = projectB.query("SELECT m.name FROM maintainer m, source s WHERE s.id = %s and s.maintainer = m.id" % (source_id));
59         maintainer = q.getresult()[0][0]
60         maintainer_from_source_cache[source_id] = fix_maintainer(maintainer)
61         
62     return maintainer_from_source_cache[source_id]
63
64 def get_maintainer (maintainer_id):
65     global maintainer_cache
66     
67     if not maintainer_cache.has_key(maintainer_id):
68         q = projectB.query("SELECT name FROM maintainer WHERE id = %s" % (maintainer_id));
69         maintainer = q.getresult()[0][0]
70         maintainer_cache[maintainer_id] = fix_maintainer(maintainer)
71         
72     return maintainer_cache[maintainer_id]
73
74 ####################################################################################################################################
75
76 def main():
77     global Cnf, projectB;
78
79     apt_pkg.init();
80     
81     Cnf = apt_pkg.newConfiguration();
82     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
83
84     extra_files = apt_pkg.ParseCommandLine(Cnf,[],sys.argv);
85
86     projectB = pg.connect('projectb', Cnf["DB::Host"], int(Cnf["DB::Port"]), None, None, Cnf["DB::ROUser"]);
87
88     for suite in Cnf.SubTree("Suite").List():
89         suite = string.lower(suite);
90         suite_priority = int(Cnf["Suite::%s::Priority" % (suite)]);
91
92         # Source packages
93         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))
94         sources = q.getresult();
95         for source in sources:
96             package = source[0];
97             version = source[1];
98             maintainer = fix_maintainer(source[2]);
99             if packages.has_key(package):
100                 if packages[package]["priority"] <= suite_priority:
101                     if apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
102                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
103             else:
104                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
105
106         # Binary packages
107         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));
108         binaries = q.getresult();
109         for binary in binaries:
110             package = binary[0];
111             source_id = binary[1];
112             version = binary[3];
113             # Use the source maintainer first; falling back on the binary maintainer as a last resort only
114             if source_id != 0:
115                 maintainer = get_maintainer_from_source(source_id);
116             else:
117                 maintainer = get_maintainer(binary[2]);
118             if packages.has_key(package):
119                 if packages[package]["priority"] <= suite_priority:
120                     if apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
121                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
122             else:
123                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
124
125     # Process any additional Maintainer files (e.g. from non-US or pseudo packages)
126     for filename in extra_files:
127         file = utils.open_file(filename, 'r')
128         for line in file.readlines():
129             m = re_split.match(line[:-1])
130             package = m.group(1)
131             maintainer = fix_maintainer(m.group(2))
132             if not packages.has_key(package):
133                 packages[package] = { "maintainer": maintainer, "priority": 0 }
134         file.close()
135     
136     package_keys = packages.keys()
137     package_keys.sort()
138     for package in package_keys:
139         print "%-20s %s" % (package, packages[package]["maintainer"])
140
141 if __name__ == '__main__':
142     main()
143