From: Ansgar Burchardt Date: Sun, 1 Jul 2012 12:13:42 +0000 (+0200) Subject: Add export subcommand to export upload from policy queues. X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=f2027f086182b71e083bab22c778fd9ed678ca33;p=dak.git Add export subcommand to export upload from policy queues. --- diff --git a/dak/dak.py b/dak/dak.py index b6e77ad4..20e88864 100755 --- a/dak/dak.py +++ b/dak/dak.py @@ -76,6 +76,8 @@ def init(): ("dominate", "Remove obsolete source and binary associations from suites"), + ("export", + "Export uploads from policy queues"), ("make-pkg-file-mapping", "Generate package <-> file mapping"), ("generate-filelist", diff --git a/dak/export.py b/dak/export.py new file mode 100644 index 00000000..8545167c --- /dev/null +++ b/dak/export.py @@ -0,0 +1,75 @@ +#! /usr/bin/env python +# +# Copyright (C) 2012, Ansgar Burchardt +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import apt_pkg +import sys + +from daklib.config import Config +from daklib.dbconn import * +from daklib.policy import UploadCopy + +def usage(): + print """Usage: dak export -q [options] -a|--all| + +Export uploads from policy queues, that is the changes files for the given +source package and all other files associated with that. + + -a --all export all uploads + -c --copy copy files instead of symlinking them + -d target directory to export packages to + default: current directory + -q queue to grab uploads from + source package name to export +""" + +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: + print "Processing {0}...".format(u.changes.changesname) + UploadCopy(u).export(directory, symlink=symlink) + +if __name__ == '__main__': + main()