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