]> git.decadent.org.uk Git - dak.git/blob - dak/make_maintainers.py
Remove files that are (no longer) generated
[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] -a ARCHIVE EXTRA_FILE[...]
47 Generate an index of packages <=> Maintainers / Uploaders.
48
49   -a, --archive=ARCHIVE      archive to take packages from
50   -s, --source               output source packages only
51   -p, --print                print package list to stdout instead of writing it to files
52   -h, --help                 show this help and exit
53 """
54     sys.exit(exit_code)
55
56 ################################################################################
57
58 def format(package, person):
59     '''Return a string nicely formatted for writing to the output file.'''
60     return '%-20s %s\n' % (package, person)
61
62 ################################################################################
63
64 def uploader_list(source):
65     '''Return a sorted list of uploader names for source package.'''
66     return sorted([uploader.name for uploader in source.uploaders])
67
68 ################################################################################
69
70 def main():
71     cnf = Config()
72
73     Arguments = [('h',"help","Make-Maintainers::Options::Help"),
74                  ('a',"archive","Make-Maintainers::Options::Archive",'HasArg'),
75                  ('s',"source","Make-Maintainers::Options::Source"),
76                  ('p',"print","Make-Maintainers::Options::Print")]
77     for i in ["Help", "Source", "Print" ]:
78         if not cnf.has_key("Make-Maintainers::Options::%s" % (i)):
79             cnf["Make-Maintainers::Options::%s" % (i)] = ""
80
81     extra_files = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
82     Options = cnf.subtree("Make-Maintainers::Options")
83
84     if Options["Help"] or not Options.get('Archive'):
85         usage()
86
87     Logger = daklog.Logger('make-maintainers')
88     session = DBConn().session()
89
90     archive = session.query(Archive).filter_by(archive_name=Options['Archive']).one()
91
92     # dictionary packages to maintainer names
93     maintainers = dict()
94     # dictionary packages to list of uploader names
95     uploaders = dict()
96
97     source_query = session.query(DBSource).from_statement('''
98         select distinct on (source.source) source.* from source
99             join src_associations sa on source.id = sa.source
100             join suite on sa.suite = suite.id
101             where suite.archive_id = :archive_id
102             order by source.source, source.version desc''') \
103         .params(archive_id=archive.archive_id)
104
105     binary_query = session.query(DBBinary).from_statement('''
106         select distinct on (binaries.package) binaries.* from binaries
107             join bin_associations ba on binaries.id = ba.bin
108             join suite on ba.suite = suite.id
109             where suite.archive_id = :archive_id
110             order by binaries.package, binaries.version desc''') \
111         .params(archive_id=archive.archive_id)
112
113     Logger.log(['sources'])
114     for source in source_query:
115         maintainers[source.source] = source.maintainer.name
116         uploaders[source.source] = uploader_list(source)
117
118     if not Options["Source"]:
119         Logger.log(['binaries'])
120         for binary in binary_query:
121                 if binary.package not in maintainers:
122                     maintainers[binary.package] = binary.maintainer.name
123                     uploaders[binary.package] = uploader_list(binary.source)
124
125     Logger.log(['files'])
126     # Process any additional Maintainer files (e.g. from pseudo
127     # packages)
128     for filename in extra_files:
129         extrafile = utils.open_file(filename)
130         for line in extrafile.readlines():
131             line = re_comments.sub('', line).strip()
132             if line == "":
133                 continue
134             (package, maintainer) = line.split(None, 1)
135             maintainers[package] = maintainer
136             uploaders[package] = [maintainer]
137
138     if Options["Print"]:
139         for package in sorted(maintainers):
140             sys.stdout.write(format(package, maintainers[package]))
141     else:
142         maintainer_file = open('Maintainers', 'w')
143         uploader_file = open('Uploaders', 'w')
144         for package in sorted(uploaders):
145             maintainer_file.write(format(package, maintainers[package]))
146             for uploader in uploaders[package]:
147                 uploader_file.write(format(package, uploader))
148         uploader_file.close()
149         maintainer_file.close()
150
151         Logger.close()
152
153 ###############################################################################
154
155 if __name__ == '__main__':
156     main()