def init(session): global cnf, Options cnf = Config() Arguments = [('h', "help", "Show-New::Options::Help"), ("p", "html-path", "Show-New::HTMLPath", "HasArg"), ('q', 'queue', 'Show-New::Options::Queue', 'HasArg')] for i in ["help"]: key = "Show-New::Options::%s" % i if key not in cnf: cnf[key] = "" changesnames = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Show-New::Options") if Options["help"]: usage() queue_names = Options.find('Queue', 'new').split(',') uploads = session.query(PolicyQueueUpload) \ .join(PolicyQueueUpload.policy_queue).filter(PolicyQueue.queue_name.in_(queue_names)) \ .join(PolicyQueueUpload.changes).order_by(DBChange.source) if len(changesnames) > 0: uploads = uploads.filter(DBChange.changesname.in_(changesnames)) return uploads
def main(argv=None): if argv is None: argv = sys.argv arguments = [('h', 'help', 'Export::Options::Help'), ('a', 'all', 'Export::Options::All'), ('c', 'copy', 'Export::Options::Copy'), ('d', 'directory', 'Export::Options::Directory', 'HasArg'), ('q', 'queue', 'Export::Options::Queue', 'HasArg')] cnf = Config() source_names = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv) options = cnf.subtree('Export::Options') if 'Help' in options or 'Queue' not in options: usage() sys.exit(0) session = DBConn().session() queue = session.query(PolicyQueue).filter_by(queue_name=options['Queue']).first() if queue is None: print("Unknown queue '{0}'".format(options['Queue'])) sys.exit(1) uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=queue) if 'All' not in options: uploads = uploads.filter(DBChange.source.in_(source_names)) directory = options.get('Directory', '.') symlink = 'Copy' not in options for u in uploads: UploadCopy(u).export(directory, symlink=symlink, ignore_existing=True)
def main(): cnf = Config() Arguments = [('h', "help", "External-Overrides::Options::Help"), ('f', 'force', 'External-Overrides::Options::Force')] args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) try: Options = cnf.subtree("External-Overrides::Options") except KeyError: Options = {} if Options.has_key("Help"): usage() force = False if Options.has_key("Force") and Options["Force"]: force = True logger = daklog.Logger('external-overrides') command = args[0] if command in ('import', 'i'): external_overrides_import(args[1], args[2], args[3], sys.stdin, force) elif command in ('copy', 'c'): external_overrides_copy(args[1], args[2], force) else: print "E: Unknown commands."
def init(self): cnf = Config() arguments = [('h', "help", "Update-DB::Options::Help"), ("y", "yes", "Update-DB::Options::Yes")] for i in ["help"]: key = "Update-DB::Options::%s" % i if key not in cnf: cnf[key] = "" arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) options = cnf.subtree("Update-DB::Options") if options["Help"]: self.usage() elif arguments: utils.warn("dak update-db takes no arguments.") self.usage(exit_code=1) try: if os.path.isdir(cnf["Dir::Lock"]): lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'daily.lock'), os.O_RDONLY | os.O_CREAT) fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) else: utils.warn("Lock directory doesn't exist yet - not locking") except IOError as e: if e.errno in (errno.EACCES, errno.EAGAIN): utils.fubar( "Couldn't obtain lock, looks like archive is doing something, try again later." ) self.update_db()
def init (self): cnf = Config() arguments = [('h', "help", "Update-DB::Options::Help")] for i in [ "help" ]: if not cnf.has_key("Update-DB::Options::%s" % (i)): cnf["Update-DB::Options::%s" % (i)] = "" arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) options = cnf.subtree("Update-DB::Options") if options["Help"]: self.usage() elif arguments: utils.warn("dak update-db takes no arguments.") self.usage(exit_code=1) try: if os.path.isdir(cnf["Dir::Lock"]): lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'dinstall.lock'), os.O_RDWR | os.O_CREAT) fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) else: utils.warn("Lock directory doesn't exist yet - not locking") except IOError as e: if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN': utils.fubar("Couldn't obtain lock; assuming another 'dak process-unchecked' is already running.") self.update_db()
def init(self): cnf = Config() arguments = [('h', "help", "Update-DB::Options::Help"), ("y", "yes", "Update-DB::Options::Yes")] for i in ["help"]: key = "Update-DB::Options::%s" % i if key not in cnf: cnf[key] = "" arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) options = cnf.subtree("Update-DB::Options") if options["Help"]: self.usage() elif arguments: utils.warn("dak update-db takes no arguments.") self.usage(exit_code=1) try: if os.path.isdir(cnf["Dir::Lock"]): lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'daily.lock'), os.O_RDONLY | os.O_CREAT) fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) else: utils.warn("Lock directory doesn't exist yet - not locking") except IOError as e: if e.errno in (errno.EACCES, errno.EAGAIN): utils.fubar("Couldn't obtain lock, looks like archive is doing something, try again later.") self.update_db()
def main(): global Options, Logger cnf = Config() session = DBConn().session() Arguments = [('h', "help", "Archive-Dedup-Pool::Options::Help")] apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) for i in ["help"]: key = "Archive-Dedup-Pool::Options::%s" % i if key not in cnf: cnf[key] = "" Options = cnf.subtree("Archive-Dedup-Pool::Options") if Options["Help"]: usage() Logger = daklog.Logger("archive-dedup-pool") dedup(session) Logger.close()
def main(): global Options, Logger cnf = Config() Arguments = [('h', "help", "Obsolete::Options::Help"), ('s', "suite", "Obsolete::Options::Suite", "HasArg"), ('n', "no-action", "Obsolete::Options::No-Action"), ('f', "force", "Obsolete::Options::Force")] cnf['Obsolete::Options::Help'] = '' cnf['Obsolete::Options::No-Action'] = '' cnf['Obsolete::Options::Force'] = '' apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Obsolete::Options") if Options['Help']: usage() if 'Suite' not in Options: query_suites = DBConn().session().query(Suite) suites = [suite.suite_name for suite in query_suites.all()] cnf['Obsolete::Options::Suite'] = ','.join(suites) Logger = daklog.Logger("dominate") session = DBConn().session() for suite_name in utils.split_args(Options['Suite']): suite = session.query(Suite).filter_by(suite_name = suite_name).one() if not suite.untouchable or Options['Force']: doDaDoDa(suite.suite_id, session) if Options['No-Action']: session.rollback() else: session.commit() Logger.close()
def check_upload_for_external_signature_request(session, target_suite, suite, binary): if 'External-Signature-Requests' not in Config(): return config = Config().subtree('External-Signature-Requests') config_sources = config.subtree('Sources') source = binary.source if source.source not in config_sources: return src_config = config_sources.subtree(source.source) if binary.package not in src_config.value_list('Packages'): return suites = config.value_list('Default-Suites') if 'Suites' in src_config: suites = src_config.value_list('Suites') if target_suite.suite_name not in suites: return archs = config.value_list('Default-Architectures') if 'Architectures' in src_config: archs = src_config.value_list('Architectures') if binary.architecture.arch_string not in archs: return add_external_signature_request(session, target_suite, suite, binary)
def main(): cnf = Config() Arguments = [ ('h', "help", "Copy-Installer::Options::Help"), ('s', "source", "Copy-Installer::Options::Source", "HasArg"), ('d', "destination", "Copy-Installer::Options::Destination", "HasArg"), ('n', "no-action", "Copy-Installer::Options::No-Action"), ] for option in ["help", "source", "destination", "no-action"]: key = "Copy-Installer::Options::%s" % option if key not in cnf: cnf[key] = "" extra_arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Copy-Installer::Options") if Options["Help"]: usage() if len(extra_arguments) != 1: usage(1) initializer = {"version": extra_arguments[0]} if Options["Source"] != "": initializer["source"] = Options["Source"] if Options["Destination"] != "": initializer["dest"] = Options["Destination"] copier = InstallerCopier(**initializer) print(copier.get_message()) if Options["No-Action"]: print('Do nothing because --no-action has been set.') else: copier.do_copy() print('Installer has been copied successfully.')
def main(): global Options, Logger, Sections, Priorities cnf = Config() session = DBConn().session() Arguments = [('a', "automatic", "Process-New::Options::Automatic"), ('b', "no-binaries", "Process-New::Options::No-Binaries"), ('c', "comments", "Process-New::Options::Comments"), ('h', "help", "Process-New::Options::Help"), ('m', "manual-reject", "Process-New::Options::Manual-Reject", "HasArg"), ('t', "trainee", "Process-New::Options::Trainee"), ('q', 'queue', 'Process-New::Options::Queue', 'HasArg'), ('n', "no-action", "Process-New::Options::No-Action")] changes_files = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) for i in [ "automatic", "no-binaries", "comments", "help", "manual-reject", "no-action", "version", "trainee" ]: if not cnf.has_key("Process-New::Options::%s" % (i)): cnf["Process-New::Options::%s" % (i)] = "" queue_name = cnf.get('Process-New::Options::Queue', 'new') new_queue = session.query(PolicyQueue).filter_by( queue_name=queue_name).one() if len(changes_files) == 0: uploads = new_queue.uploads else: uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=new_queue) \ .join(DBChange).filter(DBChange.changesname.in_(changes_files)).all() Options = cnf.subtree("Process-New::Options") if Options["Help"]: usage() if not Options["No-Action"]: try: Logger = daklog.Logger("process-new") except CantOpenError as e: Options["Trainee"] = "True" Sections = Section_Completer(session) Priorities = Priority_Completer(session) readline.parse_and_bind("tab: complete") if len(uploads) > 1: sys.stderr.write("Sorting changes...\n") uploads = sort_uploads(new_queue, uploads, session, Options["No-Binaries"]) if Options["Comments"]: show_new_comments(uploads, session) else: for upload in uploads: do_pkg(upload, session) end()
def main(): cnf = Config() Arguments = [('h', "help", "External-Overrides::Options::Help"), ('f', 'force', 'External-Overrides::Options::Force')] args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) try: Options = cnf.subtree("External-Overrides::Options") except KeyError: Options = {} if "Help" in Options: usage() force = False if "Force" in Options and Options["Force"]: force = True logger = daklog.Logger('external-overrides') command = args[0] if command in ('import', 'i'): external_overrides_import(args[1], args[2], args[3], sys.stdin, force) elif command in ('copy', 'c'): external_overrides_copy(args[1], args[2], force) else: print("E: Unknown commands.")
def init(session): global cnf, Options cnf = Config() Arguments = [ ("h", "help", "Show-New::Options::Help"), ("p", "html-path", "Show-New::HTMLPath", "HasArg"), ("q", "queue", "Show-New::Options::Queue", "HasArg"), ] for i in ["help"]: if not cnf.has_key("Show-New::Options::%s" % (i)): cnf["Show-New::Options::%s" % (i)] = "" changesnames = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Show-New::Options") if Options["help"]: usage() queue_names = Options.find("Queue", "new").split(",") uploads = ( session.query(PolicyQueueUpload) .join(PolicyQueueUpload.policy_queue) .filter(PolicyQueue.queue_name.in_(queue_names)) .join(PolicyQueueUpload.changes) .order_by(DBChange.source) ) if len(changesnames) > 0: uploads = uploads.filter(DBChange.changesname.in_(changesnames)) return uploads
def init(self): cnf = Config() arguments = [('h', "help", "Update-DB::Options::Help"), ("y", "yes", "Update-DB::Options::Yes")] for i in ["help"]: if not cnf.has_key("Update-DB::Options::%s" % (i)): cnf["Update-DB::Options::%s" % (i)] = "" arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) options = cnf.subtree("Update-DB::Options") if options["Help"]: self.usage() elif arguments: utils.warn("dak update-db takes no arguments.") self.usage(exit_code=1) try: if os.path.isdir(cnf["Dir::Lock"]): lock_fd = os.open( os.path.join(cnf["Dir::Lock"], 'dinstall.lock'), os.O_RDWR | os.O_CREAT) fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) else: utils.warn("Lock directory doesn't exist yet - not locking") except IOError as e: if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[ e.errno] == 'EAGAIN': utils.fubar( "Couldn't obtain lock; assuming another 'dak process-unchecked' is already running." ) self.update_db()
def main(): cnf = Config() Arguments = [('a', "architecture", "Ls::Options::Architecture", "HasArg"), ('b', "binarytype", "Ls::Options::BinaryType", "HasArg"), ('c', "component", "Ls::Options::Component", "HasArg"), ('f', "format", "Ls::Options::Format", "HasArg"), ('g', "greaterorequal", "Ls::Options::GreaterOrEqual"), ('G', "greaterthan", "Ls::Options::GreaterThan"), ('r', "regex", "Ls::Options::Regex"), ('s', "suite", "Ls::Options::Suite", "HasArg"), ('S', "source-and-binary", "Ls::Options::Source-And-Binary"), ('h', "help", "Ls::Options::Help")] for i in ["architecture", "binarytype", "component", "format", "greaterorequal", "greaterthan", "regex", "suite", "source-and-binary", "help"]: key = "Ls::Options::%s" % i if key not in cnf: cnf[key] = "" packages = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Ls::Options") if Options["Help"]: usage() if not packages: utils.fubar("need at least one package name as an argument.") # Handle buildd maintenance helper options if Options["GreaterOrEqual"] or Options["GreaterThan"]: if Options["GreaterOrEqual"] and Options["GreaterThan"]: utils.fubar("-g/--greaterorequal and -G/--greaterthan are mutually exclusive.") if not Options["Suite"]: Options["Suite"] = "unstable" kwargs = dict() if Options["Regex"]: kwargs['regex'] = True if Options["Source-And-Binary"]: kwargs['source_and_binary'] = True if Options["Suite"]: kwargs['suites'] = utils.split_args(Options['Suite']) if Options["Architecture"]: kwargs['architectures'] = utils.split_args(Options['Architecture']) if Options['BinaryType']: kwargs['binary_types'] = utils.split_args(Options['BinaryType']) if Options['Component']: kwargs['components'] = utils.split_args(Options['Component']) if Options['Format']: kwargs['format'] = Options['Format'] if Options['GreaterOrEqual']: kwargs['highest'] = '>=' elif Options['GreaterThan']: kwargs['highest'] = '>>' for line in list_packages(packages, **kwargs): print(line)
def do_update(self): print "Updating use of queue table" try: c = self.db.cursor() cnf = Config() print "Adding path to queue table" c.execute("ALTER TABLE queue ADD COLUMN path TEXT") c.execute("SELECT * FROM queue") rows = c.fetchall() seenqueues = {} for row in rows: dir = cnf["Dir::Queue::%s" % row[1]].rstrip('/') seenqueues[row[1].lower()] = 1 print "Setting %s queue to use path %s" % (row[1], dir) c.execute("UPDATE queue SET path = %s WHERE id = %s", (dir, row[0])) print "Adding missing queues to the queue table" for q in cnf.subtree("Dir::Queue").keys(): qname = q.lower() if qname in seenqueues.keys(): continue if qname in ["done", "holding", "reject", "newstage", "btsversiontrack"]: print "Skipping queue %s" % qname continue pth = cnf["Dir::Queue::%s" % qname].rstrip('/') if not os.path.exists(pth): print "Skipping %s as %s does not exist" % (qname, pth) continue print "Adding %s queue with path %s" % (qname, pth) c.execute("INSERT INTO queue (queue_name, path) VALUES (%s, %s)", (qname, pth)) seenqueues[qname] = 1 print "Adding queue and approved_for columns to known_changes" c.execute("ALTER TABLE known_changes ADD COLUMN in_queue INT4 REFERENCES queue(id) DEFAULT NULL") c.execute("ALTER TABLE known_changes ADD COLUMN approved_for INT4 REFERENCES queue(id) DEFAULT NULL") print "Adding policy queue column to suite table" c.execute("ALTER TABLE suite DROP COLUMN policy_engine") c.execute("ALTER TABLE suite ADD COLUMN policy_queue_id INT4 REFERENCES queue(id) DEFAULT NULL") # Handle some of our common cases automatically if seenqueues.has_key('proposedupdates'): c.execute("""UPDATE suite SET policy_queue_id = (SELECT id FROM queue WHERE queue_name = 'proposedupdates') WHERE suite_name = 'proposed-updates'""") if seenqueues.has_key('oldproposedupdates'): c.execute("""UPDATE suite SET policy_queue_id = (SELECT id FROM queue WHERE queue_name = 'oldproposedupdates') WHERE suite_name = 'oldstable-proposed-updates'""") print "Committing" c.execute("UPDATE config SET value = '20' WHERE name = 'db_revision'") self.db.commit() except psycopg2.InternalError as msg: self.db.rollback() raise DBUpdateError("Unable to apply debversion update 20, rollback issued. Error message : %s" % (str(msg)))
def main(): global Options, Logger cnf = Config() for i in ["Help"]: key = "Manage-External-Signature-Requests::Options::{}".format(i) if key not in cnf: cnf[key] = "" Arguments = [('h', "help", "Manage-External-Signature-Requests::Options::Help")] apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Manage-External-Signature-Requests::Options") if Options["Help"]: usage() Logger = daklog.Logger('manage-external-signature-requests') if 'External-Signature-Requests' not in cnf: print("DAK not configured to handle external signature requests") return config = cnf.subtree('External-Signature-Requests') session = DBConn().session() export_external_signature_requests(session, config['Export']) if 'ExportSigningKeys' in config: args = { 'pubring': cnf.get('Dinstall::SigningPubKeyring') or None, 'secring': cnf.get('Dinstall::SigningKeyring') or None, 'homedir': cnf.get('Dinstall::SigningHomedir') or None, 'passphrase_file': cnf.get('Dinstall::SigningPassphraseFile') or None, } sign_external_signature_requests( session, config['Export'], config.value_list('ExportSigningKeys'), args) session.close() Logger.close()
def main(argv=None): if argv is None: argv = sys.argv arguments = [('h', 'help', 'Export::Options::Help'), ('c', 'copy', 'Export::Options::Copy'), ('d', 'directory', 'Export::Options::Directory', 'HasArg'), ('r', 'relative', 'Export::Options::Relative'), ('s', 'suite', 'Export::Options::Suite', 'HasArg')] cnf = Config() apt_pkg.parse_commandline(cnf.Cnf, arguments, argv) options = cnf.subtree('Export::Options') if 'Help' in options or 'Suite' not in options: usage() sys.exit(0) session = DBConn().session() suite = session.query(Suite).filter_by(suite_name=options['Suite']).first() if suite is None: print("Unknown suite '{0}'".format(options['Suite'])) sys.exit(1) directory = options.get('Directory') if not directory: print("No target directory.") sys.exit(1) symlink = 'Copy' not in options relative = 'Relative' in options if relative and not symlink: print("E: --relative and --copy cannot be used together.") sys.exit(1) binaries = suite.binaries sources = suite.sources files = [] files.extend([b.poolfile for b in binaries]) for s in sources: files.extend([ds.poolfile for ds in s.srcfiles]) with FilesystemTransaction() as fs: for f in files: af = session.query(ArchiveFile) \ .join(ArchiveFile.component).join(ArchiveFile.file) \ .filter(ArchiveFile.archive == suite.archive) \ .filter(ArchiveFile.file == f).first() src = af.path if relative: src = os.path.relpath(src, directory) dst = os.path.join(directory, f.basename) if not os.path.exists(dst): fs.copy(src, dst, symlink=symlink) fs.commit()
def main(argv=None): if argv is None: argv = sys.argv arguments = [('h', 'help', 'Export::Options::Help'), ('c', 'copy', 'Export::Options::Copy'), ('d', 'directory', 'Export::Options::Directory', 'HasArg'), ('r', 'relative', 'Export::Options::Relative'), ('s', 'suite', 'Export::Options::Suite', 'HasArg')] cnf = Config() apt_pkg.parse_commandline(cnf.Cnf, arguments, argv) options = cnf.subtree('Export::Options') if 'Help' in options or 'Suite' not in options: usage() sys.exit(0) session = DBConn().session() suite = session.query(Suite).filter_by(suite_name=options['Suite']).first() if suite is None: print "Unknown suite '{0}'".format(options['Suite']) sys.exit(1) directory = options.get('Directory') if not directory: print "No target directory." sys.exit(1) symlink = 'Copy' not in options relative = 'Relative' in options if relative and not symlink: print "E: --relative and --copy cannot be used together." sys.exit(1) binaries = suite.binaries sources = suite.sources files = [] files.extend([ b.poolfile for b in binaries ]) for s in sources: files.extend([ ds.poolfile for ds in s.srcfiles ]) with FilesystemTransaction() as fs: for f in files: af = session.query(ArchiveFile) \ .join(ArchiveFile.component).join(ArchiveFile.file) \ .filter(ArchiveFile.archive == suite.archive) \ .filter(ArchiveFile.file == f).first() src = af.path if relative: src = os.path.relpath(src, directory) dst = os.path.join(directory, f.basename) if not os.path.exists(dst): fs.copy(src, dst, symlink=symlink) fs.commit()
def main(argv=None): if argv is None: argv = sys.argv arguments = [('h', 'help', 'Export::Options::Help'), ('c', 'copy', 'Export::Options::Copy'), ('d', 'directory', 'Export::Options::Directory', 'HasArg'), ('s', 'suite', 'Export::Options::Suite', 'HasArg')] cnf = Config() apt_pkg.parse_commandline(cnf.Cnf, arguments, argv) options = cnf.subtree('Export::Options') if 'Help' in options or 'Suite' not in options: usage() sys.exit(0) session = DBConn().session() suite = session.query(Suite).filter_by(suite_name=options['Suite']).first() if suite is None: print "Unknown suite '{0}'".format(options['Suite']) sys.exit(1) directory = options.get('Directory') if not directory: print "No target directory." sys.exit(1) symlink = 'Copy' not in options binaries = suite.binaries sources = suite.sources files = [] files.extend([ b.poolfile for b in binaries ]) for s in sources: files.extend([ ds.poolfile for ds in s.srcfiles ]) with FilesystemTransaction() as fs: for f in files: af = session.query(ArchiveFile) \ .join(ArchiveFile.component).join(ArchiveFile.file) \ .filter(ArchiveFile.archive == suite.archive) \ .filter(ArchiveFile.file == f).first() # XXX: Remove later. There was a bug that caused only the *.dsc to # be installed in build queues and we do not want to break them. # The bug was fixed in 55d2c7e6e2418518704623246021021e05b90e58 # on 2012-11-04 if af is None: af = session.query(ArchiveFile) \ .join(ArchiveFile.component).join(ArchiveFile.file) \ .filter(ArchiveFile.file == f).first() dst = os.path.join(directory, f.basename) if not os.path.exists(dst): fs.copy(af.path, dst, symlink=symlink) fs.commit()
def main(): global Options cnf = Config() Arguments = [ ('h', "help", "Auto-Decruft::Options::Help"), ('n', "dry-run", "Auto-Decruft::Options::Dry-Run"), ('d', "debug", "Auto-Decruft::Options::Debug"), ('s', "suite", "Auto-Decruft::Options::Suite", "HasArg"), # The "\0" seems to be the only way to disable short options. ("\0", 'if-newer-version-in', "Auto-Decruft::Options::OtherSuite", "HasArg"), ("\0", 'if-newer-version-in-rm-msg', "Auto-Decruft::Options::OtherSuiteRMMsg", "HasArg") ] for i in ["help", "Dry-Run", "Debug", "OtherSuite", "OtherSuiteRMMsg"]: if not cnf.has_key("Auto-Decruft::Options::%s" % (i)): cnf["Auto-Decruft::Options::%s" % (i)] = "" cnf["Auto-Decruft::Options::Suite"] = cnf.get("Dinstall::DefaultSuite", "unstable") apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Auto-Decruft::Options") if Options["Help"]: usage() debug = False dryrun = False if Options["Dry-Run"]: dryrun = True if Options["Debug"]: debug = True if Options["OtherSuite"] and not Options["OtherSuiteRMMsg"]: utils.fubar( "--if-newer-version-in requires --if-newer-version-in-rm-msg") session = DBConn().session() suite = get_suite(Options["Suite"].lower(), session) if not suite: utils.fubar("Cannot find suite %s" % Options["Suite"].lower()) suite_id = suite.suite_id suite_name = suite.suite_name.lower() auto_decruft_suite(suite_name, suite_id, session, dryrun, debug) if Options["OtherSuite"]: osuite = get_suite(Options["OtherSuite"].lower(), session).suite_name decruft_newer_version_in(osuite, suite_name, suite_id, Options["OtherSuiteRMMsg"], session, dryrun) if not dryrun: session.commit()
def main(): global Options, Logger cnf = Config() session = DBConn().session() Arguments = [('h', "help", "Process-Policy::Options::Help"), ('n', "no-action", "Process-Policy::Options::No-Action")] for i in ["help", "no-action"]: key = "Process-Policy::Options::%s" % i if key not in cnf: cnf[key] = "" queue_name = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) if len(queue_name) != 1: print("E: Specify exactly one policy queue") sys.exit(1) queue_name = queue_name[0] Options = cnf.subtree("Process-Policy::Options") if Options["Help"]: usage() Logger = daklog.Logger("process-policy") if not Options["No-Action"]: urgencylog = UrgencyLog() with ArchiveTransaction() as transaction: session = transaction.session try: pq = session.query(PolicyQueue).filter_by( queue_name=queue_name).one() except NoResultFound: print("E: Cannot find policy queue %s" % queue_name) sys.exit(1) commentsdir = os.path.join(pq.path, 'COMMENTS') # The comments stuff relies on being in the right directory os.chdir(pq.path) do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, transaction) do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, transaction) do_comments(commentsdir, pq, "ACCEPTED.", "ACCEPTED.", "OK", comment_accept, transaction) remove_unreferenced_binaries(pq, transaction) remove_unreferenced_sources(pq, transaction) if not Options['No-Action']: urgencylog.close()
def main(): global Options, Logger, Sections, Priorities cnf = Config() session = DBConn().session() Arguments = [('a', "automatic", "Process-New::Options::Automatic"), ('b', "no-binaries", "Process-New::Options::No-Binaries"), ('c', "comments", "Process-New::Options::Comments"), ('h', "help", "Process-New::Options::Help"), ('m', "manual-reject", "Process-New::Options::Manual-Reject", "HasArg"), ('t', "trainee", "Process-New::Options::Trainee"), ('q', 'queue', 'Process-New::Options::Queue', 'HasArg'), ('n', "no-action", "Process-New::Options::No-Action")] changes_files = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) for i in ["automatic", "no-binaries", "comments", "help", "manual-reject", "no-action", "version", "trainee"]: key = "Process-New::Options::%s" % i if key not in cnf: cnf[key] = "" queue_name = cnf.get('Process-New::Options::Queue', 'new') new_queue = session.query(PolicyQueue).filter_by(queue_name=queue_name).one() if len(changes_files) == 0: uploads = new_queue.uploads else: uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=new_queue) \ .join(DBChange).filter(DBChange.changesname.in_(changes_files)).all() Options = cnf.subtree("Process-New::Options") if Options["Help"]: usage() if not Options["No-Action"]: try: Logger = daklog.Logger("process-new") except CantOpenError as e: Options["Trainee"] = "True" Sections = Section_Completer(session) Priorities = Priority_Completer(session) readline.parse_and_bind("tab: complete") if len(uploads) > 1: print("Sorting changes...", file=sys.stderr) uploads = sort_uploads(new_queue, uploads, session, Options["No-Binaries"]) if Options["Comments"]: show_new_comments(uploads, session) else: for upload in uploads: do_pkg(upload, session) end()
def main(): global Options cnf = Config() Arguments = [('h', "help", "Auto-Decruft::Options::Help"), ('n', "dry-run", "Auto-Decruft::Options::Dry-Run"), ('d', "debug", "Auto-Decruft::Options::Debug"), ('s', "suite", "Auto-Decruft::Options::Suite", "HasArg"), # The "\0" seems to be the only way to disable short options. ("\0", 'if-newer-version-in', "Auto-Decruft::Options::OtherSuite", "HasArg"), ("\0", 'if-newer-version-in-rm-msg', "Auto-Decruft::Options::OtherSuiteRMMsg", "HasArg"), ("\0", 'decruft-equal-versions', "Auto-Decruft::Options::OtherSuiteDecruftEqual") ] for i in ["help", "Dry-Run", "Debug", "OtherSuite", "OtherSuiteRMMsg", "OtherSuiteDecruftEqual"]: key = "Auto-Decruft::Options::%s" % i if key not in cnf: cnf[key] = "" cnf["Auto-Decruft::Options::Suite"] = cnf.get("Dinstall::DefaultSuite", "unstable") apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Auto-Decruft::Options") if Options["Help"]: usage() debug = False dryrun = False decruft_equal_versions = False if Options["Dry-Run"]: dryrun = True if Options["Debug"]: debug = True if Options["OtherSuiteDecruftEqual"]: decruft_equal_versions = True if Options["OtherSuite"] and not Options["OtherSuiteRMMsg"]: utils.fubar("--if-newer-version-in requires --if-newer-version-in-rm-msg") session = DBConn().session() suite = get_suite(Options["Suite"].lower(), session) if not suite: utils.fubar("Cannot find suite %s" % Options["Suite"].lower()) suite_id = suite.suite_id suite_name = suite.suite_name.lower() auto_decruft_suite(suite_name, suite_id, session, dryrun, debug) if Options["OtherSuite"]: osuite = get_suite(Options["OtherSuite"].lower(), session).suite_name decruft_newer_version_in(osuite, suite_name, suite_id, Options["OtherSuiteRMMsg"], session, dryrun, decruft_equal_versions) if not dryrun: session.commit()
def main(argv=None): if argv is None: argv = sys.argv arguments = [('h', 'help', 'Process-Commands::Options::Help'), ('d', 'directory', 'Process-Commands::Options::Directory', 'HasArg')] cnf = Config() cnf['Process-Commands::Options::Dummy'] = '' filenames = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv) options = cnf.subtree('Process-Commands::Options') if 'Help' in options or (len(filenames) == 0 and 'Directory' not in options): usage() sys.exit(0) log = Logger('command') now = datetime.datetime.now() donedir = os.path.join(cnf['Dir::Done'], now.strftime('%Y/%m/%d')) rejectdir = cnf['Dir::Reject'] if len(filenames) == 0: filenames = [ fn for fn in os.listdir(options['Directory']) if fn.endswith('.dak-commands') ] for fn in filenames: basename = os.path.basename(fn) if not fn.endswith('.dak-commands'): log.log(['unexpected filename', basename]) continue with open(fn, 'r') as fh: data = fh.read() try: command = CommandFile(basename, data, log) command.evaluate() except: created = os.stat(fn).st_mtime now = time.time() too_new = (now - created < int(cnf.get('Dinstall::SkipTime', '60'))) if too_new: log.log(['skipped (too new)']) continue log.log(['reject', basename]) dst = find_next_free(os.path.join(rejectdir, basename)) else: log.log(['done', basename]) dst = find_next_free(os.path.join(donedir, basename)) with FilesystemTransaction() as fs: fs.unlink(fn) fs.create(dst, mode=0o644).write(data) fs.commit() log.close()
def main(): cnf = Config() Arguments = [('h',"help","DEP11::Options::Help"), ('s',"suite","DEP11::Options::Suite", "HasArg"), ('e',"expire","DEP11::Options::ExpireCache"), ('h',"write-hints","DEP11::Options::WriteHints"), ] for i in ["help", "suite", "ExpireCache"]: if not cnf.has_key("DEP11::Options::%s" % (i)): cnf["DEP11::Options::%s" % (i)] = "" arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("DEP11::Options") if Options["Help"]: usage() return suitename = Options["Suite"] if not suitename: print("You need to specify a suite!") sys.exit(1) # check if we have some important config options set if not cnf.has_key("Dir::MetaInfo"): print("You need to specify a metadata export directory (Dir::MetaInfo)") sys.exit(1) if not cnf.has_key("DEP11::Url"): print("You need to specify a metadata public web URL (DEP11::Url)") sys.exit(1) if not cnf.has_key("DEP11::IconSizes"): print("You need to specify a list of allowed icon-sizes (DEP11::IconSizes)") sys.exit(1) if Options["WriteHints"] and not cnf.has_key("Dir::MetaInfoHints"): print("You need to specify an export directory for DEP-11 hints files (Dir::MetaInfoHints)") sys.exit(1) logger = daklog.Logger('generate-metadata') from daklib.dbconn import Component, DBConn, get_suite, Suite session = DBConn().session() suite = get_suite(suitename.lower(), session) if Options["ExpireCache"]: expire_dep11_data_cache(session, suitename, logger) process_suite(session, suite, logger) # export database content as Components-<arch>.xz YAML documents write_component_files(session, suite, logger) if Options["WriteHints"]: write_hints_files(session, suite, logger) # we're done logger.close()
def main(): global Options, Logger, Sections, Priorities cnf = Config() session = DBConn().session() Arguments = [('a',"automatic","Process-New::Options::Automatic"), ('b',"no-binaries","Process-New::Options::No-Binaries"), ('c',"comments","Process-New::Options::Comments"), ('h',"help","Process-New::Options::Help"), ('m',"manual-reject","Process-New::Options::Manual-Reject", "HasArg"), ('t',"trainee","Process-New::Options::Trainee"), ('n',"no-action","Process-New::Options::No-Action")] for i in ["automatic", "no-binaries", "comments", "help", "manual-reject", "no-action", "version", "trainee"]: if not cnf.has_key("Process-New::Options::%s" % (i)): cnf["Process-New::Options::%s" % (i)] = "" changes_files = apt_pkg.parse_commandline(cnf.Cnf,Arguments,sys.argv) if len(changes_files) == 0: new_queue = get_policy_queue('new', session ); changes_paths = [ os.path.join(new_queue.path, j) for j in utils.get_changes_files(new_queue.path) ] else: changes_paths = [ os.path.abspath(j) for j in changes_files ] Options = cnf.subtree("Process-New::Options") if Options["Help"]: usage() if not Options["No-Action"]: try: Logger = daklog.Logger("process-new") except CantOpenError as e: Options["Trainee"] = "True" Sections = Section_Completer(session) Priorities = Priority_Completer(session) readline.parse_and_bind("tab: complete") if len(changes_paths) > 1: sys.stderr.write("Sorting changes...\n") changes_files = sort_changes(changes_paths, session, Options["No-Binaries"]) if Options["Comments"]: show_new_comments(changes_files, session) else: for changes_file in changes_files: changes_file = utils.validate_changes_file_arg(changes_file, 0) if not changes_file: continue print "\n" + os.path.basename(changes_file) do_pkg (changes_file, session) end()
def main(): global Options, Logger cnf = Config() for i in ["Help"]: key = "Manage-External-Signature-Requests::Options::{}".format(i) if key not in cnf: cnf[key] = "" Arguments = [('h', "help", "Manage-External-Signature-Requests::Options::Help")] apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Manage-External-Signature-Requests::Options") if Options["Help"]: usage() Logger = daklog.Logger('manage-external-signature-requests') if 'External-Signature-Requests' not in cnf: print("DAK not configured to handle external signature requests") return config = cnf.subtree('External-Signature-Requests') session = DBConn().session() export_external_signature_requests(session, config['Export']) if 'ExportSigningKeys' in config: args = { 'pubring': cnf.get('Dinstall::SigningPubKeyring') or None, 'secring': cnf.get('Dinstall::SigningKeyring') or None, 'homedir': cnf.get('Dinstall::SigningHomedir') or None, 'passphrase_file': cnf.get('Dinstall::SigningPassphraseFile') or None, } sign_external_signature_requests(session, config['Export'], config.value_list('ExportSigningKeys'), args) session.close() Logger.close()
def main(): global db_files, waste, excluded cnf = Config() Arguments = [('h', "help", "Check-Archive::Options::Help")] for i in ["help"]: if not cnf.has_key("Check-Archive::Options::%s" % (i)): cnf["Check-Archive::Options::%s" % (i)] = "" args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Check-Archive::Options") if Options["Help"]: usage() if len(args) < 1: utils.warn("dak check-archive requires at least one argument") usage(1) elif len(args) > 1: utils.warn("dak check-archive accepts only one argument") usage(1) mode = args[0].lower() # Initialize DB DBConn() if mode == "checksums": check_checksums() elif mode == "files": check_files() elif mode == "dsc-syntax": check_dscs() elif mode == "missing-overrides": check_override() elif mode == "source-in-one-dir": check_source_in_one_dir() elif mode == "timestamps": check_timestamps() elif mode == "files-in-dsc": check_files_in_dsc() elif mode == "validate-indices": check_indices_files_exist() elif mode == "files-not-symlinks": check_files_not_symlinks() elif mode == "validate-builddeps": check_build_depends() elif mode == "add-missing-source-checksums": add_missing_source_checksums() elif mode == "fix-checksums": fix_checksums() else: utils.warn("unknown mode '%s'" % (mode)) usage(1)
def main (): global db_files, waste, excluded cnf = Config() Arguments = [('h',"help","Check-Archive::Options::Help")] for i in [ "help" ]: if not cnf.has_key("Check-Archive::Options::%s" % (i)): cnf["Check-Archive::Options::%s" % (i)] = "" args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Check-Archive::Options") if Options["Help"]: usage() if len(args) < 1: utils.warn("dak check-archive requires at least one argument") usage(1) elif len(args) > 1: utils.warn("dak check-archive accepts only one argument") usage(1) mode = args[0].lower() # Initialize DB DBConn() if mode == "checksums": check_checksums() elif mode == "files": check_files() elif mode == "dsc-syntax": check_dscs() elif mode == "missing-overrides": check_override() elif mode == "source-in-one-dir": check_source_in_one_dir() elif mode == "timestamps": check_timestamps() elif mode == "files-in-dsc": check_files_in_dsc() elif mode == "validate-indices": check_indices_files_exist() elif mode == "files-not-symlinks": check_files_not_symlinks() elif mode == "validate-builddeps": check_build_depends() elif mode == "add-missing-source-checksums": add_missing_source_checksums() elif mode == "fix-checksums": fix_checksums() else: utils.warn("unknown mode '%s'" % (mode)) usage(1)
def main(): global Options, Logger cnf = Config() session = DBConn().session() Arguments = [ ("h", "help", "Process-Policy::Options::Help"), ("n", "no-action", "Process-Policy::Options::No-Action"), ] for i in ["help", "no-action"]: if not cnf.has_key("Process-Policy::Options::%s" % (i)): cnf["Process-Policy::Options::%s" % (i)] = "" queue_name = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) if len(queue_name) != 1: print "E: Specify exactly one policy queue" sys.exit(1) queue_name = queue_name[0] Options = cnf.subtree("Process-Policy::Options") if Options["Help"]: usage() Logger = daklog.Logger("process-policy") if not Options["No-Action"]: urgencylog = UrgencyLog() with ArchiveTransaction() as transaction: session = transaction.session try: pq = session.query(PolicyQueue).filter_by(queue_name=queue_name).one() except NoResultFound: print "E: Cannot find policy queue %s" % queue_name sys.exit(1) commentsdir = os.path.join(pq.path, "COMMENTS") # The comments stuff relies on being in the right directory os.chdir(pq.path) do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, transaction) do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, transaction) do_comments(commentsdir, pq, "ACCEPTED.", "ACCEPTED.", "OK", comment_accept, transaction) remove_unreferenced_binaries(pq, transaction) remove_unreferenced_sources(pq, transaction) if not Options["No-Action"]: urgencylog.close()
def main(): global Options, Logger cnf = Config() for i in ["Help", "No-Action", "Maximum" ]: if not cnf.has_key("Clean-Suites::Options::%s" % (i)): cnf["Clean-Suites::Options::%s" % (i)] = "" Arguments = [('h',"help","Clean-Suites::Options::Help"), ('n',"no-action","Clean-Suites::Options::No-Action"), ('m',"maximum","Clean-Suites::Options::Maximum", "HasArg")] apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Clean-Suites::Options") if cnf["Clean-Suites::Options::Maximum"] != "": try: # Only use Maximum if it's an integer max_delete = int(cnf["Clean-Suites::Options::Maximum"]) if max_delete < 1: utils.fubar("If given, Maximum must be at least 1") except ValueError as e: utils.fubar("If given, Maximum must be an integer") else: max_delete = None if Options["Help"]: usage() Logger = daklog.Logger("clean-suites", debug=Options["No-Action"]) session = DBConn().session() now_date = datetime.now() # Stay of execution; default to 1.5 days soe = int(cnf.get('Clean-Suites::StayOfExecution', '129600')) delete_date = now_date - timedelta(seconds=soe) check_binaries(now_date, delete_date, max_delete, session) clean_binaries(now_date, delete_date, max_delete, session) check_sources(now_date, delete_date, max_delete, session) check_files(now_date, delete_date, max_delete, session) clean(now_date, delete_date, max_delete, session) clean_maintainers(now_date, delete_date, max_delete, session) clean_fingerprints(now_date, delete_date, max_delete, session) clean_empty_directories(session) Logger.close()
def main(): cnf = Config() Arguments = [('h', "help", "Make-Overrides::Options::Help")] for i in ["help"]: key = "Make-Overrides::Options::%s" % i if key not in cnf: cnf[key] = "" apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Make-Overrides::Options") if Options["Help"]: usage() d = DBConn() session = d.session() for suite in session.query(Suite).filter( Suite.overrideprocess == True): # noqa:E712 if suite.untouchable: print("Skipping %s as it is marked as untouchable" % suite.suite_name) continue sys.stderr.write("Processing %s...\n" % (suite.suite_name)) override_suite = suite.overridecodename or suite.codename for component in session.query(Component).all(): for otype in session.query(OverrideType).all(): otype_name = otype.overridetype cname = component.component_name # TODO: Stick suffix info in database (or get rid of it) if otype_name == "deb": suffix = "" elif otype_name == "udeb": if cname == "contrib": continue # Ick2 suffix = ".debian-installer" elif otype_name == "dsc": suffix = ".src" else: utils.fubar("Don't understand OverrideType %s" % otype.overridetype) cname = cname.replace('/', '_') filename = os.path.join( cnf["Dir::Override"], "override.%s.%s%s" % (override_suite, cname, suffix)) output_file = utils.open_file(filename, 'w') do_list(output_file, suite, component, otype, session) output_file.close()
def main(): global Options, Logger cnf = Config() for i in ["Help", "No-Action", "All"]: if not cnf.has_key("Manage-Build-Queues::Options::%s" % (i)): cnf["Manage-Build-Queues::Options::%s" % (i)] = "" Arguments = [ ("h", "help", "Manage-Build-Queues::Options::Help"), ("n", "no-action", "Manage-Build-Queues::Options::No-Action"), ("a", "all", "Manage-Build-Queues::Options::All"), ] queue_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Manage-Build-Queues::Options") if Options["Help"]: usage() Logger = daklog.Logger("manage-build-queues", Options["No-Action"]) starttime = datetime.now() session = DBConn().session() if Options["All"]: if len(queue_names) != 0: print "E: Cannot use both -a and a queue_name" sys.exit(1) queues = session.query(BuildQueue).all() else: queues = [] for q in queue_names: queue = get_build_queue(q.lower(), session) if queue: queues.append(queue) else: Logger.log(["cannot find queue %s" % q]) # For each given queue, look up object and call manage_queue for q in queues: Logger.log(["cleaning queue %s using datetime %s" % (q.queue_name, starttime)]) q.clean_and_update(starttime, Logger, dryrun=Options["No-Action"]) Logger.close()
def main(): global Options, Logger cnf = Config() for i in ["Help", "No-Action", "All"]: if not cnf.has_key("Manage-Build-Queues::Options::%s" % (i)): cnf["Manage-Build-Queues::Options::%s" % (i)] = "" Arguments = [('h', "help", "Manage-Build-Queues::Options::Help"), ('n', "no-action", "Manage-Build-Queues::Options::No-Action"), ('a', "all", "Manage-Build-Queues::Options::All")] queue_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Manage-Build-Queues::Options") if Options["Help"]: usage() Logger = daklog.Logger('manage-build-queues', Options['No-Action']) starttime = datetime.now() session = DBConn().session() with ArchiveTransaction() as transaction: session = transaction.session if Options['All']: if len(queue_names) != 0: print "E: Cannot use both -a and a queue name" sys.exit(1) queues = session.query(BuildQueue) else: queues = session.query(BuildQueue).filter( BuildQueue.queue_name.in_(queue_names)) for q in queues: Logger.log([ 'cleaning queue %s using datetime %s' % (q.queue_name, starttime) ]) clean(q, transaction, now=starttime) if not Options['No-Action']: transaction.commit() else: transaction.rollback() Logger.close()
def main(): global Options, Logger cnf = Config() session = DBConn().session() Arguments = [('h',"help","Process-Policy::Options::Help"), ('n',"no-action","Process-Policy::Options::No-Action")] for i in ["help", "no-action"]: if not cnf.has_key("Process-Policy::Options::%s" % (i)): cnf["Process-Policy::Options::%s" % (i)] = "" queue_name = apt_pkg.parse_commandline(cnf.Cnf,Arguments,sys.argv) if len(queue_name) != 1: print "E: Specify exactly one policy queue" sys.exit(1) queue_name = queue_name[0] Options = cnf.subtree("Process-Policy::Options") if Options["Help"]: usage() if not Options["No-Action"]: try: Logger = daklog.Logger("process-policy") except CantOpenError as e: Logger = None # Find policy queue session.query(PolicyQueue) try: pq = session.query(PolicyQueue).filter_by(queue_name=queue_name).one() except NoResultFound: print "E: Cannot find policy queue %s" % queue_name sys.exit(1) commentsdir = os.path.join(pq.path, 'COMMENTS') # The comments stuff relies on being in the right directory os.chdir(pq.path) do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, session) do_comments(commentsdir, pq, "ACCEPTED.", "ACCEPTED.", "OK", comment_accept, session) do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, session)
def main(): cnf = Config() Arguments = [('h', "help", "Make-Overrides::Options::Help")] for i in ["help"]: key = "Make-Overrides::Options::%s" % i if key not in cnf: cnf[key] = "" apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Make-Overrides::Options") if Options["Help"]: usage() d = DBConn() session = d.session() for suite in session.query(Suite).filter(Suite.overrideprocess == True): # noqa:E712 if suite.untouchable: print("Skipping %s as it is marked as untouchable" % suite.suite_name) continue print("Processing %s..." % (suite.suite_name), file=sys.stderr) override_suite = suite.overridecodename or suite.codename for component in session.query(Component).all(): for otype in session.query(OverrideType).all(): otype_name = otype.overridetype cname = component.component_name # TODO: Stick suffix info in database (or get rid of it) if otype_name == "deb": suffix = "" elif otype_name == "udeb": if cname == "contrib": continue # Ick2 suffix = ".debian-installer" elif otype_name == "dsc": suffix = ".src" else: utils.fubar("Don't understand OverrideType %s" % otype.overridetype) cname = cname.replace('/', '_') filename = os.path.join(cnf["Dir::Override"], "override.%s.%s%s" % (override_suite, cname, suffix)) output_file = utils.open_file(filename, 'w') do_list(output_file, suite, component, otype, session) output_file.close()
def main(): from daklib.config import Config config = Config() import apt_pkg arguments = [ ('h', 'help', 'Update-Suite::Options::Help'), ('n', 'no-act', 'Update-Suite::options::NoAct'), ] argv = apt_pkg.parse_commandline(config.Cnf, arguments, sys.argv) try: options = config.subtree("Update-Suite::Options") except KeyError: options = {} if 'Help' in options or len(argv) != 2: usage() origin_name = argv[0] target_name = argv[1] dry_run = True if 'NoAct' in options else False with ArchiveTransaction() as transaction: session = transaction.session try: origin = session.query(Suite).filter_by( suite_name=origin_name).one() except NoResultFound: daklib.utils.fubar( "Origin suite '{0}' is unknown.".format(origin_name)) try: target = session.query(Suite).filter_by( suite_name=target_name).one() except NoResultFound: daklib.utils.fubar( "Target suite '{0}' is unknown.".format(target_name)) su = SuiteUpdater(transaction, origin, target, dry_run=dry_run) su.update_suite() if dry_run: transaction.rollback() else: transaction.commit()
def main (): global Options, Logger cnf = Config() for i in ["Help", "No-Action", "All"]: if not cnf.has_key("Manage-Build-Queues::Options::%s" % (i)): cnf["Manage-Build-Queues::Options::%s" % (i)] = "" Arguments = [('h',"help","Manage-Build-Queues::Options::Help"), ('n',"no-action","Manage-Build-Queues::Options::No-Action"), ('a',"all","Manage-Build-Queues::Options::All")] queue_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Manage-Build-Queues::Options") if Options["Help"]: usage() Logger = daklog.Logger('manage-build-queues', Options['No-Action']) starttime = datetime.now() session = DBConn().session() with ArchiveTransaction() as transaction: session = transaction.session if Options['All']: if len(queue_names) != 0: print "E: Cannot use both -a and a queue name" sys.exit(1) queues = session.query(BuildQueue) else: queues = session.query(BuildQueue).filter(BuildQueue.queue_name.in_(queue_names)) for q in queues: Logger.log(['cleaning queue %s using datetime %s' % (q.queue_name, starttime)]) clean(q, transaction, now=starttime) if not Options['No-Action']: transaction.commit() else: transaction.rollback() Logger.close()
def main(): cnf = Config() cnf['Contents::Options::Help'] = '' cnf['Contents::Options::Suite'] = '' cnf['Contents::Options::Component'] = '' cnf['Contents::Options::Limit'] = '' cnf['Contents::Options::Force'] = '' arguments = [ ('h', "help", 'Contents::Options::Help'), ('a', 'archive', 'Contents::Options::Archive', 'HasArg'), ('s', "suite", 'Contents::Options::Suite', "HasArg"), ('c', "component", 'Contents::Options::Component', "HasArg"), ('l', "limit", 'Contents::Options::Limit', "HasArg"), ('f', "force", 'Contents::Options::Force'), ] args = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) options = cnf.subtree('Contents::Options') if (len(args) != 1) or options['Help']: usage() limit = None if len(options['Limit']) > 0: limit = int(options['Limit']) if args[0] == 'scan-source': source_scan_all(cnf, limit) return if args[0] == 'scan-binary': binary_scan_all(cnf, limit) return archive_names = utils.split_args(options['Archive']) suite_names = utils.split_args(options['Suite']) component_names = utils.split_args(options['Component']) force = bool(options['Force']) if args[0] == 'generate': write_all(cnf, archive_names, suite_names, component_names, force) return usage()
def main(): global Options, Logger cnf = Config() Arguments = [('h', "help", "Obsolete::Options::Help"), ('s', "suite", "Obsolete::Options::Suite", "HasArg"), ('n', "no-action", "Obsolete::Options::No-Action"), ('f', "force", "Obsolete::Options::Force")] cnf['Obsolete::Options::Help'] = '' cnf['Obsolete::Options::No-Action'] = '' cnf['Obsolete::Options::Force'] = '' apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Obsolete::Options") if Options['Help']: usage() if not Options['No-Action']: Logger = daklog.Logger("dominate") session = DBConn().session() suites_query = (session.query(Suite).order_by( Suite.suite_name).filter(~exists().where( Suite.suite_id == PolicyQueue.suite_id))) if 'Suite' in Options: suites_query = suites_query.filter( Suite.suite_name.in_(utils.split_args(Options['Suite']))) if not Options['Force']: suites_query = suites_query.filter_by(untouchable=False) suites = suites_query.all() assocs = list(retrieve_associations(suites, session)) if Options['No-Action']: headers = ('source package', 'source version', 'package', 'version', 'arch', 'suite', 'id') print(tabulate(assocs, headers, tablefmt="orgtbl")) session.rollback() else: delete_associations(assocs, session) session.commit() if Logger: Logger.close()
def main(): cnf = Config() cnf['Contents::Options::Help'] = '' cnf['Contents::Options::Suite'] = '' cnf['Contents::Options::Component'] = '' cnf['Contents::Options::Limit'] = '' cnf['Contents::Options::Force'] = '' arguments = [('h', "help", 'Contents::Options::Help'), ('a', 'archive', 'Contents::Options::Archive', 'HasArg'), ('s', "suite", 'Contents::Options::Suite', "HasArg"), ('c', "component", 'Contents::Options::Component', "HasArg"), ('l', "limit", 'Contents::Options::Limit', "HasArg"), ('f', "force", 'Contents::Options::Force'), ] args = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) options = cnf.subtree('Contents::Options') if (len(args) != 1) or options['Help']: usage() limit = None if len(options['Limit']) > 0: limit = int(options['Limit']) if args[0] == 'scan-source': source_scan_all(cnf, limit) return if args[0] == 'scan-binary': binary_scan_all(cnf, limit) return archive_names = utils.split_args(options['Archive']) suite_names = utils.split_args(options['Suite']) component_names = utils.split_args(options['Component']) force = bool(options['Force']) if args[0] == 'generate': write_all(cnf, archive_names, suite_names, component_names, force) return usage()
def main(): global Options, Logger cnf = Config() for i in ["Help", "No-Action", "All"]: key = "Manage-Debug-Suites::Options::%s" % i if key not in cnf: cnf[key] = "" Arguments = [('h', "help", "Manage-Debug-Suites::Options::Help"), ('n', "no-action", "Manage-Debug-Suites::Options::No-Action"), ('a', "all", "Manage-Debug-Suites::Options::All")] debug_suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Manage-Debug-Suites::Options") if Options["Help"]: usage() Logger = daklog.Logger('manage-debug-suites', Options['No-Action']) with ArchiveTransaction() as transaction: session = transaction.session if Options['All']: if len(debug_suite_names) != 0: print("E: Cannot use both -a and a queue name") sys.exit(1) raise Exception("Not yet implemented.") else: debug_suites = session.query(Suite).filter( Suite.suite_name.in_(debug_suite_names)) for debug_suite in debug_suites: Logger.log( ['cleaning debug suite {0}'.format(debug_suite.suite_name)]) clean(debug_suite, transaction) if not Options['No-Action']: transaction.commit() else: transaction.rollback() Logger.close()
def main(): global Options, Logger cnf = Config() Arguments = [('h', "help", "Obsolete::Options::Help"), ('s', "suite", "Obsolete::Options::Suite", "HasArg"), ('n', "no-action", "Obsolete::Options::No-Action"), ('f', "force", "Obsolete::Options::Force")] cnf['Obsolete::Options::Help'] = '' cnf['Obsolete::Options::No-Action'] = '' cnf['Obsolete::Options::Force'] = '' apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Obsolete::Options") if Options['Help']: usage() if not Options['No-Action']: Logger = daklog.Logger("dominate") session = DBConn().session() suites_query = (session .query(Suite) .order_by(Suite.suite_name) .filter(~exists().where(Suite.suite_id == PolicyQueue.suite_id))) if 'Suite' in Options: suites_query = suites_query.filter(Suite.suite_name.in_(utils.split_args(Options['Suite']))) if not Options['Force']: suites_query = suites_query.filter_by(untouchable=False) suites = suites_query.all() assocs = list(retrieve_associations(suites, session)) if Options['No-Action']: headers = ('source package', 'source version', 'package', 'version', 'arch', 'suite', 'id') print((tabulate(assocs, headers, tablefmt="orgtbl"))) session.rollback() else: delete_associations(assocs, session) session.commit() if Logger: Logger.close()
def main(): from daklib.config import Config config = Config() import apt_pkg arguments = [ ('h', 'help', 'Update-Suite::Options::Help'), ('n', 'no-act', 'Update-Suite::options::NoAct'), ] argv = apt_pkg.parse_commandline(config.Cnf, arguments, sys.argv) try: options = config.subtree("Update-Suite::Options") except KeyError: options = {} if 'Help' in options or len(argv) != 2: usage() origin_name = argv[0] target_name = argv[1] dry_run = True if 'NoAct' in options else False with ArchiveTransaction() as transaction: session = transaction.session try: origin = session.query(Suite).filter_by(suite_name=origin_name).one() except NoResultFound: daklib.utils.fubar("Origin suite '{0}' is unknown.".format(origin_name)) try: target = session.query(Suite).filter_by(suite_name=target_name).one() except NoResultFound: daklib.utils.fubar("Target suite '{0}' is unknown.".format(target_name)) su = SuiteUpdater(transaction, origin, target, dry_run=dry_run) su.update_suite() if dry_run: transaction.rollback() else: transaction.commit()
def main(): global Options, Logger cnf = Config() for i in ["Help", "Incoming", "No-Action", "Verbose"]: key = "Clean-Queues::Options::%s" % i if key not in cnf: cnf[key] = "" if "Clean-Queues::Options::Days" not in cnf: cnf["Clean-Queues::Options::Days"] = "14" Arguments = [('h', "help", "Clean-Queues::Options::Help"), ('d', "days", "Clean-Queues::Options::Days", "IntLevel"), ('i', "incoming", "Clean-Queues::Options::Incoming", "HasArg"), ('n', "no-action", "Clean-Queues::Options::No-Action"), ('v', "verbose", "Clean-Queues::Options::Verbose")] apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Clean-Queues::Options") if Options["Help"]: usage() Logger = daklog.Logger('clean-queues', Options['No-Action']) init(cnf) if Options["Verbose"]: print("Processing incoming...") flush_orphans() reject = cnf["Dir::Reject"] if os.path.exists(reject) and os.path.isdir(reject): if Options["Verbose"]: print("Processing reject directory...") os.chdir(reject) flush_old() Logger.close()
def main(): global Options, Logger cnf = Config() Arguments = [ ("h", "help", "Obsolete::Options::Help"), ("s", "suite", "Obsolete::Options::Suite", "HasArg"), ("n", "no-action", "Obsolete::Options::No-Action"), ("f", "force", "Obsolete::Options::Force"), ] cnf["Obsolete::Options::Help"] = "" cnf["Obsolete::Options::No-Action"] = "" cnf["Obsolete::Options::Force"] = "" apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Obsolete::Options") if Options["Help"]: usage() if "Suite" not in Options: query_suites = DBConn().session().query(Suite) suites = [suite.suite_name for suite in query_suites] cnf["Obsolete::Options::Suite"] = str(",".join(suites)) if not Options["No-Action"]: Logger = daklog.Logger("dominate") session = DBConn().session() for suite_name in utils.split_args(Options["Suite"]): suite = session.query(Suite).filter_by(suite_name=suite_name).one() # Skip policy queues. We don't want to remove obsolete packages from those. policy_queue = session.query(PolicyQueue).filter_by(suite=suite).first() if policy_queue is not None: continue if not suite.untouchable or Options["Force"]: doDaDoDa(suite.suite_id, session) if Options["No-Action"]: session.rollback() else: session.commit() if Logger: Logger.close()
def do_update(self): """ Add suite options for overrides and control-suite to DB """ print(__doc__) try: cnf = Config() c = self.db.cursor() c.execute("ALTER TABLE suite ADD COLUMN overrideprocess BOOLEAN NOT NULL DEFAULT FALSE") c.execute("COMMENT ON COLUMN suite.overrideprocess IS %s", ['If true, check-overrides will process the suite by default']) c.execute("ALTER TABLE suite ADD COLUMN overrideorigin TEXT DEFAULT NULL") c.execute("COMMENT ON COLUMN suite.overrideprocess IS %s", ['If NOT NULL, check-overrides will take missing overrides from the named suite']) # Migrate config file values into database if "Check-Overrides::OverrideSuites" in cnf: for suitename in cnf.subtree("Check-Overrides::OverrideSuites").list(): if cnf.get("Check-Overrides::OverrideSuites::%s::Process" % suitename, "0") == "1": print("Marking %s to have overrides processed automatically" % suitename.lower()) c.execute("UPDATE suite SET overrideprocess = TRUE WHERE suite_name = %s", [suitename.lower()]) originsuite = cnf.get("Check-Overrides::OverrideSuites::%s::OriginSuite" % suitename, '') if originsuite != '': print("Setting %s to use %s as origin for overrides" % (suitename.lower(), originsuite.lower())) c.execute("UPDATE suite SET overrideorigin = %s WHERE suite_name = %s", [originsuite.lower(), suitename.lower()]) c.execute("ALTER TABLE suite ADD COLUMN allowcsset BOOLEAN NOT NULL DEFAULT FALSE") c.execute("COMMENT ON COLUMN suite.allowcsset IS %s", ['Allow control-suite to be used with the --set option without forcing']) # Import historical hard-coded values c.execute("UPDATE suite SET allowcsset = TRUE WHERE suite_name IN ('testing', 'squeeze-updates')") c.execute("UPDATE config SET value = '70' WHERE name = 'db_revision'") self.db.commit() except psycopg2.ProgrammingError as msg: self.db.rollback() raise DBUpdateError('Unable to apply sick update 70, rollback issued. Error message : %s' % (str(msg)))
def main(): cnf = Config() Arguments = [ ('h', "help", "DEP11::Options::Help"), ('e', "expire", "DEP11::Options::ExpireCache"), ('s', "suite", "DEP11::Options::Suite", "HasArg"), ] for i in ["help", "suite", "ExpireCache"]: if not cnf.has_key("DEP11::Options::%s" % (i)): cnf["DEP11::Options::%s" % (i)] = "" arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("DEP11::Options") if Options["Help"]: usage() return suitename = Options["Suite"] if not suitename: print("You need to specify a suite!") return logger = daklog.Logger('generate-metadata') from daklib.dbconn import Component, DBConn, get_suite, Suite session = DBConn().session() suite = get_suite(suitename.lower(), session) if Options["ExpireCache"]: expire_dep11_data_cache(session, suitename) process_suite(session, suite, logger) # export database content as Components-<arch>.xz YAML documents write_component_files(suite) # we're done logger.close()
def main(): global Options, Logger cnf = Config() Arguments = [('h', "help", "Obsolete::Options::Help"), ('s', "suite", "Obsolete::Options::Suite", "HasArg"), ('n', "no-action", "Obsolete::Options::No-Action"), ('f', "force", "Obsolete::Options::Force")] cnf['Obsolete::Options::Help'] = '' cnf['Obsolete::Options::No-Action'] = '' cnf['Obsolete::Options::Force'] = '' apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Obsolete::Options") if Options['Help']: usage() if 'Suite' not in Options: query_suites = DBConn().session().query(Suite) suites = [suite.suite_name for suite in query_suites] cnf['Obsolete::Options::Suite'] = str(','.join(suites)) if not Options['No-Action']: Logger = daklog.Logger("dominate") session = DBConn().session() for suite_name in utils.split_args(Options['Suite']): suite = session.query(Suite).filter_by(suite_name = suite_name).one() # Skip policy queues. We don't want to remove obsolete packages from those. policy_queue = session.query(PolicyQueue).filter_by(suite=suite).first() if policy_queue is not None: continue if not suite.untouchable or Options['Force']: doDaDoDa(suite.suite_id, session) if Options['No-Action']: session.rollback() else: session.commit() if Logger: Logger.close()
def is_autobyhand(u): cnf = Config() all_auto = 1 any_auto = 0 for f in u.pkg.files.keys(): if u.pkg.files[f].has_key("byhand"): any_auto = 1 # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH # don't contain underscores, and ARCH doesn't contain dots. # further VER matches the .changes Version:, and ARCH should be in # the .changes Architecture: list. if f.count("_") < 2: all_auto = 0 continue (pckg, ver, archext) = f.split("_", 2) if archext.count(".") < 1 or u.pkg.changes["version"] != ver: all_auto = 0 continue ABH = cnf.subtree("AutomaticByHandPackages") if not ABH.has_key(pckg) or \ ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]: print "not match %s %s" % (pckg, u.pkg.changes["source"]) all_auto = 0 continue (arch, ext) = archext.split(".", 1) if arch not in u.pkg.changes["architecture"]: all_auto = 0 continue u.pkg.files[f]["byhand-arch"] = arch u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)] return any_auto and all_auto
def main(): global Options cnf = Config() Arguments = [ ('h', "help", "Import-Keyring::Options::Help"), ('L', "import-ldap-users", "Import-Keyring::Options::Import-Ldap-Users"), ('U', "generate-users", "Import-Keyring::Options::Generate-Users", "HasArg"), ('l', "list-uids", "Import-Keyring::Options::List-UIDs", "HasArg"), ('n', "no-action", "Import-Keyring::Options::No-Action"), ] for i in [ "help", "report-changes", "generate-users", "import-ldap-users", "list-uids", "no-action" ]: key = "Import-Keyring::Options::%s" % i if key not in cnf: cnf[key] = "" keyring_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) ### Parse options Options = cnf.subtree("Import-Keyring::Options") if Options["Help"]: usage() ### Initialise session = DBConn().session() if Options["List-UIDs"]: list_uids(session, Options["List-UIDs"]) sys.exit(0) if len(keyring_names) != 1: usage(1) ### Keep track of changes made changes = [] # (uid, changes strings) ### Cache all the existing fingerprint entries db_fin_info = get_fingerprint_info(session) ### Parse the keyring keyringname = keyring_names[0] keyring = get_keyring(keyringname, session) if not keyring: print "E: Can't load keyring %s from database" % keyringname sys.exit(1) keyring.load_keys(keyringname) ### Generate new uid entries if they're needed (from LDAP or the keyring) if Options["Generate-Users"]: format = Options["Generate-Users"] (desuid_byname, desuid_byid) = keyring.generate_users_from_keyring( Options["Generate-Users"], session) elif Options["Import-Ldap-Users"]: (desuid_byname, desuid_byid) = keyring.import_users_from_ldap(session) else: (desuid_byname, desuid_byid) = ({}, {}) ### Cache all the existing uid entries (db_uid_byname, db_uid_byid) = get_uid_info(session) ### Update full names of applicable users for keyid in desuid_byid.keys(): uid = (keyid, desuid_byid[keyid][0]) name = desuid_byid[keyid][1] oname = db_uid_byid[keyid][1] if name and oname != name: changes.append((uid[1], "Full name: %s" % (name))) session.execute("UPDATE uid SET name = :name WHERE id = :keyid", { 'name': name, 'keyid': keyid }) # The fingerprint table (fpr) points to a uid and a keyring. # If the uid is being decided here (ldap/generate) we set it to it. # Otherwise, if the fingerprint table already has a uid (which we've # cached earlier), we preserve it. # Otherwise we leave it as None fpr = {} for z in keyring.keys.keys(): keyid = db_uid_byname.get(keyring.keys[z].get("uid", None), [None])[0] if keyid == None: keyid = db_fin_info.get(keyring.keys[z]["fingerprints"][0], [None])[0] for y in keyring.keys[z]["fingerprints"]: fpr[y] = (keyid, keyring.keyring_id) # For any keys that used to be in this keyring, disassociate them. # We don't change the uid, leaving that for historical info; if # the id should change, it'll be set when importing another keyring. for f, (u, fid, kr) in db_fin_info.iteritems(): if kr != keyring.keyring_id: continue if f in fpr: continue changes.append((db_uid_byid.get(u, [None])[0], "Removed key: %s" % (f))) session.execute( """UPDATE fingerprint SET keyring = NULL WHERE id = :fprid""", {'fprid': fid}) # For the keys in this keyring, add/update any fingerprints that've # changed. for f in fpr: newuid = fpr[f][0] newuiduid = db_uid_byid.get(newuid, [None])[0] (olduid, oldfid, oldkid) = db_fin_info.get(f, [-1, -1, -1]) if olduid == None: olduid = -1 if oldkid == None: oldkid = -1 if oldfid == -1: changes.append((newuiduid, "Added key: %s" % (f))) fp = Fingerprint() fp.fingerprint = f fp.keyring_id = keyring.keyring_id if newuid: fp.uid_id = newuid session.add(fp) session.flush() else: if newuid and olduid != newuid and olduid == -1: changes.append((newuiduid, "Linked key: %s" % f)) changes.append((newuiduid, " (formerly unowned)")) session.execute( "UPDATE fingerprint SET uid = :uid WHERE id = :fpr", { 'uid': newuid, 'fpr': oldfid }) # Don't move a key from a keyring with a higher priority to a lower one if oldkid != keyring.keyring_id: movekey = False if oldkid == -1: movekey = True else: try: oldkeyring = session.query(Keyring).filter_by( keyring_id=oldkid).one() except NotFoundError: print "ERROR: Cannot find old keyring with id %s" % oldkid sys.exit(1) if oldkeyring.priority < keyring.priority: movekey = True # Only change the keyring if it won't result in a loss of permissions if movekey: session.execute( """UPDATE fingerprint SET keyring = :keyring WHERE id = :fpr""", { 'keyring': keyring.keyring_id, 'fpr': oldfid }) session.flush() else: print "Key %s exists in both %s and %s keyrings. Not demoting." % ( f, oldkeyring.keyring_name, keyring.keyring_name) # All done! if Options["No-Action"]: session.rollback() else: session.commit() # Print a summary changesd = {} for (k, v) in changes: if k not in changesd: changesd[k] = "" changesd[k] += " %s\n" % (v) keys = changesd.keys() keys.sort() for k in keys: print "%s\n%s\n" % (k, changesd[k])
def main(): global Options, Logger cnf = Config() for i in ["Help", "No-Action", "Maximum"]: key = "Clean-Suites::Options::%s" % i if key not in cnf: cnf[key] = "" Arguments = [('h', "help", "Clean-Suites::Options::Help"), ('a', 'archive', 'Clean-Suites::Options::Archive', 'HasArg'), ('n', "no-action", "Clean-Suites::Options::No-Action"), ('m', "maximum", "Clean-Suites::Options::Maximum", "HasArg")] apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Clean-Suites::Options") if cnf["Clean-Suites::Options::Maximum"] != "": try: # Only use Maximum if it's an integer max_delete = int(cnf["Clean-Suites::Options::Maximum"]) if max_delete < 1: utils.fubar("If given, Maximum must be at least 1") except ValueError as e: utils.fubar("If given, Maximum must be an integer") else: max_delete = None if Options["Help"]: usage() program = "clean-suites" if Options['No-Action']: program = "clean-suites (no action)" Logger = daklog.Logger(program, debug=Options["No-Action"]) session = DBConn().session() archives = None if 'Archive' in Options: archive_names = Options['Archive'].split(',') archives = session.query(Archive).filter( Archive.archive_name.in_(archive_names)).all() if len(archives) == 0: utils.fubar('Unknown archive.') now_date = datetime.now() set_archive_delete_dates(now_date, session) check_binaries(now_date, session) clean_binaries(now_date, session) check_sources(now_date, session) check_files(now_date, session) clean(now_date, archives, max_delete, session) clean_maintainers(now_date, session) clean_fingerprints(now_date, session) clean_byhash(now_date, session) clean_empty_directories(session) session.rollback() Logger.close()
def main(): global Logger cnf = Config() for i in ["Help", "Suite", "Force", "Quiet"]: key = "Generate-Releases::Options::%s" % i if key not in cnf: cnf[key] = "" Arguments = [('h', "help", "Generate-Releases::Options::Help"), ('a', 'archive', 'Generate-Releases::Options::Archive', 'HasArg'), ('s', "suite", "Generate-Releases::Options::Suite"), ('f', "force", "Generate-Releases::Options::Force"), ('q', "quiet", "Generate-Releases::Options::Quiet"), ('o', 'option', '', 'ArbItem')] suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) Options = cnf.subtree("Generate-Releases::Options") if Options["Help"]: usage() Logger = daklog.Logger('generate-releases') pool = DakProcessPool() session = DBConn().session() if Options["Suite"]: suites = [] for s in suite_names: suite = get_suite(s.lower(), session) if suite: suites.append(suite) else: print("cannot find suite %s" % s) Logger.log(['cannot find suite %s' % s]) else: query = session.query(Suite).filter(Suite.untouchable == False) # noqa:E712 if 'Archive' in Options: archive_names = utils.split_args(Options['Archive']) query = query.join(Suite.archive).filter(Archive.archive_name.in_(archive_names)) suites = query.all() for s in suites: # Setup a multiprocessing Pool. As many workers as we have CPU cores. if s.untouchable and not Options["Force"]: print("Skipping %s (untouchable)" % s.suite_name) continue if not Options["Quiet"]: print("Processing %s" % s.suite_name) Logger.log(['Processing release file for Suite: %s' % (s.suite_name)]) pool.apply_async(generate_helper, (s.suite_id, )) # No more work will be added to our pool, close it and then wait for all to finish pool.close() pool.join() retcode = pool.overall_status() if retcode > 0: # TODO: CENTRAL FUNCTION FOR THIS / IMPROVE LOGGING Logger.log(['Release file generation broken: %s' % (','.join([str(x[1]) for x in pool.results]))]) Logger.close() sys.exit(retcode)
def main(argv=None): if argv is None: argv = sys.argv arguments = [('h', 'help', 'Process-Commands::Options::Help'), ('d', 'directory', 'Process-Commands::Options::Directory', 'HasArg')] cnf = Config() cnf['Process-Commands::Options::Dummy'] = '' filenames = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv) options = cnf.subtree('Process-Commands::Options') if 'Help' in options or (len(filenames) == 0 and 'Directory' not in options): usage() sys.exit(0) log = Logger('command') now = datetime.datetime.now() donedir = os.path.join(cnf['Dir::Done'], now.strftime('%Y/%m/%d')) rejectdir = cnf['Dir::Reject'] if len(filenames) == 0: cdir = options['Directory'] filenames = [ os.path.join(cdir, fn) for fn in os.listdir(cdir) if fn.endswith('.dak-commands') ] for fn in filenames: basename = os.path.basename(fn) if not fn.endswith('.dak-commands'): log.log(['unexpected filename', basename]) continue with open(fn, 'r') as fh: data = fh.read() try: command = CommandFile(basename, data, log) command.evaluate() except CommandError as e: created = os.stat(fn).st_mtime now = time.time() too_new = (now - created < int(cnf.get('Dinstall::SkipTime', '60'))) if too_new: log.log(['skipped (too new)']) continue log.log(['reject', basename, e]) except Exception as e: log.log_traceback('Exception while processing %s:' % (basename), e) dst = find_next_free(os.path.join(rejectdir, basename)) else: log.log(['done', basename]) dst = find_next_free(os.path.join(donedir, basename)) with FilesystemTransaction() as fs: fs.unlink(fn) fs.create(dst, mode=0o644).write(data) fs.commit() log.close()