]> git.decadent.org.uk Git - dak.git/blob - dak/dak.py
c4d76be89db1626cf3e9bd3f46348dfa96d272ad
[dak.git] / dak / dak.py
1 #!/usr/bin/env python
2
3 """Wrapper to launch dak functionality"""
4 # Copyright (C) 2005, 2006 Anthony Towns <ajt@debian.org>
5 # Copyright (C) 2006 James Troup <james@nocrew.org>
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ################################################################################
22
23 # well I don't know where you're from but in AMERICA, there's a little
24 # thing called "abstinent until proven guilty."
25 #  -- http://harrietmiers.blogspot.com/2005/10/wow-i-feel-loved.html
26
27 # (if James had a blog, I bet I could find a funny quote in it to use!)
28
29 ################################################################################
30
31 import sys
32 import daklib.utils
33
34 ################################################################################
35
36 def init():
37     """Setup the list of modules and brief explanation of what they
38     do."""
39
40     functionality = [
41         ("ls",
42          "Show which suites packages are in"),
43         ("override",
44          "Query/change the overrides"),
45         ("check-archive",
46          "Archive sanity checks"),
47         ("queue-report",
48          "Produce a report on NEW and BYHAND packages"),
49         
50         ("rm",
51          "Remove packages from suites"),
52         
53         ("process-new",
54          "Process NEW and BYHAND packages"),
55         ("process-unchecked",
56          "Process packages in queue/unchecked"),
57         ("process-accepted",
58          "Install packages into the pool"),
59         
60         ("make-suite-file-list",
61          "Generate lists of packages per suite for apt-ftparchive"),
62         ("generate-releases",
63          "Generate Release files"),
64         ("generate-index-diffs",
65          "Generate .diff/Index files"),
66         ("clean-suites",
67          "Clean unused/superseded packages from the archive"),
68         ("clean-queues",
69          "Clean cruft from incoming"),
70         ("clean-proposed-updates",
71          "Remove obsolete .changes from proposed-updates"),
72         
73         ("check-overrides",
74          "Override cruft checks"),
75         ("check-proposed-updates",
76          "Dependency checking for proposed-updates"),
77         ("compare-suites",
78          "Show fixable discrepencies between suites"),
79         ("control-overrides",
80          "Manipulate/list override entries in bulk"),
81         ("control-suite",
82          "Manipulate suites in bulk"),
83         ("cruft-report",
84          "Check for obsolete or duplicated packages"),
85         ("decode-dot-dak",
86          "Display contents of a .dak file"),
87         ("examine-package",
88          "Show information useful for NEW processing"),
89         ("find-null-maintainers",
90          "Check for users with no packages in the archive"),
91         ("import-archive",
92          "Populate SQL database based from an archive tree"),
93         ("import-ldap-fingerprints",
94          "Syncs fingerprint and uid tables with Debian LDAP db"),
95         ("import-users-from-passwd",
96          "Sync PostgreSQL users with passwd file"),
97         ("init-db",
98          "Update the database to match the conf file"),
99         ("init-dirs",
100          "Initial setup of the archive"),
101         ("make-maintainers",
102          "Generates Maintainers file for BTS etc"),
103         ("make-overrides",
104          "Generates override files"),
105         ("mirror-split",
106          "Split the pool/ by architecture groups"),
107         ("poolize",
108          "Move packages from dists/ to pool/"),
109         ("reject-proposed-updates",
110          "Manually reject from proposed-updates"),
111         ("security-install",
112          "Install a security upload into the archive"),
113         ("new-security-install",
114          "New way to install a security upload into the archive"),
115         ("split-done",
116          "Split queue/done into a date-based hierarchy"),
117         ("stats",
118          "Generate statistics"),
119         ("symlink-dists",
120          "Generate compatability symlinks from dists/ into pool/"),
121         ]
122     return functionality
123     
124 ################################################################################
125
126 def usage(functionality, exit_code=0):
127     """Print a usage message and exit with 'exit_code'."""
128
129     print """Usage: dak COMMAND [...]
130 Run DAK commands.  (Will also work if invoked as COMMAND.)
131
132 Availble commands:"""
133     for (command, description) in functionality:
134         print "  %-23s %s" % (command, description)
135     sys.exit(exit_code)
136
137 ################################################################################
138
139 def main():
140     """Launch dak functionality."""
141
142     functionality = init()
143     modules = [ command for (command, _) in functionality ]
144     
145     if len(sys.argv) == 0:
146         daklib.utils.fubar("err, argc == 0? how is that possible?")
147     elif (len(sys.argv) == 1
148           or (len(sys.argv) == 2 and
149               (sys.argv[1] == "--help" or sys.argv[1] == "-h"))):
150         usage(functionality)
151
152     # First see if we were invoked with/as the name of a module
153     cmdname = sys.argv[0]
154     cmdname = cmdname[cmdname.rfind("/")+1:]
155     if cmdname in modules:
156         pass
157     # Otherwise the argument is the module
158     else:
159         cmdname = sys.argv[1]
160         sys.argv = [sys.argv[0] + " " + sys.argv[1]] + sys.argv[2:]
161         if cmdname not in modules:
162             match = []
163             for name in modules:
164                 if name.startswith(cmdname):
165                     match.append(name)
166             if len(match) == 1:
167                 cmdname = match[0]
168             elif len(match) > 1:
169                 daklib.utils.warn("ambiguous command '%s' - could be %s" \
170                            % (cmdname, ", ".join(match)))
171                 usage(functionality, 1)
172             else:
173                 daklib.utils.warn("unknown command '%s'" % (cmdname))
174                 usage(functionality, 1)
175
176     # Invoke the module
177     module = __import__(cmdname.replace("-","_"))
178     module.main()
179
180 ################################################################################
181
182 if __name__ == "__main__":
183     main()