_narval/checkers/apycot/scenarios.py
author David Douard <david.douard@logilab.fr>
Wed, 27 Sep 2017 12:39:06 +0200
changeset 1871 980e20892562
parent 1513 c6bcb8c3f96d
permissions -rw-r--r--
[checker/pypi] allow to configure the pypi repo to use and defaults to 'pypi'.

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)