]> git.decadent.org.uk Git - dak.git/blob - dak/dak.py
Remove import-known-changes and import-new-files.
[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-policy",
75          "Process packages in policy queues from COMMENTS files"),
76
77         ("dominate",
78          "Remove obsolete source and binary associations from suites"),
79         ("make-pkg-file-mapping",
80          "Generate package <-> file mapping"),
81         ("generate-filelist",
82          "Generate file lists for apt-ftparchive"),
83         ("generate-releases",
84          "Generate Release files"),
85         ("generate-packages-sources",
86          "Generate Packages/Sources files"),
87         ("generate-packages-sources2",
88          "Generate Packages/Sources files [directly from database]"),
89         ("contents",
90          "Generate content files"),
91         ("metadata",
92          "Load data for packages/sources files"),
93         ("generate-index-diffs",
94          "Generate .diff/Index files"),
95         ("clean-suites",
96          "Clean unused/superseded packages from the archive"),
97         ("manage-build-queues",
98          "Clean and update metadata for build queues"),
99         ("clean-queues",
100          "Clean cruft from incoming"),
101
102         ("transitions",
103          "Manage the release transition file"),
104         ("check-overrides",
105          "Override cruft checks"),
106         ("control-overrides",
107          "Manipulate/list override entries in bulk"),
108         ("control-suite",
109          "Manipulate suites in bulk"),
110         ("cruft-report",
111          "Check for obsolete or duplicated packages"),
112         ("examine-package",
113          "Show information useful for NEW processing"),
114         ("find-null-maintainers",
115          "Check for users with no packages in the archive"),
116         ("import-keyring",
117          "Populate fingerprint/uid table based on a new/updated keyring"),
118         ("import-ldap-fingerprints",
119          "Syncs fingerprint and uid tables with Debian LDAP db"),
120         ("import-users-from-passwd",
121          "Sync PostgreSQL users with passwd file"),
122         ("admin",
123          "Perform administration on the dak database"),
124         ("update-db",
125          "Updates databae schema to latest revision"),
126         ("init-dirs",
127          "Initial setup of the archive"),
128         ("make-maintainers",
129          "Generates Maintainers file for BTS etc"),
130         ("make-overrides",
131          "Generates override files"),
132         ("new-security-install",
133          "New way to install a security upload into the archive"),
134         ("split-done",
135          "Split queue/done into a date-based hierarchy"),
136         ("stats",
137          "Generate statistics"),
138         ("bts-categorize",
139          "Categorize uncategorized bugs filed against ftp.debian.org"),
140         ("add-user",
141          "Add a user to the archive"),
142         ("make-changelog",
143          "Generate changelog between two suites"),
144         ("copy-installer",
145          "Copies the installer from one suite to another"),
146         ("override-disparity",
147          "Generate a list of override disparities"),
148         ("external-overrides",
149          "Modify external overrides"),
150         ]
151     return functionality
152
153 ################################################################################
154
155 def usage(functionality, exit_code=0):
156     """Print a usage message and exit with 'exit_code'."""
157
158     print """Usage: dak COMMAND [...]
159 Run DAK commands.  (Will also work if invoked as COMMAND.)
160
161 Available commands:"""
162     for (command, description) in functionality:
163         print "  %-23s %s" % (command, description)
164     sys.exit(exit_code)
165
166 ################################################################################
167
168 def main():
169     """Launch dak functionality."""
170
171
172     try:
173         logger = Logger('dak top-level', print_starting=False)
174     except CantOpenError:
175         logger = None
176
177     functionality = init()
178     modules = [ command for (command, _) in functionality ]
179
180     if len(sys.argv) == 0:
181         daklib.utils.fubar("err, argc == 0? how is that possible?")
182     elif (len(sys.argv) == 1
183           or (len(sys.argv) == 2 and
184               (sys.argv[1] == "--help" or sys.argv[1] == "-h"))):
185         usage(functionality)
186
187     # First see if we were invoked with/as the name of a module
188     cmdname = sys.argv[0]
189     cmdname = cmdname[cmdname.rfind("/")+1:]
190     if cmdname in modules:
191         pass
192     # Otherwise the argument is the module
193     else:
194         cmdname = sys.argv[1]
195         sys.argv = [sys.argv[0] + " " + sys.argv[1]] + sys.argv[2:]
196         if cmdname not in modules:
197             match = []
198             for name in modules:
199                 if name.startswith(cmdname):
200                     match.append(name)
201             if len(match) == 1:
202                 cmdname = match[0]
203             elif len(match) > 1:
204                 daklib.utils.warn("ambiguous command '%s' - could be %s" \
205                            % (cmdname, ", ".join(match)))
206                 usage(functionality, 1)
207             else:
208                 daklib.utils.warn("unknown command '%s'" % (cmdname))
209                 usage(functionality, 1)
210
211     # Invoke the module
212     module = __import__(cmdname.replace("-","_"))
213
214     try:
215         module.main()
216     except KeyboardInterrupt:
217         msg = 'KeyboardInterrupt caught; exiting'
218         print msg
219         if logger:
220             logger.log([msg])
221         sys.exit(1)
222     except SystemExit:
223         pass
224     except:
225         if logger:
226             for line in traceback.format_exc().split('\n')[:-1]:
227                 logger.log(['exception', line])
228         raise
229
230 ################################################################################
231
232 if __name__ == "__main__":
233     os.environ['LANG'] = 'C'
234     os.environ['LC_ALL'] = 'C'
235     main()