1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import apt_pkg
20 import os
21 import sys
22
23 from daklib.config import Config
24 from daklib.dbconn import *
25 from daklib.fstransactions import FilesystemTransaction
26
27
29 print("""Usage: dak export-suite -s <suite> [options]
30
31 Export binaries and sources from a suite to a flat directory structure.
32
33 -c --copy copy files instead of symlinking them
34 -d <directory> target directory to export packages to
35 default: current directory
36 -r --relative use symlinks relative to target directory
37 -s <suite> suite to grab uploads from
38 """)
39
40
42 if argv is None:
43 argv = sys.argv
44
45 arguments = [('h', 'help', 'Export::Options::Help'),
46 ('c', 'copy', 'Export::Options::Copy'),
47 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
48 ('r', 'relative', 'Export::Options::Relative'),
49 ('s', 'suite', 'Export::Options::Suite', 'HasArg')]
50
51 cnf = Config()
52 apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
53 options = cnf.subtree('Export::Options')
54
55 if 'Help' in options or 'Suite' not in options:
56 usage()
57 sys.exit(0)
58
59 session = DBConn().session()
60
61 suite = session.query(Suite).filter_by(suite_name=options['Suite']).first()
62 if suite is None:
63 print("Unknown suite '{0}'".format(options['Suite']))
64 sys.exit(1)
65
66 directory = options.get('Directory')
67 if not directory:
68 print("No target directory.")
69 sys.exit(1)
70
71 symlink = 'Copy' not in options
72 relative = 'Relative' in options
73
74 if relative and not symlink:
75 print("E: --relative and --copy cannot be used together.")
76 sys.exit(1)
77
78 binaries = suite.binaries
79 sources = suite.sources
80
81 files = []
82 files.extend([b.poolfile for b in binaries])
83 for s in sources:
84 files.extend([ds.poolfile for ds in s.srcfiles])
85
86 with FilesystemTransaction() as fs:
87 for f in files:
88 af = session.query(ArchiveFile) \
89 .join(ArchiveFile.component).join(ArchiveFile.file) \
90 .filter(ArchiveFile.archive == suite.archive) \
91 .filter(ArchiveFile.file == f).first()
92 src = af.path
93 if relative:
94 src = os.path.relpath(src, directory)
95 dst = os.path.join(directory, f.basename)
96 if not os.path.exists(dst):
97 fs.copy(src, dst, symlink=symlink)
98 fs.commit()
99
100
101 if __name__ == '__main__':
102 main()
103