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.11 2001-09-27 01:23:41 troup Exp $
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.
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.
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
21 ################################################################################
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@
27 ################################################################################
29 import os, pg, re, string, sys
30 import db_access, utils
33 ################################################################################
37 maintainer_from_source_cache = {}
39 fixed_maintainer_cache = {}
41 ################################################################################
43 def usage (exit_code=0):
44 print """Usage: charisma [OPTION] EXTRA_FILE[...]
45 Generate an index of packages <=> Maintainers.
47 -h, --help show this help and exit
51 ################################################################################
53 def fix_maintainer (maintainer):
54 global fixed_maintainer_cache;
56 if not fixed_maintainer_cache.has_key(maintainer):
57 fixed_maintainer_cache[maintainer] = utils.fix_maintainer(maintainer)[0]
59 return fixed_maintainer_cache[maintainer]
61 def get_maintainer (maintainer):
62 return fix_maintainer(db_access.get_maintainer(maintainer));
64 def get_maintainer_from_source (source_id):
65 global maintainer_from_source_cache
67 if not maintainer_from_source_cache.has_key(source_id):
68 q = projectB.query("SELECT m.name FROM maintainer m, source s WHERE s.id = %s and s.maintainer = m.id" % (source_id));
69 maintainer = q.getresult()[0][0]
70 maintainer_from_source_cache[source_id] = fix_maintainer(maintainer)
72 return maintainer_from_source_cache[source_id]
74 ################################################################################
81 Cnf = apt_pkg.newConfiguration();
82 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
84 Arguments = [('h',"help","Charisma::Options::Help")];
85 Cnf["Charisma::Options::Help"] = "";
86 extra_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
87 Options = Cnf.SubTree("Charisma::Options");
92 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
93 db_access.init(Cnf, projectB);
95 for suite in Cnf.SubTree("Suite").List():
96 suite = string.lower(suite);
97 suite_priority = int(Cnf["Suite::%s::Priority" % (suite)]);
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:
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) == -1:
109 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
111 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
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:
118 source_id = binary[1];
120 # Use the source maintainer first; falling back on the binary maintainer as a last resort only
121 if source_id != 0 and source_id != None:
122 maintainer = get_maintainer_from_source(source_id);
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) == -1:
128 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
130 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
132 # Process any additional Maintainer files (e.g. from non-US or pseudo packages)
133 for filename in extra_files:
134 file = utils.open_file(filename);
135 for line in file.readlines():
136 line = string.strip(utils.re_comments.sub('', line[:-1]))
139 split = string.split(line);
141 maintainer = fix_maintainer(string.join(split[1:]));
142 if string.find(lhs,'~') != -1:
143 lhs_split = string.split(lhs, '~');
144 package = lhs_split[0];
145 version = lhs_split[1];
149 # A version of '*' overwhelms all real version numbers
150 if not packages.has_key(package) or version == '*' \
151 or apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
152 packages[package] = { "maintainer": maintainer, "version": version };
155 package_keys = packages.keys()
157 for package in package_keys:
158 lhs = string.join([package, packages[package]["version"]], '~');
159 print "%-30s %s" % (lhs, packages[package]["maintainer"]);
161 ################################################################################
163 if __name__ == '__main__':