]> git.decadent.org.uk Git - dak.git/blob - dak/dak.py
That much for trusting an example - which assumed stuff like "import * from os" or...
[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, imp
32 import daklib.utils, daklib.extensions
33
34 ################################################################################
35
36 class UserExtension:
37     def __init__(self, user_extension = None):
38         if user_extension:
39             m = imp.load_source("dak_userext", user_extension)
40             d = m.__dict__
41         else:
42             m, d = None, {}
43         self.__dict__["_module"] = m
44         self.__dict__["_d"] = d
45
46     def __getattr__(self, a):
47         if a in self.__dict__: return self.__dict__[a]
48         if a[0] == "_": raise AttributeError, a
49         return self._d.get(a, None)
50
51     def __setattr__(self, a, v):
52         self._d[a] = v
53
54 ################################################################################
55
56 def init():
57     """Setup the list of modules and brief explanation of what they
58     do."""
59
60     functionality = [
61         ("ls",
62          "Show which suites packages are in"),
63         ("override",
64          "Query/change the overrides"),
65         ("check-archive",
66          "Archive sanity checks"),
67         ("queue-report",
68          "Produce a report on NEW and BYHAND packages"),
69         ("show-new",
70          "Output html for packages in NEW"),
71         
72         ("rm",
73          "Remove packages from suites"),
74         
75         ("process-new",
76          "Process NEW and BYHAND packages"),
77         ("process-unchecked",
78          "Process packages in queue/unchecked"),
79         ("process-accepted",
80          "Install packages into the pool"),
81         
82         ("make-suite-file-list",
83          "Generate lists of packages per suite for apt-ftparchive"),
84         ("generate-releases",
85          "Generate Release files"),
86         ("generate-index-diffs",
87          "Generate .diff/Index files"),
88         ("clean-suites",
89          "Clean unused/superseded packages from the archive"),
90         ("clean-queues",
91          "Clean cruft from incoming"),
92         ("clean-proposed-updates",
93          "Remove obsolete .changes from proposed-updates"),
94
95         ("transitions",
96          "Manage the release transition file"),
97         ("check-overrides",
98          "Override cruft checks"),
99         ("check-proposed-updates",
100          "Dependency checking for proposed-updates"),
101         ("compare-suites",
102          "Show fixable discrepencies between suites"),
103         ("control-overrides",
104          "Manipulate/list override entries in bulk"),
105         ("control-suite",
106          "Manipulate suites in bulk"),
107         ("cruft-report",
108          "Check for obsolete or duplicated packages"),
109         ("decode-dot-dak",
110          "Display contents of a .dak file"),
111         ("examine-package",
112          "Show information useful for NEW processing"),
113         ("find-null-maintainers",
114          "Check for users with no packages in the archive"),
115         ("import-archive",
116          "Populate SQL database based from an archive tree"),
117         ("import-keyring",
118          "Populate fingerprint/uid table based on a new/updated keyring"),
119         ("import-ldap-fingerprints",
120          "Syncs fingerprint and uid tables with Debian LDAP db"),
121         ("import-users-from-passwd",
122          "Sync PostgreSQL users with passwd file"),
123         ("init-db",
124          "Update the database to match the conf file"),
125         ("init-dirs",
126          "Initial setup of the archive"),
127         ("make-maintainers",
128          "Generates Maintainers file for BTS etc"),
129         ("make-overrides",
130          "Generates override files"),
131         ("mirror-split",
132          "Split the pool/ by architecture groups"),
133         ("poolize",
134          "Move packages from dists/ to pool/"),
135         ("reject-proposed-updates",
136          "Manually reject from proposed-updates"),
137         ("security-install",
138          "Install a security upload into the archive"),
139         ("new-security-install",
140          "New way to install a security upload into the archive"),
141         ("split-done",
142          "Split queue/done into a date-based hierarchy"),
143         ("stats",
144          "Generate statistics"),
145         ("symlink-dists",
146          "Generate compatability symlinks from dists/ into pool/"),
147         ]
148     return functionality
149     
150 ################################################################################
151
152 def usage(functionality, exit_code=0):
153     """Print a usage message and exit with 'exit_code'."""
154
155     print """Usage: dak COMMAND [...]
156 Run DAK commands.  (Will also work if invoked as COMMAND.)
157
158 Availble commands:"""
159     for (command, description) in functionality:
160         print "  %-23s %s" % (command, description)
161     sys.exit(exit_code)
162
163 ################################################################################
164
165 def main():
166     """Launch dak functionality."""
167
168     Cnf = daklib.utils.get_conf()
169
170     if Cnf.has_key("Dinstall::UserExtensions"):
171         userext = UserExtension(Cnf["Dinstall::UserExtensions"])
172     else:
173         userext = UserExtension()
174
175     functionality = init()
176     modules = [ command for (command, _) in functionality ]
177     
178     if len(sys.argv) == 0:
179         daklib.utils.fubar("err, argc == 0? how is that possible?")
180     elif (len(sys.argv) == 1
181           or (len(sys.argv) == 2 and
182               (sys.argv[1] == "--help" or sys.argv[1] == "-h"))):
183         usage(functionality)
184
185     # First see if we were invoked with/as the name of a module
186     cmdname = sys.argv[0]
187     cmdname = cmdname[cmdname.rfind("/")+1:]
188     if cmdname in modules:
189         pass
190     # Otherwise the argument is the module
191     else:
192         cmdname = sys.argv[1]
193         sys.argv = [sys.argv[0] + " " + sys.argv[1]] + sys.argv[2:]
194         if cmdname not in modules:
195             match = []
196             for name in modules:
197                 if name.startswith(cmdname):
198                     match.append(name)
199             if len(match) == 1:
200                 cmdname = match[0]
201             elif len(match) > 1:
202                 daklib.utils.warn("ambiguous command '%s' - could be %s" \
203                            % (cmdname, ", ".join(match)))
204                 usage(functionality, 1)
205             else:
206                 daklib.utils.warn("unknown command '%s'" % (cmdname))
207                 usage(functionality, 1)
208
209     # Invoke the module
210     module = __import__(cmdname.replace("-","_"))
211
212     module.dak_userext = userext
213     userext.dak_module = module
214
215     daklib.extensions.init(cmdname, module, userext)
216     if userext.init is not None: userext.init(cmdname)
217
218     module.main()
219
220 ################################################################################
221
222 if __name__ == "__main__":
223     main()