aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/autobuilder/buildsteps/RemoveTmpFiles.py
blob: 3517d22a00a6a0c8611c8cfc2653a8a33243f72b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'''
Created on Jun 06, 2017

__author__ = "Joshua Lock"
__copyright__ = "Copyright 2017, Intel Corp."
__credits__ = ["Joshua Lock"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = "Joshua Lock"
__email__ = "joshua.g.lock@intel.com"
'''


from buildbot.steps.shell import ShellCommand
from autobuilder.config import *
import os

class RemoveTmpFiles(ShellCommand):
    haltOnFailure = False
    flunkOnFailure = True
    name = "RemoveTmpFiles"

    def __init__(self, factory, argdict=None, **kwargs):
        self._pendingLogObservers = []
        self.files = ""
        for k, v in argdict.iteritems():
            setattr(self, k, v)
        # Timeout needs to be passed to LoggingBuildStep as a kwarg
        self.timeout = 100000
        kwargs['timeout'] = self.timeout
        ShellCommand.__init__(self, **kwargs)

    def start(self):
        # the "build" child of the buildbot builddir is the directory poky (or
        # openembedded-core) has been cloned to, the build subdirectory of that
        # directory (build/build) is the OE-Core BUILDDIR.
        builddir = os.path.join(self.getProperty("builddir"), "build", "build")

        filesOK = True
        if not self.files:
            self.files = os.path.join(builddir, 'tmp')
        else:
            files = self.files.split()
            for f in files:
                if f.startswith('/') and not f.startswith(builddir):
                    filesOK = False
                    break
                else:
                    abs = os.path.abspath(os.path.join(builddir, f))
                    if not abs.startswith(builddir):
                        filesOK = False
                        break

        # Ensure the resulting path is a sub-directory of the build directory
        if not filesOK:
            reason = "Skipping RemoveTmpFiles because one or more of '%s' "
            reason = reason + "aren't a child of the build directory "
            reason = reason + "(BUILDDIR) '%s'"
            reason = reason % (self.files, build)
            self.command = "echo '%s'" % reason
            self.description = ["%s" % reason]
        else:
            self.command = "rm -rf %s" % self.files

        ShellCommand.start(self)