Package dak :: Module export
[hide private]
[frames] | no frames]

Source Code for Module dak.export

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