16
from optparse import OptionParser
19
17
from zope.component import getUtility
21
# Still needed fake import to stop circular imports.
22
import canonical.launchpad.interfaces
24
from canonical.database.sqlbase import ISOLATION_LEVEL_READ_COMMITTED
25
19
from lp.app.errors import NotFoundError
26
from canonical.launchpad.scripts import (
27
execute_zcml_for_scripts, logger_options, logger)
28
from canonical.lp import initZopeless
29
20
from lp.buildmaster.enums import BuildStatus
30
21
from lp.registry.interfaces.distribution import IDistributionSet
31
22
from lp.registry.interfaces.pocket import PackagePublishingPocket
35
parser = OptionParser()
36
logger_options(parser)
38
parser.add_option("-d", "--distribution",
39
dest="distribution", metavar="DISTRIBUTION",
40
default="ubuntu", help="distribution name")
42
parser.add_option("-s", "--suite",
43
dest="suite", metavar="SUITE", default=None,
46
parser.add_option("-a", "--architecture",
47
dest="architecture", metavar="ARCH", default=None,
48
help="architecture tag")
50
parser.add_option("-N", "--dry-run", action="store_true",
51
dest="dryrun", metavar="DRY_RUN", default=False,
52
help="Whether to treat this as a dry-run or not.")
54
parser.add_option("-F", "--failed", action="store_true",
55
dest="failed", default=False,
56
help="Reset builds in FAILED state.")
58
parser.add_option("-D", "--dep-wait", action="store_true",
59
dest="depwait", default=False,
60
help="Reset builds in DEPWAIT state.")
62
parser.add_option("-C", "--chroot-wait", action="store_true",
63
dest="chrootwait", default=False,
64
help="Reset builds in CHROOTWAIT state.")
66
(options, args) = parser.parse_args()
68
log = logger(options, "build-mass-retry")
70
log.debug("Intitialising connection.")
71
execute_zcml_for_scripts()
72
ztm = initZopeless(dbuser="fiera",
73
isolation=ISOLATION_LEVEL_READ_COMMITTED)
76
distribution = getUtility(IDistributionSet)[options.distribution]
77
except NotFoundError, info:
78
log.error("Distribution not found: %s" % info)
82
if options.suite is not None:
83
series, pocket = distribution.getDistroSeriesAndPocket(
23
from lp.services.scripts.base import LaunchpadScript, LaunchpadScriptFailure
26
class BuilddMassRetryScript(LaunchpadScript):
30
def add_my_options(self):
31
self.parser.add_option(
32
"-d", "--distribution", dest="distribution",
33
metavar="DISTRIBUTION", default="ubuntu",
34
help="distribution name")
36
self.parser.add_option(
37
"-s", "--suite", dest="suite", metavar="SUITE", help="suite name")
39
self.parser.add_option(
40
"-a", "--architecture", dest="architecture", metavar="ARCH",
41
help="architecture tag")
43
self.parser.add_option(
44
"-N", "--dry-run", action="store_true", dest="dryrun",
45
metavar="DRY_RUN", default=False,
46
help="Whether to treat this as a dry-run or not.")
48
self.parser.add_option(
49
"-F", "--failed", action="store_true", dest="failed",
50
default=False, help="Reset builds in FAILED state.")
52
self.parser.add_option(
53
"-D", "--dep-wait", action="store_true", dest="depwait",
54
default=False, help="Reset builds in DEPWAIT state.")
56
self.parser.add_option(
57
"-C", "--chroot-wait", action="store_true", dest="chrootwait",
58
default=False, help="Reset builds in CHROOTWAIT state.")
62
distribution = getUtility(IDistributionSet)[
63
self.options.distribution]
64
except NotFoundError, info:
65
raise LaunchpadScriptFailure("Distribution not found: %s" % info)
68
if self.options.suite is not None:
69
series, pocket = distribution.getDistroSeriesAndPocket(
72
series = distribution.currentseries
73
pocket = PackagePublishingPocket.RELEASE
74
except NotFoundError, info:
75
raise LaunchpadScriptFailure("Suite not found: %s" % info)
77
# store distroseries as the current IHasBuildRecord provider
78
build_provider = series
80
if self.options.architecture:
82
dar = series[self.options.architecture]
83
except NotFoundError, info:
84
raise LaunchpadScriptFailure(info)
86
# store distroarchseries as the current IHasBuildRecord provider
90
"Initializing Build Mass-Retry for '%s/%s'"
91
% (build_provider.title, pocket.name))
93
requested_states_map = {
94
BuildStatus.FAILEDTOBUILD: self.options.failed,
95
BuildStatus.MANUALDEPWAIT: self.options.depwait,
96
BuildStatus.CHROOTWAIT: self.options.chrootwait,
99
# XXX cprov 2006-08-31: one query per requested state
100
# could organise it in a single one nicely if I have
101
# an empty SQLResult instance, than only iteration + union()
103
for target_state, requested in requested_states_map.items():
107
self.logger.info("Processing builds in '%s'" % target_state.title)
108
target_builds = build_provider.getBuildRecords(
109
build_state=target_state, pocket=pocket)
111
for build in target_builds:
112
# Skip builds for superseded sources; they won't ever
114
if not build.current_source_publication:
116
'Skipping superseded %s (%s)'
117
% (build.title, build.id))
120
if not build.can_be_retried:
122
'Can not retry %s (%s)' % (build.title, build.id))
125
self.logger.info('Retrying %s (%s)' % (build.title, build.id))
128
self.logger.info("Success.")
130
if self.options.dryrun:
132
self.logger.info('Dry-run.')
86
series = distribution.currentseries
87
pocket = PackagePublishingPocket.RELEASE
88
except NotFoundError, info:
89
log.error("Suite not found: %s" % info)
92
# store distroseries as the current IHasBuildRecord provider
93
build_provider = series
95
if options.architecture:
97
dar = series[options.architecture]
98
except NotFoundError, info:
102
# store distroarchseries as the current IHasBuildRecord provider
105
log.info("Initializing Build Mass-Retry for '%s/%s'"
106
% (build_provider.title, pocket.name))
108
requested_states_map = {
109
BuildStatus.FAILEDTOBUILD : options.failed,
110
BuildStatus.MANUALDEPWAIT : options.depwait,
111
BuildStatus.CHROOTWAIT : options.chrootwait,
114
# XXX cprov 2006-08-31: one query per requested state
115
# could organise it in a single one nicely if I have
116
# an empty SQLResult instance, than only iteration + union()
118
for target_state, requested in requested_states_map.items():
122
log.info("Processing builds in '%s'" % target_state.title)
123
target_builds = build_provider.getBuildRecords(
124
build_state=target_state, pocket=pocket)
126
for build in target_builds:
127
# Skip builds for superseded sources; they won't ever
129
if not build.current_source_publication:
131
'Skipping superseded %s (%s)' % (build.title, build.id))
134
if not build.can_be_retried:
135
log.warn('Can not retry %s (%s)' % (build.title, build.id))
138
log.info('Retrying %s (%s)' % (build.title, build.id))
148
log.info("Committed")
135
self.logger.info("Committed")
153
138
if __name__ == '__main__':
139
BuilddMassRetryScript('buildd-mass-retry', 'fiera').lock_and_run()