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