_narval/checkers/apycot/scenarios.py
author David Douard <david.douard@logilab.fr>
Sun, 26 Oct 2014 22:46:44 +0100
changeset 1768 48066736c862
parent 1513 c6bcb8c3f96d
permissions -rw-r--r--
[recipe] make recipe names a bit more consistant

import os
from commands import getstatusoutput
from apycotlib import SUCCESS, FAILURE, ERROR
from apycotlib import register

from checkers.apycot import AbstractFilteredFileChecker

class ScriptRunner(AbstractFilteredFileChecker):
    """
    run files accepted by the filter
    """
    id = 'script_runner'
    def do_check(self, test):
        if self.options.get('filename_filter') is not None:
            self.filename_filter = self.options.get('filename_filter')
        super(ScriptRunner, self).do_check(test)

    def check_file(self, filepath):
        try:
            self.writer.debug("running : " + filepath, path=filepath)
            status, out = getstatusoutput(filepath)
            if status != 0:
                self.writer.error(out, path=filepath)
                return FAILURE
            self.writer.info(out, path=filepath)
            return SUCCESS
        except Exception, error:
            self.writer.error(error.msg, path=filepath)
            return ERROR

register('checker', ScriptRunner)