]> git.decadent.org.uk Git - dak.git/blob - dak/manage_build_queues.py
and another one
[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   -v, --verbose              explain what is being done
45   -h, --help                 show this help and exit"""
46
47     sys.exit(exit_code)
48
49 ################################################################################
50
51 def main ():
52     global Options, Logger
53
54     cnf = Config()
55
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)] = ""
59
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")]
64
65     queue_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
66     Options = cnf.SubTree("Manage-Build-Queues::Options")
67
68     if Options["Help"]:
69         usage()
70
71     Logger = daklog.Logger(cnf, 'manage-build-queues', Options['No-Action'])
72
73     starttime = datetime.now()
74
75     session = DBConn().session()
76
77     if Options["All"]:
78         if len(queue_names) != 0:
79             print "E: Cannot use both -a and a queue_name"
80             sys.exit(1)
81         queues = session.query(BuildQueue).all()
82
83     else:
84         queues = []
85         for q in queue_names:
86             queue = get_build_queue(q.lower(), session)
87             if queue:
88                 queues.append(queue)
89             else:
90                 Logger.log(['cannot find queue %s' % q])
91
92     # For each given queue, look up object and call manage_queue
93     for q in queues:
94         Logger.log(['cleaning queue %s using datetime %s' % (q.queue_name, starttime)])
95         q.clean_and_update(starttime, dryrun=Options["No-Action"])
96
97     Logger.close()
98
99 #######################################################################################
100
101 if __name__ == '__main__':
102     main()