]> git.decadent.org.uk Git - dak.git/blob - dak/manage_build_queues.py
some docstrings
[dak.git] / dak / manage_build_queues.py
1 #!/usr/bin/env python
2
3 """ Manage build queues
4
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @copyright: 2000, 2001, 2002, 2006  James Troup <james@nocrew.org>
7 @copyright: 2009  Mark Hymers <mhy@debian.org>
8
9 """
10
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
25 ################################################################################
26
27 import os
28 import os.path
29 import stat
30 import sys
31 from datetime import datetime
32 import apt_pkg
33
34 from daklib import daklog
35 from daklib.dbconn import *
36 from daklib.config import Config
37
38 ################################################################################
39
40 Options = None
41 Logger = None
42
43 ################################################################################
44
45 def usage (exit_code=0):
46     print """Usage: dak manage-build-queues [OPTIONS] buildqueue1 buildqueue2
47 Manage the contents of one or more build queues
48
49   -a, --all                  run on all known build queues
50   -n, --no-action            don't do anything
51   -h, --help                 show this help and exit"""
52
53     sys.exit(exit_code)
54
55 ################################################################################
56
57 def main ():
58     global Options, Logger
59
60     cnf = Config()
61
62     for i in ["Help", "No-Action", "All"]:
63         if not cnf.has_key("Manage-Build-Queues::Options::%s" % (i)):
64             cnf["Manage-Build-Queues::Options::%s" % (i)] = ""
65
66     Arguments = [('h',"help","Manage-Build-Queues::Options::Help"),
67                  ('n',"no-action","Manage-Build-Queues::Options::No-Action"),
68                  ('a',"all","Manage-Build-Queues::Options::All")]
69
70     queue_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
71     Options = cnf.SubTree("Manage-Build-Queues::Options")
72
73     if Options["Help"]:
74         usage()
75
76     Logger = daklog.Logger(cnf, 'manage-build-queues', Options['No-Action'])
77
78     starttime = datetime.now()
79
80     session = DBConn().session()
81
82     if Options["All"]:
83         if len(queue_names) != 0:
84             print "E: Cannot use both -a and a queue_name"
85             sys.exit(1)
86         queues = session.query(BuildQueue).all()
87
88     else:
89         queues = []
90         for q in queue_names:
91             queue = get_build_queue(q.lower(), session)
92             if queue:
93                 queues.append(queue)
94             else:
95                 Logger.log(['cannot find queue %s' % q])
96
97     # For each given queue, look up object and call manage_queue
98     for q in queues:
99         Logger.log(['cleaning queue %s using datetime %s' % (q.queue_name, starttime)])
100         q.clean_and_update(starttime, Logger, dryrun=Options["No-Action"])
101
102     Logger.close()
103
104 #######################################################################################
105
106 if __name__ == '__main__':
107     main()