]> git.decadent.org.uk Git - dak.git/blob - charisma
move get_maintainer to db_access.
[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.7 2001-04-03 10:01:27 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 re_split = re.compile(r"(\S+)\s+(\S+.*)")
42
43 ####################################################################################################################################
44
45 def fix_maintainer (maintainer):
46     global fixed_maintainer_cache;
47
48     if not fixed_maintainer_cache.has_key(maintainer):
49         fixed_maintainer_cache[maintainer] = utils.fix_maintainer(maintainer)[0]
50
51     return fixed_maintainer_cache[maintainer]
52
53 def get_maintainer (maintainer):
54     return fix_maintainer(db_access.get_maintainer(maintainer));
55
56 def get_maintainer_from_source (source_id):
57     global maintainer_from_source_cache
58     
59     if not maintainer_from_source_cache.has_key(source_id):
60         q = projectB.query("SELECT m.name FROM maintainer m, source s WHERE s.id = %s and s.maintainer = m.id" % (source_id));
61         maintainer = q.getresult()[0][0]
62         maintainer_from_source_cache[source_id] = fix_maintainer(maintainer)
63         
64     return maintainer_from_source_cache[source_id]
65
66 ####################################################################################################################################
67
68 def main():
69     global Cnf, projectB;
70
71     apt_pkg.init();
72     
73     Cnf = apt_pkg.newConfiguration();
74     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
75
76     extra_files = apt_pkg.ParseCommandLine(Cnf,[],sys.argv);
77
78     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]), None, None, Cnf["DB::ROUser"]);
79     db_access.init(Cnf, projectB);
80
81     for suite in Cnf.SubTree("Suite").List():
82         suite = string.lower(suite);
83         suite_priority = int(Cnf["Suite::%s::Priority" % (suite)]);
84
85         # Source packages
86         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))
87         sources = q.getresult();
88         for source in sources:
89             package = source[0];
90             version = source[1];
91             maintainer = fix_maintainer(source[2]);
92             if packages.has_key(package):
93                 if packages[package]["priority"] <= suite_priority:
94                     if apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
95                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
96             else:
97                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
98
99         # Binary packages
100         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));
101         binaries = q.getresult();
102         for binary in binaries:
103             package = binary[0];
104             source_id = binary[1];
105             version = binary[3];
106             # Use the source maintainer first; falling back on the binary maintainer as a last resort only
107             if source_id != 0:
108                 maintainer = get_maintainer_from_source(source_id);
109             else:
110                 maintainer = get_maintainer(binary[2]);
111             if packages.has_key(package):
112                 if packages[package]["priority"] <= suite_priority:
113                     if apt_pkg.VersionCompare(packages[package]["version"], version) == -1:
114                         packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
115             else:
116                 packages[package] = { "maintainer": maintainer, "priority": suite_priority, "version": version };
117
118     # Process any additional Maintainer files (e.g. from non-US or pseudo packages)
119     for filename in extra_files:
120         file = utils.open_file(filename, 'r')
121         for line in file.readlines():
122             m = re_split.match(line[:-1])
123             package = m.group(1)
124             maintainer = fix_maintainer(m.group(2))
125             if not packages.has_key(package):
126                 packages[package] = { "maintainer": maintainer, "priority": 0 }
127         file.close()
128     
129     package_keys = packages.keys()
130     package_keys.sort()
131     for package in package_keys:
132         print "%-20s %s" % (package, packages[package]["maintainer"])
133
134 if __name__ == '__main__':
135     main()
136