10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
__metaclass__ = type |
|
5 |
||
10154.8.7
by Jeroen Vermeulen
Still failing for lack of a proper chroot tarball, but close. |
6 |
import os |
7 |
||
10427.20.1
by Henning Eggers
Use DebianBuildManager. |
8 |
from canonical.buildd.debian import DebianBuildManager, DebianBuildState |
9 |
||
11077.1.1
by Jeroen Vermeulen
Make pottery strip quotes from config/makefile variables. |
10 |
|
10427.20.3
by Henning Eggers
Fixed incosistent class name. |
11 |
class TranslationTemplatesBuildState(DebianBuildState): |
10154.8.9
by Jeroen Vermeulen
Unit-testing translation-templates build manager. |
12 |
INSTALL = "INSTALL" |
10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
13 |
GENERATE = "GENERATE" |
14 |
||
15 |
||
10427.20.2
by Henning Eggers
Small fix. |
16 |
class TranslationTemplatesBuildManager(DebianBuildManager): |
10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
17 |
"""Generate translation templates from branch.
|
18 |
||
19 |
This is the implementation of `TranslationTemplatesBuildJob`. The
|
|
20 |
latter runs on the master server; TranslationTemplatesBuildManager
|
|
21 |
runs on the build slave.
|
|
22 |
"""
|
|
10427.20.1
by Henning Eggers
Use DebianBuildManager. |
23 |
|
10427.20.3
by Henning Eggers
Fixed incosistent class name. |
24 |
initial_build_state = TranslationTemplatesBuildState.INSTALL |
10427.20.1
by Henning Eggers
Use DebianBuildManager. |
25 |
|
26 |
def __init__(self, slave, buildid): |
|
27 |
super(TranslationTemplatesBuildManager, self).__init__(slave, buildid) |
|
28 |
self._generatepath = slave._config.get( |
|
29 |
"translationtemplatesmanager", "generatepath") |
|
10427.23.8
by Henning Eggers
Central place to define result name. |
30 |
self._resultname = slave._config.get( |
31 |
"translationtemplatesmanager", "resultarchive") |
|
10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
32 |
|
33 |
def initiate(self, files, chroot, extra_args): |
|
34 |
"""See `BuildManager`."""
|
|
10427.20.9
by Henning Eggers
Got a running slave now. |
35 |
self._branch_url = extra_args['branch_url'] |
36 |
self._chroot_path = os.path.join( |
|
10427.20.1
by Henning Eggers
Use DebianBuildManager. |
37 |
self.home, 'build-' + self._buildid, 'chroot-autobuild') |
10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
38 |
|
39 |
super(TranslationTemplatesBuildManager, self).initiate( |
|
10154.8.7
by Jeroen Vermeulen
Still failing for lack of a proper chroot tarball, but close. |
40 |
files, chroot, extra_args) |
10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
41 |
|
42 |
def doInstall(self): |
|
43 |
"""Install packages required."""
|
|
44 |
required_packages = [ |
|
45 |
'bzr', |
|
10346.2.5
by Henning Eggers
Got it running in pbuilder. |
46 |
'intltool', |
10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
47 |
]
|
10427.20.6
by Henning Eggers
Adapt state machine to call new script. |
48 |
command = ['apt-get', 'install', '-y'] + required_packages |
10427.20.9
by Henning Eggers
Got a running slave now. |
49 |
chroot = ['sudo', 'chroot', self._chroot_path] |
10427.20.6
by Henning Eggers
Adapt state machine to call new script. |
50 |
self.runSubProcess('/usr/bin/sudo', chroot + command) |
10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
51 |
|
10427.20.2
by Henning Eggers
Small fix. |
52 |
# To satisfy DebianPackageManagers needs without having a misleading
|
53 |
# method name here.
|
|
10427.20.1
by Henning Eggers
Use DebianBuildManager. |
54 |
doRunBuild = doInstall |
10154.8.2
by Jeroen Vermeulen
Skeleton script & test. |
55 |
|
56 |
def doGenerate(self): |
|
57 |
"""Generate templates."""
|
|
10427.23.8
by Henning Eggers
Central place to define result name. |
58 |
command = [ |
59 |
self._generatepath, |
|
10427.23.9
by Henning Eggers
Build manager test passing again. |
60 |
self._buildid, self._branch_url, self._resultname] |
10427.20.6
by Henning Eggers
Adapt state machine to call new script. |
61 |
self.runSubProcess(self._generatepath, command) |
10427.20.1
by Henning Eggers
Use DebianBuildManager. |
62 |
|
10427.23.8
by Henning Eggers
Central place to define result name. |
63 |
def gatherResults(self): |
64 |
"""Gather the results of the build and add them to the file cache."""
|
|
10427.23.10
by Henning Eggers
Result gathering implemented. |
65 |
# The file is inside the chroot, in the home directory of the buildd
|
10427.23.18
by Henning Eggers
Reviewer comments and suggestions. |
66 |
# user. Should be safe to assume the home dirs are named identically.
|
10604.5.9
by William Grant
Add full stop to end of assertion message. |
67 |
assert self.home.startswith('/'), "home directory must be absolute." |
10604.5.5
by William Grant
Assert that the slave home directory is absolute before removing a separator from the start. |
68 |
|
11077.1.2
by Jeroen Vermeulen
Inherited lint. |
69 |
path = os.path.join( |
70 |
self._chroot_path, self.home[1:], self._resultname) |
|
10427.23.10
by Henning Eggers
Result gathering implemented. |
71 |
if os.access(path, os.F_OK): |
10604.5.1
by William Grant
Unbreak the translations slave's tarball collection. |
72 |
self._slave.addWaitingFile(path) |
10427.23.8
by Henning Eggers
Central place to define result name. |
73 |
|
10427.20.1
by Henning Eggers
Use DebianBuildManager. |
74 |
def iterate_INSTALL(self, success): |
75 |
"""Installation was done."""
|
|
76 |
if success == 0: |
|
77 |
self._state = TranslationTemplatesBuildState.GENERATE |
|
78 |
self.doGenerate() |
|
79 |
else: |
|
80 |
if not self.alreadyfailed: |
|
81 |
self._slave.chrootFail() |
|
82 |
self.alreadyfailed = True |
|
83 |
self._state = TranslationTemplatesBuildState.UMOUNT |
|
84 |
self.doUnmounting() |
|
85 |
||
86 |
def iterate_GENERATE(self, success): |
|
10427.23.18
by Henning Eggers
Reviewer comments and suggestions. |
87 |
"""Template generation finished."""
|
10427.20.1
by Henning Eggers
Use DebianBuildManager. |
88 |
if success == 0: |
10427.23.10
by Henning Eggers
Result gathering implemented. |
89 |
# It worked! Now let's bring in the harvest.
|
90 |
self.gatherResults() |
|
10427.23.2
by Henning Eggers
Added iterate method for new UPLOAD state. |
91 |
self._state = TranslationTemplatesBuildState.REAP |
92 |
self.doReapProcesses() |
|
93 |
else: |
|
94 |
if not self.alreadyfailed: |
|
95 |
self._slave.buildFail() |
|
96 |
self.alreadyfailed = True |
|
97 |
self._state = TranslationTemplatesBuildState.REAP |
|
98 |
self.doReapProcesses() |
|
99 |