]> git.decadent.org.uk Git - dak.git/blob - dak/manage_build_queues.py
manage_build_queues fixups
[dak.git] / dak / manage_build_queues.py
1 #!/usr/bin/env python
2
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>
6
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.
11
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.
16
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
20
21 ################################################################################
22
23 import os, os.path, stat, sys
24 from datetime import datetime
25 import apt_pkg
26
27 from daklib import daklog
28 from daklib.dbconn import *
29 from daklib.config import Config
30
31 ################################################################################
32
33 Options = None
34 Logger = None
35
36 ################################################################################
37
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
41
42   -n, --no-action            don't do anything
43   -v, --verbose              explain what is being done
44   -h, --help                 show this help and exit"""
45
46     sys.exit(exit_code)
47
48 ################################################################################
49
50 def main ():
51     global Options, Logger
52
53     cnf = Config()
54
55     for i in ["Help", "No-Action", "Verbose" ]:
56         if not cnf.has_key("Manage-Build-Queues::Options::%s" % (i)):
57             cnf["Manage-Build-Queues::Options::%s" % (i)] = ""
58
59     Arguments = [('h',"help","Manage-Build-Queues::Options::Help"),
60                  ('n',"no-action","Manage-Build-Queues::Options::No-Action"),
61                  ('v',"verbose","Manage-Build-Queues::Options::Verbose")]
62
63     queue_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
64     Options = cnf.SubTree("Manage-Build-Queues::Options")
65
66     if Options["Help"]:
67         usage()
68
69     Logger = daklog.Logger(cnf, 'manage-build-queues', Options['No-Action'])
70
71     starttime = datetime.now()
72
73     # For each given queue, look up object and call manage_queue
74     for q in queue_names:
75         session = DBConn().session()
76         queue = get_build_queue(q.lower(), session)
77         if queue:
78             Logger.log(['cleaning queue %s using datetime %s' % (q, starttime)])
79             queue.clean_and_update(starttime, dryrun=Options["No-Action"])
80         else:
81             Logger.log(['cannot find queue %s' % q])
82
83     Logger.close()
84
85 #######################################################################################
86
87 if __name__ == '__main__':
88     main()