]> git.decadent.org.uk Git - dak.git/blob - dak/export.py
auto-decruft: Expand NVI in cmd line argument names
[dak.git] / dak / export.py
1 #! /usr/bin/env python
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.
18
19 import apt_pkg
20 import sys
21
22 from daklib.config import Config
23 from daklib.dbconn import *
24 from daklib.policy import UploadCopy
25
26 def usage():
27     print """Usage: dak export -q <queue> [options] -a|--all|<source...>
28
29 Export uploads from policy queues, that is the changes files for the given
30 source package and all other files associated with that.
31
32  -a --all          export all uploads
33  -c --copy         copy files instead of symlinking them
34  -d <directory>    target directory to export packages to
35                    default: current directory
36  -q <queue>        queue to grab uploads from
37  <source>          source package name to export
38 """
39
40 def main(argv=None):
41     if argv is None:
42         argv = sys.argv
43
44     arguments = [('h', 'help', 'Export::Options::Help'),
45                  ('a', 'all', 'Export::Options::All'),
46                  ('c', 'copy', 'Export::Options::Copy'),
47                  ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
48                  ('q', 'queue', 'Export::Options::Queue', 'HasArg')]
49
50     cnf = Config()
51     source_names = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
52     options = cnf.subtree('Export::Options')
53
54     if 'Help' in options or 'Queue' not in options:
55         usage()
56         sys.exit(0)
57
58     session = DBConn().session()
59
60     queue = session.query(PolicyQueue).filter_by(queue_name=options['Queue']).first()
61     if queue is None:
62         print "Unknown queue '{0}'".format(options['Queue'])
63         sys.exit(1)
64     uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=queue)
65     if 'All' not in options:
66         uploads = uploads.filter(DBChange.source.in_(source_names))
67     directory = options.get('Directory', '.')
68     symlink = 'Copy' not in options
69
70     for u in uploads:
71         UploadCopy(u).export(directory, symlink=symlink, ignore_existing=True)
72
73 if __name__ == '__main__':
74     main()