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 daklog
35 from daklib import utils
36 from daklib.config import Config
37 from daklib.dbconn import *
38 from daklib.regexes import re_comments
43 ################################################################################
45 def usage (exit_code=0):
46 print """Usage: dak make-maintainers [OPTION] -a ARCHIVE EXTRA_FILE[...]
47 Generate an index of packages <=> Maintainers / Uploaders.
49 -a, --archive=ARCHIVE archive to take packages from
50 -s, --source output source packages only
51 -h, --help show this help and exit
55 ################################################################################
57 def format(package, person):
58 '''Return a string nicely formatted for writing to the output file.'''
59 return '%-20s %s\n' % (package, person)
61 ################################################################################
63 def uploader_list(source):
64 '''Return a sorted list of uploader names for source package.'''
65 return sorted([uploader.name for uploader in source.uploaders])
67 ################################################################################
72 Arguments = [('h',"help","Make-Maintainers::Options::Help"),
73 ('a',"archive","Make-Maintainers::Options::Archive",'HasArg'),
74 ('s',"source","Make-Maintainers::Options::Source")]
75 for i in ["Help", "Source" ]:
76 if not cnf.has_key("Make-Maintainers::Options::%s" % (i)):
77 cnf["Make-Maintainers::Options::%s" % (i)] = ""
79 extra_files = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
80 Options = cnf.subtree("Make-Maintainers::Options")
82 if Options["Help"] or not Options.get('Archive'):
85 Logger = daklog.Logger('make-maintainers')
86 session = DBConn().session()
88 archive = session.query(Archive).filter_by(archive_name=Options['Archive']).one()
90 # dictionary packages to maintainer names
92 # dictionary packages to list of uploader names
95 source_query = session.query(DBSource).from_statement('''
96 select distinct on (source.source) source.* from source
97 join src_associations sa on source.id = sa.source
98 join suite on sa.suite = suite.id
99 where suite.archive_id = :archive_id
100 order by source.source, source.version desc''') \
101 .params(archive_id=archive.archive_id)
103 binary_query = session.query(DBBinary).from_statement('''
104 select distinct on (binaries.package) binaries.* from binaries
105 join bin_associations ba on binaries.id = ba.bin
106 join suite on ba.suite = suite.id
107 where suite.archive_id = :archive_id
108 order by binaries.package, binaries.version desc''') \
109 .params(archive_id=archive.archive_id)
111 Logger.log(['sources'])
112 for source in source_query:
113 maintainers[source.source] = source.maintainer.name
114 uploaders[source.source] = uploader_list(source)
116 if not Options["Source"]:
117 Logger.log(['binaries'])
118 for binary in binary_query:
119 if binary.package not in maintainers:
120 maintainers[binary.package] = binary.maintainer.name
121 uploaders[binary.package] = uploader_list(binary.source)
123 Logger.log(['files'])
124 # Process any additional Maintainer files (e.g. from pseudo
126 for filename in extra_files:
127 extrafile = utils.open_file(filename)
128 for line in extrafile.readlines():
129 line = re_comments.sub('', line).strip()
132 (package, maintainer) = line.split(None, 1)
133 maintainers[package] = maintainer
134 uploaders[package] = [maintainer]
136 maintainer_file = open('Maintainers', 'w')
137 uploader_file = open('Uploaders', 'w')
138 for package in sorted(uploaders):
139 maintainer_file.write(format(package, maintainers[package]))
140 for uploader in uploaders[package]:
141 uploader_file.write(format(package, uploader))
142 uploader_file.close()
143 maintainer_file.close()
146 ################################################################################
148 if __name__ == '__main__':