[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Add export subcommand to export upload from policy queues.



---
 dak/dak.py    |    2 +
 dak/export.py |   75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100644 dak/export.py

diff --git a/dak/dak.py b/dak/dak.py
index b6e77ad..20e8886 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 0000000..8545167
--- /dev/null
+++ b/dak/export.py
@@ -0,0 +1,75 @@
+#! /usr/bin/env python
+#
+# Copyright (C) 2012, Ansgar Burchardt <ansgar@debian.org>
+#
+# 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 <queue> [options] -a|--all|<source...>
+
+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 <directory>    target directory to export packages to
+                   default: current directory
+ -q <queue>        queue to grab uploads from
+ <source>          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()
-- 
1.7.2.5



Reply to: