From 81b7481eaee512c4e93fd73bc4853fd316c9c37a Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Sun, 12 Aug 2012 09:50:38 +0200 Subject: [PATCH] add export-suite subcommand to export a suite to a flat directory --- dak/dak.py | 2 ++ dak/export_suite.py | 84 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 dak/export_suite.py diff --git a/dak/dak.py b/dak/dak.py index 20e88864..7e78bc29 100755 --- a/dak/dak.py +++ b/dak/dak.py @@ -78,6 +78,8 @@ def init(): "Remove obsolete source and binary associations from suites"), ("export", "Export uploads from policy queues"), + ("export-suite", + "export a suite to a flat directory structure"), ("make-pkg-file-mapping", "Generate package <-> file mapping"), ("generate-filelist", diff --git a/dak/export_suite.py b/dak/export_suite.py new file mode 100644 index 00000000..a4a59531 --- /dev/null +++ b/dak/export_suite.py @@ -0,0 +1,84 @@ +#! /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 os +import sys + +from daklib.config import Config +from daklib.dbconn import * +from daklib.fstransactions import FilesystemTransaction + +def usage(): + print """Usage: dak export-suite -s [options] + +Export binaries and sources from a suite to a flat directory structure. + + -c --copy copy files instead of symlinking them + -d target directory to export packages to + default: current directory + -s suite to grab uploads from +""" + +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: + dst = os.path.join(directory, f.basename) + fs.copy(f.fullpath, dst, symlink=symlink) + fs.commit() + +if __name__ == '__main__': + main() -- 2.39.5