]> git.decadent.org.uk Git - dak.git/blob - charisma
Add new top level directories
[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, 2002, 2003, 2004  James Troup <james@nocrew.org>
5 # $Id: charisma,v 1.18 2004-06-17 15:02:02 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 pg, 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
43 def usage (exit_code=0):
44     print """Usage: charisma [OPTION] EXTRA_FILE[...]
45 Generate an index of packages <=> Maintainers.
46
47   -h, --help                 show this help and exit
48 """
49     sys.exit(exit_code)
50
51 ################################################################################
52
53 def fix_maintainer (maintainer):
54     global fixed_maintainer_cache;
55
56     if not fixed_maintainer_cache.has_key(maintainer):
57         fixed_maintainer_cache[maintainer] = utils.fix_maintainer(maintainer)[0]
58
59     return fixed_maintainer_cache[maintainer]
60
61 def get_maintainer (maintainer):
62     return fix_maintainer(db_access.get_maintainer(maintainer));
63
64 def get_maintainer_from_source (source_id):
65     global maintainer_from_source_cache
66
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)
71
72     return maintainer_from_source_cache[source_id]
73
74 ################################################################################
75
76 def main():
77     global Cnf, projectB;
78
79     Cnf = utils.get_conf()
80
81     Arguments = [('h',"help","Charisma::Options::Help")];
82     if not Cnf.has_key("Charisma::Options::Help"):
83         Cnf["Charisma::Options::Help"] = "";
84
85     extra_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
86     Options = Cnf.SubTree("Charisma::Options");
87
88     if Options["Help"]:
89         usage();
90
91     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
92     db_access.init(Cnf, projectB);
93
94     for suite in Cnf.SubTree("Suite").List():
95         suite = suite.lower();
96         suite_priority = int(Cnf["Suite::%s::Priority" % (suite)]);
97
98         # Source packages
99         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))
100         sources = q.getresult();
101         for source in sources:
102             package = source[0];
103             version = source[1];
104             maintainer = fix_maintainer(source[2]);
105             if packages.has_key(package):
106                 if packages[package]["priority"] <= suite_priority:
107                     if apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
108                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
109             else:
110                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
111
112         # Binary packages
113         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));
114         binaries = q.getresult();
115         for binary in binaries:
116             package = binary[0];
117             source_id = binary[1];
118             version = binary[3];
119             # Use the source maintainer first; falling back on the binary maintainer as a last resort only
120             if source_id:
121                 maintainer = get_maintainer_from_source(source_id);
122             else:
123                 maintainer = get_maintainer(binary[2]);
124             if packages.has_key(package):
125                 if packages[package]["priority"] <= suite_priority:
126                     if apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
127                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
128             else:
129                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
130
131     # Process any additional Maintainer files (e.g. from non-US or pseudo packages)
132     for filename in extra_files:
133         file = utils.open_file(filename);
134         for line in file.readlines():
135             line = utils.re_comments.sub('', line).strip();
136             if line == "":
137                 continue;
138             split = line.split();
139             lhs = split[0];
140             maintainer = fix_maintainer(" ".join(split[1:]));
141             if lhs.find('~') != -1:
142                 (package, version) = lhs.split('~');
143             else:
144                 package = lhs;
145                 version = '*';
146             # A version of '*' overwhelms all real version numbers
147             if not packages.has_key(package) or version == '*' \
148                or apt_pkg.VersionCompare(packages[package]["version"], version) < 0:
149                 packages[package] = { "maintainer": maintainer, "version": version };
150         file.close();
151
152     package_keys = packages.keys()
153     package_keys.sort()
154     for package in package_keys:
155         lhs = "~".join([package, packages[package]["version"]]);
156         print "%-30s %s" % (lhs, packages[package]["maintainer"]);
157
158 ################################################################################
159
160 if __name__ == '__main__':
161     main()
162