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