'''
Created on Jan 10, 2013

__author__ = "Elizabeth 'pidge' Flanagan"
__copyright__ = "Copyright 2012-2013, Intel Corp."
__credits__ = ["Elizabeth Flanagan"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = "Elizabeth Flanagan"
__email__ = "elizabeth.flanagan@intel.com"
'''


from buildbot.steps.shell import ShellCommand
from buildbot.status.results import SUCCESS, FAILURE
import os

class RunSanityTests(ShellCommand):

    haltOnFailure = False 
    flunkOnFailure = True 
    name = "Running Sanity Tests" 
    def __init__(self, factory, argdict=None, **kwargs):
        self.factory = factory
        self.images=""
        for k, v in argdict.iteritems():
            setattr(self, k, v)
        self.description = "Running Sanity Tests"
        command = ""
        command = command + ". ./oe-init-build-env; "
        command = command + "(echo > /dev/tcp/localhost/5901) 2> /dev/null;"
        command = command + 'if [ $? -ne 0 ]; then echo "Starting a VNC server on :1"; vncserver :1; else echo "Will use a VNC server already running on :1"; fi;'
        command = command + "echo 'IMAGETEST = \"qemu\"' >> ./conf/auto.conf;"
        command = command + "DISPLAY=localhost:1 bitbake " + self.images + " -c qemuimagetest_standalone"
        # Timeout needs to be passed to LoggingBuildStep as a kwarg
        self.timeout = 100000
        kwargs['timeout']=self.timeout
        self.command = command
        ShellCommand.__init__(self)

    def describe(self, done=False):
        description = ShellCommand.describe(self,done)
        return description


'''
Created on Jan 10, 2013

__author__ = "Elizabeth 'pidge' Flanagan"
__copyright__ = "Copyright 2012-2013, Intel Corp."
__credits__ = ["Elizabeth Flanagan"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = "Elizabeth Flanagan"
__email__ = "elizabeth.flanagan@intel.com"
'''


from buildbot.steps.shell import ShellCommand
from buildbot.status.results import SUCCESS, FAILURE
import os

class RunSanityTests(ShellCommand):

    haltOnFailure = False 
    flunkOnFailure = True 
    name = "Running Sanity Tests" 
    def __init__(self, factory, argdict=None, **kwargs):
        self.factory = factory
        self.images=""
        self.scene=None
        for k, v in argdict.iteritems():
            setattr(self, k, v)
        self.description = "Running Sanity Tests"
        command = ""
        command = command + ". ./oe-init-build-env; "
        command = command + "(echo > /dev/tcp/localhost/5901) 2> /dev/null;"
        command = command + 'if [ $? -ne 0 ]; then echo "Starting a VNC server on :1"; vncserver :1; else echo "Will use a VNC server already running on :1"; fi;'
        command = command + "echo 'IMAGETEST = \"qemu\"' >> ./conf/auto.conf;"
        if self.scene:
            command = command + "echo 'TEST_SCEN = \"" + self.scene + "\"'" + " >> ./conf/auto.conf;"
        command = command + "DISPLAY=localhost:1 bitbake " + self.images + " -c qemuimagetest_standalone"
        # Timeout needs to be passed to LoggingBuildStep as a kwarg
        self.timeout = 100000
        kwargs['timeout']=self.timeout
        self.command = command
        ShellCommand.__init__(self)

    def describe(self, done=False):
        description = ShellCommand.describe(self,done)
        return description


add suport for custom steps