1#!/usr/bin/env python3
3"""
4Wrapper to launch dak functionality
6G{importgraph}
8"""
9# Copyright (C) 2005, 2006 Anthony Towns <ajt@debian.org>
10# Copyright (C) 2006 James Troup <james@nocrew.org>
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.
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.
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
26################################################################################
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
32# (if James had a blog, I bet I could find a funny quote in it to use!)
34################################################################################
36import importlib
37import os
38import sys
39import traceback
41sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
43import daklib.utils
45from daklib.daklog import Logger
47################################################################################
50def init():
51 """Setup the list of modules and brief explanation of what they
52 do."""
54 functionality = [
55 ("ls",
56 "Show which suites packages are in"),
57 ("override",
58 "Query/change the overrides"),
59 ("check-archive",
60 "Archive sanity checks"),
61 ("queue-report",
62 "Produce a report on NEW and BYHAND packages"),
63 ("show-new",
64 "Output html for packages in NEW"),
65 ("show-deferred",
66 "Output html and symlinks for packages in DEFERRED"),
67 ("graph",
68 "Output graphs of number of packages in various queues"),
70 ("rm",
71 "Remove packages from suites"),
73 ("process-new",
74 "Process NEW and BYHAND packages"),
75 ("process-upload",
76 "Process packages in queue/unchecked"),
77 ("process-commands",
78 "Process command files (*.dak-commands)"),
79 ("process-policy",
80 "Process packages in policy queues from COMMENTS files"),
82 ("dominate",
83 "Remove obsolete source and binary associations from suites"),
84 ("export",
85 "Export uploads from policy queues"),
86 ("export-suite",
87 "export a suite to a flat directory structure"),
88 ("make-pkg-file-mapping",
89 "Generate package <-> file mapping"),
90 ("generate-releases",
91 "Generate Release files"),
92 ("generate-packages-sources2",
93 "Generate Packages/Sources files"),
94 ("contents",
95 "Generate content files"),
96 ("metadata",
97 "Load data for packages/sources files"),
98 ("generate-index-diffs",
99 "Generate .diff/Index files"),
100 ("clean-suites",
101 "Clean unused/superseded packages from the archive"),
102 ("manage-build-queues",
103 "Clean and update metadata for build queues"),
104 ("manage-debug-suites",
105 "Clean obsolete packages from debug suites"),
106 ("manage-external-signature-requests",
107 "Maintain external signature requests"),
108 ("clean-queues",
109 "Clean cruft from incoming"),
110 ("archive-dedup-pool",
111 "De-duplicates files in the pool directory"),
113 ("transitions",
114 "Manage the release transition file"),
115 ("check-overrides",
116 "Override cruft checks"),
117 ("control-overrides",
118 "Manipulate/list override entries in bulk"),
119 ("control-suite",
120 "Manipulate suites in bulk"),
121 ("update-suite",
122 "Update suite with packages from a different suite"),
123 ("cruft-report",
124 "Check for obsolete or duplicated packages"),
125 ("auto-decruft",
126 "Clean cruft without reverse dependencies automatically"),
127 ("examine-package",
128 "Show information useful for NEW processing"),
129 ("import",
130 "Import existing source and binary packages"),
131 ("import-repository",
132 "Import packages from another repository"),
133 ("import-keyring",
134 "Populate fingerprint/uid table based on a new/updated keyring"),
135 ("import-users-from-passwd",
136 "Sync PostgreSQL users with passwd file"),
137 ("acl",
138 "Manage upload ACLs"),
139 ("admin",
140 "Perform administration on the dak database"),
141 ("update-db",
142 "Updates databae schema to latest revision"),
143 ("init-dirs",
144 "Initial setup of the archive"),
145 ("make-maintainers",
146 "Generates Maintainers file for BTS etc"),
147 ("make-overrides",
148 "Generates override files"),
149 ("new-security-install",
150 "New way to install a security upload into the archive"),
151 ("stats",
152 "Generate statistics"),
153 ("bts-categorize",
154 "Categorize uncategorized bugs filed against ftp.debian.org"),
155 ("add-user",
156 "Add a user to the archive"),
157 ("make-changelog",
158 "Generate changelog between two suites"),
159 ("copy-installer",
160 "Copies the installer from one suite to another"),
161 ("external-overrides",
162 "Modify external overrides"),
163 ("write-sections",
164 "Write out section descriptions"),
165 ("find-files",
166 "Find files related to a given source package and version"),
167 ]
168 return functionality
170################################################################################
173def usage(functionality, exit_code=0):
174 """Print a usage message and exit with 'exit_code'."""
176 print("""Usage: dak COMMAND [...]
177Run DAK commands. (Will also work if invoked as COMMAND.)
179Available commands:""")
180 for (command, description) in functionality:
181 print(" %-23s %s" % (command, description))
182 sys.exit(exit_code)
184################################################################################
187def main():
188 """Launch dak functionality."""
190 try:
191 logger = Logger('dak top-level', print_starting=False)
192 except OSError:
193 logger = None
195 functionality = init()
196 modules = [command for (command, _) in functionality]
198 if len(sys.argv) == 0: 198 ↛ 199line 198 didn't jump to line 199, because the condition on line 198 was never true
199 daklib.utils.fubar("err, argc == 0? how is that possible?")
200 elif (len(sys.argv) == 1
201 or (len(sys.argv) == 2
202 and (sys.argv[1] == "--help" or sys.argv[1] == "-h"))):
203 usage(functionality)
205 # First see if we were invoked with/as the name of a module
206 cmdname = sys.argv[0]
207 cmdname = cmdname[cmdname.rfind("/") + 1:]
208 if cmdname in modules: 208 ↛ 209line 208 didn't jump to line 209, because the condition on line 208 was never true
209 pass
210 # Otherwise the argument is the module
211 else:
212 cmdname = sys.argv[1]
213 sys.argv = [sys.argv[0] + " " + sys.argv[1]] + sys.argv[2:]
214 if cmdname not in modules:
215 match = []
216 for name in modules:
217 if name.startswith(cmdname):
218 match.append(name)
219 if len(match) == 1: 219 ↛ 221line 219 didn't jump to line 221, because the condition on line 219 was never false
220 cmdname = match[0]
221 elif len(match) > 1:
222 daklib.utils.warn("ambiguous command '%s' - could be %s"
223 % (cmdname, ", ".join(match)))
224 usage(functionality, 1)
225 else:
226 daklib.utils.warn("unknown command '%s'" % (cmdname))
227 usage(functionality, 1)
229 # Invoke the module
230 module = importlib.import_module("dak.{}".format(cmdname.replace("-", "_")))
232 try:
233 module.main()
234 except KeyboardInterrupt: 234 ↛ 235line 234 didn't jump to line 235, because the exception caught by line 234 didn't happen
235 msg = 'KeyboardInterrupt caught; exiting'
236 print(msg)
237 if logger:
238 logger.log([msg])
239 sys.exit(1)
240 except SystemExit: 240 ↛ 242line 240 didn't jump to line 242
241 raise
242 except:
243 if logger:
244 for line in traceback.format_exc().split('\n')[:-1]:
245 logger.log(['exception', line])
246 raise
248################################################################################
251if __name__ == "__main__":
252 os.environ['LANG'] = 'C'
253 os.environ['LC_ALL'] = 'C'
254 main()