]> git.decadent.org.uk Git - dak.git/blob - dak/manage_build_queues.py
remove pointless verbose option
[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   -a, --all                  run on all known build queues
43   -n, --no-action            don't do anything
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", "All"]:
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                  ('a',"all","Manage-Build-Queues::Options::All")]
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     session = DBConn().session()
74
75     if Options["All"]:
76         if len(queue_names) != 0:
77             print "E: Cannot use both -a and a queue_name"
78             sys.exit(1)
79         queues = session.query(BuildQueue).all()
80
81     else:
82         queues = []
83         for q in queue_names:
84             queue = get_build_queue(q.lower(), session)
85             if queue:
86                 queues.append(queue)
87             else:
88                 Logger.log(['cannot find queue %s' % q])
89
90     # For each given queue, look up object and call manage_queue
91     for q in queues:
92         Logger.log(['cleaning queue %s using datetime %s' % (q.queue_name, starttime)])
93         q.clean_and_update(starttime, Logger, dryrun=Options["No-Action"])
94
95     Logger.close()
96
97 #######################################################################################
98
99 if __name__ == '__main__':
100     main()