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 -h, --help show this help and exit
54 ################################################################################
56 def format(package, person):
57 '''Return a string nicely formatted for writing to the output file.'''
58 return '%-20s %s\n' % (package, person)
60 ################################################################################
62 def uploader_list(source):
63 '''Return a sorted list of uploader names for source package.'''
64 return sorted([uploader.name for uploader in source.uploaders])
66 ################################################################################
71 Arguments = [('h',"help","Make-Maintainers::Options::Help"),
72 ('a','archive','Make-Maintainers::Options::Archive','HasArg')]
73 if not cnf.has_key("Make-Maintainers::Options::Help"):
74 cnf["Make-Maintainers::Options::Help"] = ""
76 extra_files = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
77 Options = cnf.subtree("Make-Maintainers::Options")
79 if Options["Help"] or not Options.get('Archive'):
82 Logger = daklog.Logger('make-maintainers')
83 session = DBConn().session()
85 archive = session.query(Archive).filter_by(archive_name=Options['Archive']).one()
87 # dictionary packages to maintainer names
89 # dictionary packages to list of uploader names
92 source_query = session.query(DBSource).from_statement('''
93 select distinct on (source.source) source.* from source
94 join src_associations sa on source.id = sa.source
95 join suite on sa.suite = suite.id
96 where suite.archive_id = :archive_id
97 order by source.source, source.version desc''') \
98 .params(archive_id=archive.archive_id)
100 binary_query = session.query(DBBinary).from_statement('''
101 select distinct on (binaries.package) binaries.* from binaries
102 join bin_associations ba on binaries.id = ba.bin
103 join suite on ba.suite = suite.id
104 where suite.archive_id = :archive_id
105 order by binaries.package, binaries.version desc''') \
106 .params(archive_id=archive.archive_id)
108 Logger.log(['sources'])
109 for source in source_query:
110 maintainers[source.source] = source.maintainer.name
111 uploaders[source.source] = uploader_list(source)
113 Logger.log(['binaries'])
114 for binary in binary_query:
115 if binary.package not in maintainers:
116 maintainers[binary.package] = binary.maintainer.name
117 uploaders[binary.package] = uploader_list(binary.source)
119 Logger.log(['files'])
120 # Process any additional Maintainer files (e.g. from pseudo
122 for filename in extra_files:
123 extrafile = utils.open_file(filename)
124 for line in extrafile.readlines():
125 line = re_comments.sub('', line).strip()
128 (package, maintainer) = line.split(None, 1)
129 maintainers[package] = maintainer
130 uploaders[package] = [maintainer]
132 maintainer_file = open('Maintainers', 'w')
133 uploader_file = open('Uploaders', 'w')
134 for package in sorted(uploaders):
135 maintainer_file.write(format(package, maintainers[package]))
136 for uploader in uploaders[package]:
137 uploader_file.write(format(package, uploader))
138 uploader_file.close()
139 maintainer_file.close()
142 ################################################################################
144 if __name__ == '__main__':