10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
8687.15.22
by Karl Fogel
Add the copyright header block to the remaining .py files. |
2 |
#
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3147.5.35
by Celso Providelo
Applying review comments [r=bjornt] |
5 |
|
6 |
||
7 |
"""Tool for 'mass-retrying' build records.
|
|
8 |
||
4285.2.4
by Mark Shuttleworth
Test fixes with renamed distrorelease |
9 |
It supports build collections based distroseries and/or distroarchseries.
|
3147.5.29
by Celso Providelo
add experimental script for mass-retry builds |
10 |
"""
|
11 |
||
3147.5.35
by Celso Providelo
Applying review comments [r=bjornt] |
12 |
__metaclass__ = type |
13 |
||
3147.5.29
by Celso Providelo
add experimental script for mass-retry builds |
14 |
import _pythonpath |
3147.5.35
by Celso Providelo
Applying review comments [r=bjornt] |
15 |
|
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
16 |
import transaction |
3147.5.29
by Celso Providelo
add experimental script for mass-retry builds |
17 |
from zope.component import getUtility |
18 |
||
11270.1.3
by Tim Penhey
Changed NotFoundError imports - gee there were a lot of them. |
19 |
from lp.app.errors import NotFoundError |
11458.1.1
by Jelmer Vernooij
Move enums of buildmaster. |
20 |
from lp.buildmaster.enums import BuildStatus |
7675.575.1
by William Grant
Move lp.soyuz.interfaces.build.BuildStatus to lp.buildmaster.interfaces.buildbase. Sort various imports along the way. |
21 |
from lp.registry.interfaces.distribution import IDistributionSet |
22 |
from lp.registry.interfaces.pocket import PackagePublishingPocket |
|
14612.2.7
by William Grant
scripts |
23 |
from lp.services.scripts.base import ( |
24 |
LaunchpadScript, |
|
25 |
LaunchpadScriptFailure, |
|
26 |
)
|
|
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
27 |
|
28 |
||
29 |
class BuilddMassRetryScript(LaunchpadScript): |
|
30 |
||
31 |
dbuser = "fiera" |
|
32 |
||
33 |
def add_my_options(self): |
|
34 |
self.parser.add_option( |
|
35 |
"-d", "--distribution", dest="distribution", |
|
36 |
metavar="DISTRIBUTION", default="ubuntu", |
|
37 |
help="distribution name") |
|
38 |
||
39 |
self.parser.add_option( |
|
40 |
"-s", "--suite", dest="suite", metavar="SUITE", help="suite name") |
|
41 |
||
42 |
self.parser.add_option( |
|
43 |
"-a", "--architecture", dest="architecture", metavar="ARCH", |
|
44 |
help="architecture tag") |
|
45 |
||
46 |
self.parser.add_option( |
|
47 |
"-N", "--dry-run", action="store_true", dest="dryrun", |
|
48 |
metavar="DRY_RUN", default=False, |
|
49 |
help="Whether to treat this as a dry-run or not.") |
|
50 |
||
51 |
self.parser.add_option( |
|
52 |
"-F", "--failed", action="store_true", dest="failed", |
|
53 |
default=False, help="Reset builds in FAILED state.") |
|
54 |
||
55 |
self.parser.add_option( |
|
56 |
"-D", "--dep-wait", action="store_true", dest="depwait", |
|
57 |
default=False, help="Reset builds in DEPWAIT state.") |
|
58 |
||
59 |
self.parser.add_option( |
|
60 |
"-C", "--chroot-wait", action="store_true", dest="chrootwait", |
|
61 |
default=False, help="Reset builds in CHROOTWAIT state.") |
|
62 |
||
63 |
def main(self): |
|
64 |
try: |
|
13970.7.8
by William Grant
And make it a bit more native. |
65 |
distribution = getUtility(IDistributionSet)[ |
66 |
self.options.distribution] |
|
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
67 |
except NotFoundError, info: |
13970.7.8
by William Grant
And make it a bit more native. |
68 |
raise LaunchpadScriptFailure("Distribution not found: %s" % info) |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
69 |
|
70 |
try: |
|
13970.7.8
by William Grant
And make it a bit more native. |
71 |
if self.options.suite is not None: |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
72 |
series, pocket = distribution.getDistroSeriesAndPocket( |
13970.7.8
by William Grant
And make it a bit more native. |
73 |
self.options.suite) |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
74 |
else: |
75 |
series = distribution.currentseries |
|
76 |
pocket = PackagePublishingPocket.RELEASE |
|
77 |
except NotFoundError, info: |
|
13970.7.8
by William Grant
And make it a bit more native. |
78 |
raise LaunchpadScriptFailure("Suite not found: %s" % info) |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
79 |
|
80 |
# store distroseries as the current IHasBuildRecord provider
|
|
81 |
build_provider = series |
|
82 |
||
13970.7.8
by William Grant
And make it a bit more native. |
83 |
if self.options.architecture: |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
84 |
try: |
13970.7.8
by William Grant
And make it a bit more native. |
85 |
dar = series[self.options.architecture] |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
86 |
except NotFoundError, info: |
13970.7.8
by William Grant
And make it a bit more native. |
87 |
raise LaunchpadScriptFailure(info) |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
88 |
|
89 |
# store distroarchseries as the current IHasBuildRecord provider
|
|
90 |
build_provider = dar |
|
91 |
||
13970.7.8
by William Grant
And make it a bit more native. |
92 |
self.logger.info( |
93 |
"Initializing Build Mass-Retry for '%s/%s'" |
|
94 |
% (build_provider.title, pocket.name)) |
|
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
95 |
|
96 |
requested_states_map = { |
|
13970.7.8
by William Grant
And make it a bit more native. |
97 |
BuildStatus.FAILEDTOBUILD: self.options.failed, |
98 |
BuildStatus.MANUALDEPWAIT: self.options.depwait, |
|
99 |
BuildStatus.CHROOTWAIT: self.options.chrootwait, |
|
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
100 |
}
|
101 |
||
102 |
# XXX cprov 2006-08-31: one query per requested state
|
|
103 |
# could organise it in a single one nicely if I have
|
|
104 |
# an empty SQLResult instance, than only iteration + union()
|
|
105 |
# would work.
|
|
106 |
for target_state, requested in requested_states_map.items(): |
|
107 |
if not requested: |
|
108 |
continue
|
|
109 |
||
13970.7.8
by William Grant
And make it a bit more native. |
110 |
self.logger.info("Processing builds in '%s'" % target_state.title) |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
111 |
target_builds = build_provider.getBuildRecords( |
112 |
build_state=target_state, pocket=pocket) |
|
113 |
||
114 |
for build in target_builds: |
|
115 |
# Skip builds for superseded sources; they won't ever
|
|
116 |
# actually build.
|
|
117 |
if not build.current_source_publication: |
|
13970.7.8
by William Grant
And make it a bit more native. |
118 |
self.logger.debug( |
119 |
'Skipping superseded %s (%s)' |
|
120 |
% (build.title, build.id)) |
|
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
121 |
continue
|
122 |
||
123 |
if not build.can_be_retried: |
|
13970.7.8
by William Grant
And make it a bit more native. |
124 |
self.logger.warn( |
125 |
'Can not retry %s (%s)' % (build.title, build.id)) |
|
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
126 |
continue
|
127 |
||
13970.7.8
by William Grant
And make it a bit more native. |
128 |
self.logger.info('Retrying %s (%s)' % (build.title, build.id)) |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
129 |
build.retry() |
130 |
||
13970.7.8
by William Grant
And make it a bit more native. |
131 |
self.logger.info("Success.") |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
132 |
|
13970.7.8
by William Grant
And make it a bit more native. |
133 |
if self.options.dryrun: |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
134 |
transaction.abort() |
13970.7.8
by William Grant
And make it a bit more native. |
135 |
self.logger.info('Dry-run.') |
3147.5.29
by Celso Providelo
add experimental script for mass-retry builds |
136 |
else: |
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
137 |
transaction.commit() |
13970.7.8
by William Grant
And make it a bit more native. |
138 |
self.logger.info("Committed") |
3147.5.29
by Celso Providelo
add experimental script for mass-retry builds |
139 |
|
140 |
||
141 |
if __name__ == '__main__': |
|
13970.7.7
by William Grant
Quick port of buildd-mass-retry to LaunchpadScript. |
142 |
BuilddMassRetryScript('buildd-mass-retry', 'fiera').lock_and_run() |