19
25
This is the implementation of `TranslationTemplatesBuildJob`. The
20
26
latter runs on the master server; TranslationTemplatesBuildManager
21
runs on the build slave.
24
initial_build_state = TranslationTemplatesBuildState.INSTALL
30
initial_build_state = TranslationTemplatesBuildState.GENERATE
26
def __init__(self, slave, buildid):
27
super(TranslationTemplatesBuildManager, self).__init__(slave, buildid)
28
self._generatepath = os.path.join(
29
self._slavebin, "generate-translation-templates")
30
self._resultname = slave._config.get(
32
def __init__(self, builder, buildid):
33
super(TranslationTemplatesBuildManager, self).__init__(
35
self._resultname = builder._config.get(
31
36
"translationtemplatesmanager", "resultarchive")
33
38
def initiate(self, files, chroot, extra_args):
34
39
"""See `BuildManager`."""
35
40
self._branch_url = extra_args['branch_url']
36
self._chroot_path = os.path.join(
37
self.home, 'build-' + self._buildid, 'chroot-autobuild')
39
42
super(TranslationTemplatesBuildManager, self).initiate(
40
43
files, chroot, extra_args)
43
"""Install packages required."""
48
command = ['apt-get', 'install', '-y'] + required_packages
49
chroot = ['sudo', 'chroot', self._chroot_path]
50
self.runSubProcess('/usr/bin/sudo', chroot + command)
52
# To satisfy DebianPackageManagers needs without having a misleading
54
doRunBuild = doInstall
56
45
def doGenerate(self):
57
46
"""Generate templates."""
60
self._buildid, self._branch_url, self._resultname]
61
self.runSubProcess(self._generatepath, command)
47
self.runTargetSubProcess(
48
"generate-translation-templates",
49
self._branch_url, self._resultname)
51
# Satisfy DebianPackageManager's needs without having a misleading
53
doRunBuild = doGenerate
63
55
def gatherResults(self):
64
56
"""Gather the results of the build and add them to the file cache."""
65
# The file is inside the chroot, in the home directory of the buildd
57
# The file is inside the target, in the home directory of the buildd
66
58
# user. Should be safe to assume the home dirs are named identically.
67
assert self.home.startswith('/'), "home directory must be absolute."
70
self._chroot_path, self.home[1:], self._resultname)
71
if os.access(path, os.F_OK):
72
self._slave.addWaitingFile(path)
74
def iterate_INSTALL(self, success):
75
"""Installation was done."""
77
self._state = TranslationTemplatesBuildState.GENERATE
80
if not self.alreadyfailed:
81
self._slave.chrootFail()
82
self.alreadyfailed = True
83
self._state = TranslationTemplatesBuildState.UMOUNT
86
def iterate_GENERATE(self, success):
59
path = os.path.join(self.home, self._resultname)
60
if self.backend.path_exists(path):
61
self.addWaitingFileFromBackend(path)
63
def iterate_GENERATE(self, retcode):
87
64
"""Template generation finished."""
89
66
# It worked! Now let's bring in the harvest.
91
self.doReapProcesses(self._state)
67
return self.deferGatherResults()
93
69
if not self.alreadyfailed:
94
self._slave.buildFail()
70
if retcode == RETCODE_FAILURE_INSTALL:
71
self._builder.chrootFail()
72
elif retcode == RETCODE_FAILURE_BUILD:
73
self._builder.buildFail()
75
self._builder.builderFail()
95
76
self.alreadyfailed = True
96
self.doReapProcesses(self._state)
77
self.doReapProcesses(self._state)
98
79
def iterateReap_GENERATE(self, success):
99
80
"""Finished reaping after template generation."""