]> git.decadent.org.uk Git - dak.git/blob - dak/dak.py
Remove files that are (no longer) generated
[dak.git] / dak / dak.py
1 #!/usr/bin/env python
2
3 """
4 Wrapper to launch dak functionality
5
6 G{importgraph}
7
8 """
9 # Copyright (C) 2005, 2006 Anthony Towns <ajt@debian.org>
10 # Copyright (C) 2006 James Troup <james@nocrew.org>
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 # well I don't know where you're from but in AMERICA, there's a little
29 # thing called "abstinent until proven guilty."
30 #  -- http://harrietmiers.blogspot.com/2005/10/wow-i-feel-loved.html
31
32 # (if James had a blog, I bet I could find a funny quote in it to use!)
33
34 ################################################################################
35
36 import os
37 import sys
38 import traceback
39 import daklib.utils
40
41 from daklib.daklog import Logger
42 from daklib.config import Config
43 from daklib.dak_exceptions import CantOpenError
44
45 ################################################################################
46
47 def init():
48     """Setup the list of modules and brief explanation of what they
49     do."""
50
51     functionality = [
52         ("ls",
53          "Show which suites packages are in"),
54         ("override",
55          "Query/change the overrides"),
56         ("check-archive",
57          "Archive sanity checks"),
58         ("queue-report",
59          "Produce a report on NEW and BYHAND packages"),
60         ("show-new",
61          "Output html for packages in NEW"),
62         ("show-deferred",
63          "Output html and symlinks for packages in DEFERRED"),
64         ("graph",
65          "Output graphs of number of packages in various queues"),
66
67         ("rm",
68          "Remove packages from suites"),
69
70         ("process-new",
71          "Process NEW and BYHAND packages"),
72         ("process-upload",
73          "Process packages in queue/unchecked"),
74         ("process-commands",
75          "Process command files (*.dak-commands)"),
76         ("process-policy",
77          "Process packages in policy queues from COMMENTS files"),
78
79         ("dominate",
80          "Remove obsolete source and binary associations from suites"),
81         ("export",
82          "Export uploads from policy queues"),
83         ("export-suite",
84          "export a suite to a flat directory structure"),
85         ("make-pkg-file-mapping",
86          "Generate package <-> file mapping"),
87         ("generate-releases",
88          "Generate Release files"),
89         ("generate-packages-sources2",
90          "Generate Packages/Sources files"),
91         ("contents",
92          "Generate content files"),
93         ("metadata",
94          "Load data for packages/sources files"),
95         ("generate-index-diffs",
96          "Generate .diff/Index files"),
97         ("clean-suites",
98          "Clean unused/superseded packages from the archive"),
99         ("manage-build-queues",
100          "Clean and update metadata for build queues"),
101         ("manage-debug-suites",
102          "Clean obsolete packages from debug suites"),
103         ("clean-queues",
104          "Clean cruft from incoming"),
105
106         ("transitions",
107          "Manage the release transition file"),
108         ("check-overrides",
109          "Override cruft checks"),
110         ("control-overrides",
111          "Manipulate/list override entries in bulk"),
112         ("control-suite",
113          "Manipulate suites in bulk"),
114         ("update-suite",
115          "Update suite with packages from a different suite"),
116         ("cruft-report",
117          "Check for obsolete or duplicated packages"),
118         ("auto-decruft",
119          "Clean cruft without reverse dependencies automatically"),
120         ("examine-package",
121          "Show information useful for NEW processing"),
122         ("import",
123          "Import existing source and binary packages"),
124         ("import-repository",
125          "Import packages from another repository"),
126         ("import-keyring",
127          "Populate fingerprint/uid table based on a new/updated keyring"),
128         ("import-users-from-passwd",
129          "Sync PostgreSQL users with passwd file"),
130         ("acl",
131          "Manage upload ACLs"),
132         ("admin",
133          "Perform administration on the dak database"),
134         ("update-db",
135          "Updates databae schema to latest revision"),
136         ("init-dirs",
137          "Initial setup of the archive"),
138         ("make-maintainers",
139          "Generates Maintainers file for BTS etc"),
140         ("make-overrides",
141          "Generates override files"),
142         ("new-security-install",
143          "New way to install a security upload into the archive"),
144         ("stats",
145          "Generate statistics"),
146         ("bts-categorize",
147          "Categorize uncategorized bugs filed against ftp.debian.org"),
148         ("add-user",
149          "Add a user to the archive"),
150         ("make-changelog",
151          "Generate changelog between two suites"),
152         ("copy-installer",
153          "Copies the installer from one suite to another"),
154         ("override-disparity",
155          "Generate a list of override disparities"),
156         ("external-overrides",
157          "Modify external overrides"),
158         ]
159     return functionality
160
161 ################################################################################
162
163 def usage(functionality, exit_code=0):
164     """Print a usage message and exit with 'exit_code'."""
165
166     print """Usage: dak COMMAND [...]
167 Run DAK commands.  (Will also work if invoked as COMMAND.)
168
169 Available commands:"""
170     for (command, description) in functionality:
171         print "  %-23s %s" % (command, description)
172     sys.exit(exit_code)
173
174 ################################################################################
175
176 def main():
177     """Launch dak functionality."""
178
179
180     try:
181         logger = Logger('dak top-level', print_starting=False)
182     except CantOpenError:
183         logger = None
184
185     functionality = init()
186     modules = [ command for (command, _) in functionality ]
187
188     if len(sys.argv) == 0:
189         daklib.utils.fubar("err, argc == 0? how is that possible?")
190     elif (len(sys.argv) == 1
191           or (len(sys.argv) == 2 and
192               (sys.argv[1] == "--help" or sys.argv[1] == "-h"))):
193         usage(functionality)
194
195     # First see if we were invoked with/as the name of a module
196     cmdname = sys.argv[0]
197     cmdname = cmdname[cmdname.rfind("/")+1:]
198     if cmdname in modules:
199         pass
200     # Otherwise the argument is the module
201     else:
202         cmdname = sys.argv[1]
203         sys.argv = [sys.argv[0] + " " + sys.argv[1]] + sys.argv[2:]
204         if cmdname not in modules:
205             match = []
206             for name in modules:
207                 if name.startswith(cmdname):
208                     match.append(name)
209             if len(match) == 1:
210                 cmdname = match[0]
211             elif len(match) > 1:
212                 daklib.utils.warn("ambiguous command '%s' - could be %s" \
213                            % (cmdname, ", ".join(match)))
214                 usage(functionality, 1)
215             else:
216                 daklib.utils.warn("unknown command '%s'" % (cmdname))
217                 usage(functionality, 1)
218
219     # Invoke the module
220     module = __import__(cmdname.replace("-","_"))
221
222     try:
223         module.main()
224     except KeyboardInterrupt:
225         msg = 'KeyboardInterrupt caught; exiting'
226         print msg
227         if logger:
228             logger.log([msg])
229         sys.exit(1)
230     except SystemExit:
231         pass
232     except:
233         if logger:
234             for line in traceback.format_exc().split('\n')[:-1]:
235                 logger.log(['exception', line])
236         raise
237
238 ################################################################################
239
240 if __name__ == "__main__":
241     os.environ['LANG'] = 'C'
242     os.environ['LC_ALL'] = 'C'
243     main()