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