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 -h, --help show this help and exit"""
48 ################################################################################
51 global Options, Logger
55 for i in ["Help", "No-Action", "All"]:
56 if not cnf.has_key("Manage-Build-Queues::Options::%s" % (i)):
57 cnf["Manage-Build-Queues::Options::%s" % (i)] = ""
59 Arguments = [('h',"help","Manage-Build-Queues::Options::Help"),
60 ('n',"no-action","Manage-Build-Queues::Options::No-Action"),
61 ('a',"all","Manage-Build-Queues::Options::All")]
63 queue_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
64 Options = cnf.SubTree("Manage-Build-Queues::Options")
69 Logger = daklog.Logger(cnf, 'manage-build-queues', Options['No-Action'])
71 starttime = datetime.now()
73 session = DBConn().session()
76 if len(queue_names) != 0:
77 print "E: Cannot use both -a and a queue_name"
79 queues = session.query(BuildQueue).all()
84 queue = get_build_queue(q.lower(), session)
88 Logger.log(['cannot find queue %s' % q])
90 # For each given queue, look up object and call manage_queue
92 Logger.log(['cleaning queue %s using datetime %s' % (q.queue_name, starttime)])
93 q.clean_and_update(starttime, Logger, dryrun=Options["No-Action"])
97 #######################################################################################
99 if __name__ == '__main__':