]> git.decadent.org.uk Git - dak.git/blob - dak/make_maintainers.py
Add missing stuff to make-maintainers.
[dak.git] / dak / make_maintainers.py
1 #!/usr/bin/env python
2
3 """
4 Generate Maintainers file used by e.g. the Debian Bug Tracking System
5 @contact: Debian FTP Master <ftpmaster@debian.org>
6 @copyright: 2000, 2001, 2002, 2003, 2004, 2006  James Troup <james@nocrew.org>
7 @copyright: 2011 Torsten Werner <twerner@debian.org>
8 @license: GNU General Public License version 2 or later
9
10 """
11
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 ################################################################################
27
28 # ``As opposed to "Linux sucks. Respect my academic authoritah, damn
29 #   you!" or whatever all this hot air amounts to.''
30 #                             -- ajt@ in _that_ thread on debian-devel@
31
32 ################################################################################
33
34 from daklib import utils
35 from daklib.config import Config
36 from daklib.dbconn import *
37 from daklib.regexes import re_comments
38
39 import apt_pkg
40 import sys
41
42 ################################################################################
43
44 def usage (exit_code=0):
45     print """Usage: dak make-maintainers [OPTION] EXTRA_FILE[...]
46 Generate an index of packages <=> Maintainers / Uploaders.
47
48   -h, --help                 show this help and exit
49 """
50     sys.exit(exit_code)
51
52 ################################################################################
53
54 def format(package, person):
55     '''Return a string nicely formatted for writing to the output file.'''
56     return '%-20s %s\n' % (package, person)
57
58 ################################################################################
59
60 def uploader_list(source):
61     '''Return a sorted list of uploader names for source package.'''
62     return sorted([uploader.name for uploader in source.uploaders])
63
64 ################################################################################
65
66 def main():
67     cnf = Config()
68
69     Arguments = [('h',"help","Make-Maintainers::Options::Help")]
70     if not cnf.has_key("Make-Maintainers::Options::Help"):
71         cnf["Make-Maintainers::Options::Help"] = ""
72
73     extra_files = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
74     Options = cnf.SubTree("Make-Maintainers::Options")
75
76     if Options["Help"]:
77         usage()
78
79     session = DBConn().session()
80
81     # dictionary packages to maintainer names
82     maintainers = dict()
83     # dictionary packages to list of uploader names
84     uploaders = dict()
85
86     source_query = session.query(DBSource).from_statement('''
87         select distinct on (source) * from source
88             order by source, version desc''')
89
90     binary_query = session.query(DBBinary).from_statement('''
91         select distinct on (package) * from binaries
92             order by package, version desc''')
93
94     for source in source_query:
95         maintainers[source.source] = source.maintainer.name
96         uploaders[source.source] = uploader_list(source)
97
98     for binary in binary_query:
99         if binary.package not in maintainers:
100             maintainers[binary.package] = binary.maintainer.name
101             uploaders[binary.package] = uploader_list(binary.source)
102
103     # Process any additional Maintainer files (e.g. from pseudo
104     # packages)
105     for filename in extra_files:
106         extrafile = utils.open_file(filename)
107         for line in extrafile.readlines():
108             line = re_comments.sub('', line).strip()
109             if line == "":
110                 continue
111             (package, maintainer) = line.split(None, 1)
112             maintainers[package] = maintainer
113             uploaders[package] = [maintainer]
114
115     maintainer_file = open('Maintainers', 'w')
116     uploader_file = open('Uploaders', 'w')
117     for package in sorted(uploaders):
118         maintainer_file.write(format(package, maintainers[package]))
119         for uploader in uploaders[package]:
120             uploader_file.write(format(package, uploader))
121     uploader_file.close()
122     maintainer_file.close()
123
124 ################################################################################
125
126 if __name__ == '__main__':
127     main()