1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
8
from canonical.buildd.debian import DebianBuildManager, DebianBuildState
11
class TranslationTemplatesBuildState(DebianBuildState):
16
class TranslationTemplatesBuildManager(DebianBuildManager):
17
"""Generate translation templates from branch.
19
This is the implementation of `TranslationTemplatesBuildJob`. The
20
latter runs on the master server; TranslationTemplatesBuildManager
21
runs on the build slave.
24
initial_build_state = TranslationTemplatesBuildState.INSTALL
26
def __init__(self, slave, buildid):
27
super(TranslationTemplatesBuildManager, self).__init__(slave, buildid)
28
self._generatepath = slave._config.get(
29
"translationtemplatesmanager", "generatepath")
30
self._resultname = slave._config.get(
31
"translationtemplatesmanager", "resultarchive")
33
def initiate(self, files, chroot, extra_args):
34
"""See `BuildManager`."""
35
self._branch_url = extra_args['branch_url']
36
self._chroot_path = os.path.join(
37
self.home, 'build-' + self._buildid, 'chroot-autobuild')
39
super(TranslationTemplatesBuildManager, self).initiate(
40
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
57
"""Generate templates."""
60
self._buildid, self._branch_url, self._resultname]
61
self.runSubProcess(self._generatepath, command)
63
def gatherResults(self):
64
"""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
66
# 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):
87
"""Template generation finished."""
89
# It worked! Now let's bring in the harvest.
91
self._state = TranslationTemplatesBuildState.REAP
92
self.doReapProcesses()
94
if not self.alreadyfailed:
95
self._slave.buildFail()
96
self.alreadyfailed = True
97
self._state = TranslationTemplatesBuildState.REAP
98
self.doReapProcesses()