aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/autobuilder/buildsteps/ScrapeTargets.py
blob: 0480f3de38b40805eea5f406dcc42aed51fd7043 (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
66
67
'''
Created on Apr 27, 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 buildbot.status.results import SUCCESS, FAILURE
from autobuilder.config import *
import os
import re

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

    def __init__(self, factory, argdict=None, **kwargs):
        self._pendingLogObservers = []
        self.source = ""
        self.targetsvar = ""
        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):
        if not self.targetsvar or not self.source:
            self.step_status.setText(["Scrape incorrectly configured."])
            self.finished(FAILURE)
            return

        workerdir = os.path.join(os.path.join(YOCTO_ABBASE, "yocto-worker"))
        buildername = self.getProperty("buildername")
        src = os.path.join(workerdir, buildername, "build", self.source)
        self.command = ["cat", src]
        ShellCommand.start(self)

    def commandComplete(self, cmd):
        if cmd.didFail():
            return

        result = cmd.logs['stdio'].getText()
        start = result.find(self.targetsvar) + len(self.targetsvar)
        res = re.search('"([^"]*)"', result[start:])
        targets = ""
        if res:
            targets = res.group()
            # Try and ensure we scrape the target regardless of which
            # assignment operator is used and surrounding whitespace
            targets = targets.replace(self.targetsvar, '')
            targets = targets.translate(None, ':+?="')
            targets = targets.replace("\\", "")
            targets = targets.replace ("\n", "")
        self.setProperty("scraped_targets",
                         targets,
                         'Targets "%s" scraped from %s' % (targets,
                                                           self.source))