3 """Manage build queues"""
4 # Copyright (C) 2000, 2001, 2002, 2006 James Troup <james@nocrew.org>
5 # Copyright (C) 2009 Mark Hymers <mhy@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ################################################################################
23 import os, os.path, stat, sys
24 from datetime import datetime
27 from daklib import daklog
28 from daklib.dbconn import *
29 from daklib.config import Config
31 ################################################################################
36 ################################################################################
38 def usage (exit_code=0):
39 print """Usage: dak manage-build-queues [OPTIONS] buildqueue1 buildqueue2
40 Manage the contents of one or more build queues
42 -a, --all run on all known build queues
43 -n, --no-action don't do anything
44 -v, --verbose explain what is being done
45 -h, --help show this help and exit"""
49 ################################################################################
52 global Options, Logger
56 for i in ["Help", "No-Action", "Verbose", "All"]:
57 if not cnf.has_key("Manage-Build-Queues::Options::%s" % (i)):
58 cnf["Manage-Build-Queues::Options::%s" % (i)] = ""
60 Arguments = [('h',"help","Manage-Build-Queues::Options::Help"),
61 ('n',"no-action","Manage-Build-Queues::Options::No-Action"),
62 ('a',"all","Manage-Build-Queues::Options::All"),
63 ('v',"verbose","Manage-Build-Queues::Options::Verbose")]
65 queue_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
66 Options = cnf.SubTree("Manage-Build-Queues::Options")
71 Logger = daklog.Logger(cnf, 'manage-build-queues', Options['No-Action'])
73 starttime = datetime.now()
75 session = DBConn().session()
78 if len(queue_names) != 0:
79 print "E: Cannot use both -a and a queue_name"
81 queues = session.query(BuildQueue).all()
86 queue = get_build_queue(q.lower(), session)
90 Logger.log(['cannot find queue %s' % q])
92 # For each given queue, look up object and call manage_queue
94 Logger.log(['cleaning queue %s using datetime %s' % (q.queue_name, starttime)])
95 q.clean_and_update(starttime, dryrun=Options["No-Action"])
99 #######################################################################################
101 if __name__ == '__main__':