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