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
44from daklib.daklog import Logger
46################################################################################
49def init():
50 """Setup the list of modules and brief explanation of what they
51 do."""
53 functionality = [
54 ("ls", "Show which suites packages are in"),
55 ("override", "Query/change the overrides"),
56 ("check-archive", "Archive sanity checks"),
57 ("queue-report", "Produce a report on NEW and BYHAND packages"),
58 ("show-new", "Output html for packages in NEW"),
59 ("show-deferred", "Output html and symlinks for packages in DEFERRED"),
60 ("graph", "Output graphs of number of packages in various queues"),
61 ("graph-new", "Output graphs of age of packages in the NEW queue"),
62 ("rm", "Remove packages from suites"),
63 ("process-new", "Process NEW and BYHAND packages"),
64 ("process-upload", "Process packages in queue/unchecked"),
65 ("process-commands", "Process command files (*.dak-commands)"),
66 ("process-policy", "Process packages in policy queues from COMMENTS files"),
67 ("dominate", "Remove obsolete source and binary associations from suites"),
68 ("export", "Export uploads from policy queues"),
69 ("export-suite", "export a suite to a flat directory structure"),
70 ("make-pkg-file-mapping", "Generate package <-> file mapping"),
71 ("generate-releases", "Generate Release files"),
72 ("generate-packages-sources2", "Generate Packages/Sources files"),
73 ("contents", "Generate content files"),
74 ("metadata", "Load data for packages/sources files"),
75 ("generate-index-diffs", "Generate .diff/Index files"),
76 ("clean-suites", "Clean unused/superseded packages from the archive"),
77 ("manage-build-queues", "Clean and update metadata for build queues"),
78 ("manage-debug-suites", "Clean obsolete packages from debug suites"),
79 ("manage-external-signature-requests", "Maintain external signature requests"),
80 ("clean-queues", "Clean cruft from incoming"),
81 ("archive-dedup-pool", "De-duplicates files in the pool directory"),
82 ("transitions", "Manage the release transition file"),
83 ("check-overrides", "Override cruft checks"),
84 ("control-overrides", "Manipulate/list override entries in bulk"),
85 ("control-suite", "Manipulate suites in bulk"),
86 ("update-suite", "Update suite with packages from a different suite"),
87 ("cruft-report", "Check for obsolete or duplicated packages"),
88 ("auto-decruft", "Clean cruft without reverse dependencies automatically"),
89 ("examine-package", "Show information useful for NEW processing"),
90 ("import", "Import existing source and binary packages"),
91 ("import-repository", "Import packages from another repository"),
92 (
93 "import-keyring",
94 "Populate fingerprint/uid table based on a new/updated keyring",
95 ),
96 ("import-users-from-passwd", "Sync PostgreSQL users with passwd file"),
97 ("acl", "Manage upload ACLs"),
98 ("admin", "Perform administration on the dak database"),
99 ("update-db", "Updates databae schema to latest revision"),
100 ("init-dirs", "Initial setup of the archive"),
101 ("make-maintainers", "Generates Maintainers file for BTS etc"),
102 ("make-overrides", "Generates override files"),
103 (
104 "new-security-install",
105 "New way to install a security upload into the archive",
106 ),
107 ("stats", "Generate statistics"),
108 (
109 "bts-categorize",
110 "Categorize uncategorized bugs filed against ftp.debian.org",
111 ),
112 ("add-user", "Add a user to the archive"),
113 ("make-changelog", "Generate changelog between two suites"),
114 ("copy-installer", "Copies the installer from one suite to another"),
115 ("external-overrides", "Modify external overrides"),
116 ("write-sections", "Write out section descriptions"),
117 ("find-files", "Find files related to a given source package and version"),
118 ]
119 return functionality
122################################################################################
125def usage(functionality, exit_code=0):
126 """Print a usage message and exit with 'exit_code'."""
128 print(
129 """Usage: dak COMMAND [...]
130Run DAK commands. (Will also work if invoked as COMMAND.)
132Available commands:"""
133 )
134 for command, description in functionality:
135 print(" %-23s %s" % (command, description))
136 sys.exit(exit_code)
139################################################################################
142def main():
143 """Launch dak functionality."""
145 try:
146 logger = Logger("dak top-level", print_starting=False)
147 except OSError:
148 logger = None
150 functionality = init()
151 modules = [command for (command, _) in functionality]
153 if len(sys.argv) == 0: 153 ↛ 154line 153 didn't jump to line 154, because the condition on line 153 was never true
154 daklib.utils.fubar("err, argc == 0? how is that possible?")
155 elif len(sys.argv) == 1 or (
156 len(sys.argv) == 2 and (sys.argv[1] == "--help" or sys.argv[1] == "-h")
157 ):
158 usage(functionality)
160 # First see if we were invoked with/as the name of a module
161 cmdname = sys.argv[0]
162 cmdname = cmdname[cmdname.rfind("/") + 1 :]
163 if cmdname in modules: 163 ↛ 164line 163 didn't jump to line 164, because the condition on line 163 was never true
164 pass
165 # Otherwise the argument is the module
166 else:
167 cmdname = sys.argv[1]
168 sys.argv = [sys.argv[0] + " " + sys.argv[1]] + sys.argv[2:]
169 if cmdname not in modules:
170 match = []
171 for name in modules:
172 if name.startswith(cmdname):
173 match.append(name)
174 if len(match) == 1: 174 ↛ 176line 174 didn't jump to line 176, because the condition on line 174 was never false
175 cmdname = match[0]
176 elif len(match) > 1:
177 daklib.utils.warn(
178 "ambiguous command '%s' - could be %s" % (cmdname, ", ".join(match))
179 )
180 usage(functionality, 1)
181 else:
182 daklib.utils.warn("unknown command '%s'" % (cmdname))
183 usage(functionality, 1)
185 # Invoke the module
186 module = importlib.import_module("dak.{}".format(cmdname.replace("-", "_")))
188 try:
189 module.main()
190 except KeyboardInterrupt: 190 ↛ 191line 190 didn't jump to line 191, because the exception caught by line 190 didn't happen
191 msg = "KeyboardInterrupt caught; exiting"
192 print(msg)
193 if logger:
194 logger.log([msg])
195 sys.exit(1)
196 except SystemExit: 196 ↛ 198line 196 didn't jump to line 198
197 raise
198 except:
199 if logger:
200 for line in traceback.format_exc().split("\n")[:-1]:
201 logger.log(["exception", line])
202 raise
205################################################################################
208if __name__ == "__main__":
209 os.environ["LANG"] = "C"
210 os.environ["LC_ALL"] = "C"
211 main()