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
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.
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.
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
26 ################################################################################
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@
32 ################################################################################
34 from daklib import utils
35 from daklib.config import Config
36 from daklib.dbconn import *
37 from daklib.regexes import re_comments
42 ################################################################################
44 def usage (exit_code=0):
45 print """Usage: dak make-maintainers [OPTION] EXTRA_FILE[...]
46 Generate an index of packages <=> Maintainers / Uploaders.
48 -h, --help show this help and exit
52 ################################################################################
54 def format(package, person):
55 '''Return a string nicely formatted for writing to the output file.'''
56 return '%-20s %s\n' % (package, person)
58 ################################################################################
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])
64 ################################################################################
69 Arguments = [('h',"help","Make-Maintainers::Options::Help")]
70 if not cnf.has_key("Make-Maintainers::Options::Help"):
71 cnf["Make-Maintainers::Options::Help"] = ""
73 extra_files = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
74 Options = cnf.SubTree("Make-Maintainers::Options")
79 session = DBConn().session()
81 # dictionary packages to maintainer names
83 # dictionary packages to list of uploader names
86 source_query = session.query(DBSource).from_statement('''
87 select distinct on (source) * from source
88 order by source, version desc''')
90 binary_query = session.query(DBBinary).from_statement('''
91 select distinct on (package) * from binaries
92 order by package, version desc''')
94 for source in source_query:
95 maintainers[source.source] = source.maintainer.name
96 uploaders[source.source] = uploader_list(source)
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)
103 # Process any additional Maintainer files (e.g. from pseudo
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()
111 (package, maintainer) = line.split(None, 1)
112 maintainers[package] = maintainer
113 uploaders[package] = [maintainer]
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()
124 ################################################################################
126 if __name__ == '__main__':