]> git.decadent.org.uk Git - dak.git/blob - dak/make_maintainers.py
Merge branch 'master' into merge
[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 daklog
35 from daklib import utils
36 from daklib.config import Config
37 from daklib.dbconn import *
38 from daklib.regexes import re_comments
39
40 import apt_pkg
41 import sys
42
43 ################################################################################
44
45 def usage (exit_code=0):
46     print """Usage: dak make-maintainers [OPTION] EXTRA_FILE[...]
47 Generate an index of packages <=> Maintainers / Uploaders.
48
49   -h, --help                 show this help and exit
50 """
51     sys.exit(exit_code)
52
53 ################################################################################
54
55 def format(package, person):
56     '''Return a string nicely formatted for writing to the output file.'''
57     return '%-20s %s\n' % (package, person)
58
59 ################################################################################
60
61 def uploader_list(source):
62     '''Return a sorted list of uploader names for source package.'''
63     return sorted([uploader.name for uploader in source.uploaders])
64
65 ################################################################################
66
67 def main():
68     cnf = Config()
69
70     Arguments = [('h',"help","Make-Maintainers::Options::Help")]
71     if not cnf.has_key("Make-Maintainers::Options::Help"):
72         cnf["Make-Maintainers::Options::Help"] = ""
73
74     extra_files = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
75     Options = cnf.SubTree("Make-Maintainers::Options")
76
77     if Options["Help"]:
78         usage()
79
80     Logger = daklog.Logger(cnf.Cnf, 'make-maintainers')
81     session = DBConn().session()
82
83     # dictionary packages to maintainer names
84     maintainers = dict()
85     # dictionary packages to list of uploader names
86     uploaders = dict()
87
88     source_query = session.query(DBSource).from_statement('''
89         select distinct on (source) * from source
90             order by source, version desc''')
91
92     binary_query = session.query(DBBinary).from_statement('''
93         select distinct on (package) * from binaries
94             order by package, version desc''')
95
96     Logger.log(['sources'])
97     for source in source_query:
98         maintainers[source.source] = source.maintainer.name
99         uploaders[source.source] = uploader_list(source)
100
101     Logger.log(['binaries'])
102     for binary in binary_query:
103         if binary.package not in maintainers:
104             maintainers[binary.package] = binary.maintainer.name
105             uploaders[binary.package] = uploader_list(binary.source)
106
107     Logger.log(['files'])
108     # Process any additional Maintainer files (e.g. from pseudo
109     # packages)
110     for filename in extra_files:
111         extrafile = utils.open_file(filename)
112         for line in extrafile.readlines():
113             line = re_comments.sub('', line).strip()
114             if line == "":
115                 continue
116             (package, maintainer) = line.split(None, 1)
117             maintainers[package] = maintainer
118             uploaders[package] = [maintainer]
119
120     maintainer_file = open('Maintainers', 'w')
121     uploader_file = open('Uploaders', 'w')
122     for package in sorted(uploaders):
123         maintainer_file.write(format(package, maintainers[package]))
124         for uploader in uploaders[package]:
125             uploader_file.write(format(package, uploader))
126     uploader_file.close()
127     maintainer_file.close()
128     Logger.close()
129
130 ################################################################################
131
132 if __name__ == '__main__':
133     main()