1#! /usr/bin/env python3
2#
3# Copyright (C) 2012, Ansgar Burchardt <ansgar@debian.org>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19import apt_pkg
20import sys
22from daklib.config import Config
23from daklib.dbconn import *
24from daklib.policy import UploadCopy
27def usage():
28 print("""Usage: dak export -q <queue> [options] -a|--all|<source...>
30Export uploads from policy queues, that is the changes files for the given
31source package and all other files associated with that.
33 -a --all export all uploads
34 -c --copy copy files instead of symlinking them
35 -d <directory> target directory to export packages to
36 default: current directory
37 -q <queue> queue to grab uploads from
38 <source> source package name to export
39""")
42def main(argv=None):
43 if argv is None: 43 ↛ 46line 43 didn't jump to line 46, because the condition on line 43 was never false
44 argv = sys.argv
46 arguments = [('h', 'help', 'Export::Options::Help'),
47 ('a', 'all', 'Export::Options::All'),
48 ('c', 'copy', 'Export::Options::Copy'),
49 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
50 ('q', 'queue', 'Export::Options::Queue', 'HasArg')]
52 cnf = Config()
53 source_names = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
54 options = cnf.subtree('Export::Options')
56 if 'Help' in options or 'Queue' not in options: 56 ↛ 60line 56 didn't jump to line 60, because the condition on line 56 was never false
57 usage()
58 sys.exit(0)
60 session = DBConn().session()
62 queue = session.query(PolicyQueue).filter_by(queue_name=options['Queue']).first()
63 if queue is None:
64 print("Unknown queue '{0}'".format(options['Queue']))
65 sys.exit(1)
66 uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=queue)
67 if 'All' not in options:
68 uploads = uploads.filter(DBChange.source.in_(source_names))
69 directory = options.get('Directory', '.')
70 symlink = 'Copy' not in options
72 for u in uploads:
73 UploadCopy(u).export(directory, symlink=symlink, ignore_existing=True)
76if __name__ == '__main__':
77 main()