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