1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
28 print("""Usage: dak export -q <queue> [options] -a|--all|<source...>
29
30 Export uploads from policy queues, that is the changes files for the given
31 source package and all other files associated with that.
32
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 """)
40
41
43 if argv is None:
44 argv = sys.argv
45
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')]
51
52 cnf = Config()
53 source_names = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
54 options = cnf.subtree('Export::Options')
55
56 if 'Help' in options or 'Queue' not in options:
57 usage()
58 sys.exit(0)
59
60 session = DBConn().session()
61
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
71
72 for u in uploads:
73 UploadCopy(u).export(directory, symlink=symlink, ignore_existing=True)
74
75
76 if __name__ == '__main__':
77 main()
78