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 -s <suite> suite to grab uploads from
42 arguments = [('h', 'help', 'Export::Options::Help'),
43 ('c', 'copy', 'Export::Options::Copy'),
44 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
45 ('s', 'suite', 'Export::Options::Suite', 'HasArg')]
48 apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
49 options = cnf.subtree('Export::Options')
51 if 'Help' in options or 'Suite' not in options:
55 session = DBConn().session()
57 suite = session.query(Suite).filter_by(suite_name=options['Suite']).first()
59 print "Unknown suite '{0}'".format(options['Suite'])
62 directory = options.get('Directory')
64 print "No target directory."
67 symlink = 'Copy' not in options
69 binaries = suite.binaries
70 sources = suite.sources
73 files.extend([ b.poolfile for b in binaries ])
75 files.extend([ ds.poolfile for ds in s.srcfiles ])
77 with FilesystemTransaction() as fs:
79 af = session.query(ArchiveFile) \
80 .join(ArchiveFile.component).join(ArchiveFile.file) \
81 .filter(ArchiveFile.archive == suite.archive) \
82 .filter(ArchiveFile.file == f).first()
83 # XXX: Remove later. There was a bug that caused only the *.dsc to
84 # be installed in build queues and we do not want to break them.
85 # The bug was fixed in 55d2c7e6e2418518704623246021021e05b90e58
88 af = session.query(ArchiveFile) \
89 .join(ArchiveFile.component).join(ArchiveFile.file) \
90 .filter(ArchiveFile.file == f).first()
91 dst = os.path.join(directory, f.basename)
92 if not os.path.exists(dst):
93 fs.copy(af.path, dst, symlink=symlink)
96 if __name__ == '__main__':