~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/buildd/translationtemplates.py

  • Committer: mbp at canonical
  • Date: 2011-11-20 23:37:23 UTC
  • mto: This revision was merged to the branch mainline in revision 14344.
  • Revision ID: mbp@canonical.com-20111120233723-370p96db2crru5tm
Delete canonical.buildd again

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
6
 
import os
7
 
 
8
 
from canonical.buildd.debian import DebianBuildManager, DebianBuildState
9
 
 
10
 
 
11
 
class TranslationTemplatesBuildState(DebianBuildState):
12
 
    INSTALL = "INSTALL"
13
 
    GENERATE = "GENERATE"
14
 
 
15
 
 
16
 
class TranslationTemplatesBuildManager(DebianBuildManager):
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
 
    """
23
 
 
24
 
    initial_build_state = TranslationTemplatesBuildState.INSTALL
25
 
 
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")
32
 
 
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')
38
 
 
39
 
        super(TranslationTemplatesBuildManager, self).initiate(
40
 
            files, chroot, extra_args)
41
 
 
42
 
    def doInstall(self):
43
 
        """Install packages required."""
44
 
        required_packages = [
45
 
            'bzr',
46
 
            'intltool',
47
 
            ]
48
 
        command = ['apt-get', 'install', '-y'] + required_packages
49
 
        chroot = ['sudo', 'chroot', self._chroot_path]
50
 
        self.runSubProcess('/usr/bin/sudo', chroot + command)
51
 
 
52
 
    # To satisfy DebianPackageManagers needs without having a misleading
53
 
    # method name here.
54
 
    doRunBuild = doInstall
55
 
 
56
 
    def doGenerate(self):
57
 
        """Generate templates."""
58
 
        command = [
59
 
            self._generatepath,
60
 
            self._buildid, self._branch_url, self._resultname]
61
 
        self.runSubProcess(self._generatepath, command)
62
 
 
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."
68
 
 
69
 
        path = os.path.join(
70
 
            self._chroot_path, self.home[1:], self._resultname)
71
 
        if os.access(path, os.F_OK):
72
 
            self._slave.addWaitingFile(path)
73
 
 
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):
87
 
        """Template generation finished."""
88
 
        if success == 0:
89
 
            # It worked! Now let's bring in the harvest.
90
 
            self.gatherResults()
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