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