3 # Copyright (C) 2012, Ansgar Burchardt <ansgar@debian.org>
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.
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.
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.
23 from daklib.config import Config
24 from daklib.dbconn import *
25 from daklib.fstransactions import FilesystemTransaction
28 print """Usage: dak export-suite -s <suite> [options]
30 Export binaries and sources from a suite to a flat directory structure.
32 -c --copy copy files instead of symlinking them
33 -d <directory> target directory to export packages to
34 default: current directory
35 -r --relative use symlinks relative to target directory
36 -s <suite> suite to grab uploads from
43 arguments = [('h', 'help', 'Export::Options::Help'),
44 ('c', 'copy', 'Export::Options::Copy'),
45 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
46 ('r', 'relative', 'Export::Options::Relative'),
47 ('s', 'suite', 'Export::Options::Suite', 'HasArg')]
50 apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
51 options = cnf.subtree('Export::Options')
53 if 'Help' in options or 'Suite' not in options:
57 session = DBConn().session()
59 suite = session.query(Suite).filter_by(suite_name=options['Suite']).first()
61 print "Unknown suite '{0}'".format(options['Suite'])
64 directory = options.get('Directory')
66 print "No target directory."
69 symlink = 'Copy' not in options
70 relative = 'Relative' in options
72 if relative and not symlink:
73 print "E: --relative and --copy cannot be used together."
76 binaries = suite.binaries
77 sources = suite.sources
80 files.extend([ b.poolfile for b in binaries ])
82 files.extend([ ds.poolfile for ds in s.srcfiles ])
84 with FilesystemTransaction() as fs:
86 af = session.query(ArchiveFile) \
87 .join(ArchiveFile.component).join(ArchiveFile.file) \
88 .filter(ArchiveFile.archive == suite.archive) \
89 .filter(ArchiveFile.file == f).first()
90 # XXX: Remove later. There was a bug that caused only the *.dsc to
91 # be installed in build queues and we do not want to break them.
92 # The bug was fixed in 55d2c7e6e2418518704623246021021e05b90e58
95 af = session.query(ArchiveFile) \
96 .join(ArchiveFile.component).join(ArchiveFile.file) \
97 .filter(ArchiveFile.file == f).first()
100 src = os.path.relpath(src, directory)
101 dst = os.path.join(directory, f.basename)
102 if not os.path.exists(dst):
103 fs.copy(src, dst, symlink=symlink)
106 if __name__ == '__main__':