1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
#! /usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Canonical Ltd.
# Author: Stéphane Graber <stgraber@ubuntu.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Fetches the list of pending rebuilds."""
from optparse import OptionParser
import os
import subprocess
import sys
sys.path.insert(0, os.path.join(sys.path[0], os.pardir, "lib"))
from cdimage.config import Config
from cdimage.tree import Publisher, Tree
def main():
parser = OptionParser(usage="Usage: %prog [options] SERIES INSTANCE")
parser.add_option('-b', '--build', help="Build any pending product",
action="store_true", default=False)
parser.add_option('-c', '--cancel', help="Cancel any pending/stuck build",
action="store_true", default=False)
parser.add_option('-n', '--dry-run', help="Print the commands that "
"would normally be run",
action="store_true", default=False)
parser.add_option('-q', '--quiet', help="Hide all info messages",
action="store_true", default=False)
options, args = parser.parse_args()
if len(args) < 2:
parser.error("need series and instance")
config = Config()
tree = Tree.get_daily(config)
publisher = Publisher.get_daily(tree, "daily")
# Only import it here to avoid --help failing from the bzr branch
from isotracker import ISOTracker
tracker = ISOTracker(target="%s-%s" % (args[1], args[0]))
if not options.build and not options.cancel:
# List all the pending entries
for rebuild in tracker.qatracker.get_rebuilds("Requested"):
if rebuild.series_title.lower() != args[0]:
continue
print(" - %s for %s (requested by %s) => %s " %
(rebuild.product_title, rebuild.series_title,
rebuild.requestedby_name,
publisher.cdimage_project(rebuild.product_title, args[1])))
return
if options.cancel:
# Iterate through all non-final states
for rebuild in tracker.qatracker.get_rebuilds(
["Requested", "Queued", "Building", "Built"]):
if rebuild.series_title.lower() != args[0]:
continue
print(" - %s for %s (requested by %s) => %s " %
(rebuild.product_title, rebuild.series_title,
rebuild.requestedby_name,
publisher.cdimage_project(rebuild.product_title, args[1])))
if not options.dry_run:
rebuild.status = 5
rebuild.save()
return
# Process any pending rebuild
rebuilds = {}
queue = tracker.qatracker.get_rebuilds("Requested")
processes = []
# Group everything by project+build_type
for rebuild in queue:
if rebuild.series_title.lower() != args[0]:
continue
project = publisher.cdimage_project(rebuild.product_title, args[1])
if not project:
print("Invalid entry '%s' for '%s'" % (rebuild.product_title,
args[0]))
continue
project_id = "%s/%s" % (project[0], project[1])
if project_id not in rebuilds:
rebuilds[project_id] = []
rebuilds[project_id].append([rebuild] + list(project))
for project_id, entries in rebuilds.items():
if not options.quiet:
print("Processing rebuilds for: %s" % project_id)
project, build_type = project_id.rsplit("/", 1)
sub_project = None
if "/" in project:
project, sub_project = project.split("/", 1)
arches = " ".join([entry[4] for entry in entries])
for entry in entries:
# Marking the entry as "queued"
if not options.dry_run:
entry[0].status = 1
entry[0].save()
if not options.quiet:
print(" - %s for %s (requested by %s) => %s " %
(entry[0].product_title, entry[0].series_title,
entry[0].requestedby_name, entry[1:]))
env = dict(os.environ)
if sub_project:
env['SUBPROJECT'] = sub_project
env['ARCHES'] = arches
env['DIST'] = entries[0][0].series_title.lower()
cmd = ["for-project", entry[1], "cron.%s" % entry[2]]
if (build_type != "daily" or
entry[1] in ("ubuntu-core", "ubuntu-server")):
cmd += ["--live"]
if options.dry_run:
if not options.quiet:
if sub_project:
print("Dry-run: SUBPROJECT=%s ARCHES=%s DIST=%s %s" %
(env['SUBPROJECT'], env['ARCHES'], env['DIST'],
" ".join(cmd)))
else:
print("Dry-run: ARCHES=%s DIST=%s %s" %
(env['ARCHES'], env['DIST'], " ".join(cmd)))
else:
processes.append(subprocess.Popen(cmd, env=env))
if not options.quiet:
print("")
if processes:
if not options.quiet:
print("Waiting for %s builds to complete." % len(processes))
for process in processes:
process.wait()
if __name__ == "__main__":
main()
|