示例#1
0
def getYamlList(data, line, field):
    if (not isinstance(data, list)):
        if (isinstance(data, dict)):
            raise GeneratorException(
                f"field '{field}' expects a list at line {data['__line__']}")
        raise GeneratorException(
            f"field '{field}' expects a list at line {line}")
    return data
示例#2
0
def getYamlString(data, line, field):
    if (not isinstance(data, str)):
        if (isinstance(data, dict)):
            raise GeneratorException(
                f"field '{field}' expects an integer at line {data['__line__']}"
            )
        raise GeneratorException(
            f"field '{field}' expects a string at line {line}")
    return data
def getYamlPaths(data, line=None, field=None):
    if isinstance(data, str):
        dirs = shlex.split(data)
        if (len(dirs) == 2):
            return dirs
    if (line and field):
        raise GeneratorException(
            f"Field '{field}' expects two paths at line {line}")
    else:
        raise GeneratorException(f"'diff' block not recognized")
示例#4
0
def getYamlInt(data, line, field):
    if data == None: return None
    if (not isinstance(data, int)):
        if (isinstance(data, dict)):
            raise GeneratorException(
                f"field '{field}' expects an integer at line {data['__line__']}"
            )
        raise GeneratorException(
            f"field '{field}' expects an integer at line {line}")

    return data
def _parseignore(data, line, field):
    listignore = getYamlList(data, line, field)
    for ignoreline in listignore:
        if (not isinstance(ignoreline, str)):
            raise GeneratorException(
                f"Field '{field}' expects a list of strings at line {line}")
    return listignore
def _parseStrategy(data, line, field):
    strStrat = getYamlString(data, line, field)
    if not any(x for x in diffStrategy if x.name == strStrat):
        raise GeneratorException(
            f"Invalid value '{strStrat}' for field '{field}' at line {line}")

    return diffStrategy[data]
示例#7
0
def _parseEntries(data):
    if data == None: return []
    knownkeys = {'product': _parseProduct, 'zip': _parseZip}
    entries = []
    for key in data:
        if key == "__line__": continue
        if not key.lower() in knownkeys.keys():
            raise GeneratorException(
                f"Only one of the following keys are allowed: {[*knownkeys.keys()]} at line {data['__line__']}"
            )
        entries.extend(knownkeys[key](data[key]))
    return entries
示例#8
0
def generateRunBlock(data):
    if isinstance(data, str):
        return RunBlock(cmd=data)
    if not isinstance(data, dict):
        raise GeneratorException(f"'run' block not recognized")
    args = {}
    key = ""
    knownkeys = {
        'cmd': lambda _data: getYamlString(_data, data['__line__'], key),
        'outputfile':
        lambda _data: getYamlString(_data, data['__line__'], key),
        'inputfile': lambda _data: getYamlString(_data, data['__line__'], key),
        'exitcode': lambda _data: getYamlInt(_data, data['__line__'], key),
        'shell': lambda _data: getYamlString(_data, data['__line__'], key)
    }
    for key in data:
        if key == "__line__": continue
        if not key.lower() in knownkeys.keys():
            raise GeneratorException(
                f"Only one of the following keys are allowed: {[*knownkeys.keys()]} at line {data['__line__']}"
            )
        args[key.lower()] = knownkeys[key.lower()](data[key])
    return RunBlock(**args)
示例#9
0
def _parseSteps(data, line):
    steps = list()
    knownkeys = {
        'serial': generateSerialBlock,
        'parallel': generateParallelBlock,
        'run': generateRunBlock,
        'diff': generateDiffBlock,
        'makedirs': generateMakedirs,
        'rmdir': generateRmdir
    }
    for yamlSteps in data:
        for key in yamlSteps:
            if key == "__line__": continue
            if not key.lower() in knownkeys.keys():
                if (isinstance(data, dict)):
                    raise GeneratorException(
                        f"Error: Key '{key}' not allowed. Only one of the following keys are allowed :{[*knownkeys.keys()]} at line {data['__line__']}"
                    )
                else:
                    raise GeneratorException(
                        f"Error: Key '{key}' not allowed. Only one of the following keys are allowed :{[*knownkeys.keys()]} at line {line}"
                    )
            steps.append(knownkeys[key.lower()](yamlSteps[key]))
    return steps
示例#10
0
def generateSerialBlock(data):
    if data == None: return
    args = {}
    knownkeys = {
        'entries': lambda data: list(_parseEntries(data)),
        'failfast': lambda _data: getYamlBool(_data, data['__line__'], key),
        'steps': lambda _data: list(_parseSteps(_data, data['__line__']))
    }
    for key in data:
        if key == "__line__": continue
        if not key.lower() in knownkeys.keys():
            raise GeneratorException(
                f"Only one of the following keys are allowed: {[*knownkeys.keys()]} at line {data['__line__']}"
            )
        args[key.lower()] = knownkeys[key.lower()](data[key])
    return Serial(**args)
示例#11
0
def replaceVariables(line, dictReplVar, printer=Printer()):
    global __replaceVariablesExp
    if line == None: return (True, line)
    searchStart = 0
    while (True):
        m = __replaceVariablesExp.search(line[searchStart:])
        if not m:
            break
        foundVar = m.group()[2:-1]
        replaceVal = dictReplVar.get(foundVar)
        if (replaceVal):
            strReplaceVal = str(replaceVal)
            line = line[:searchStart +
                        m.start()] + strReplaceVal + line[searchStart +
                                                          m.end():]
            searchStart += m.start() + len(strReplaceVal)
        else:
            raise GeneratorException("Variable " + str(m.group()) +
                                     " does not exist")
    line = line.replace(r'\$', "$")
    return line
示例#12
0
def generateDiffBlock(data):
    if isinstance(data, str):
        return DiffBlock(paths=getYamlPaths(data))
    if not isinstance(data, dict):
        raise DiffBlock(f"'diff' block not recognized")
    args = {}
    key = ""
    knownkeys = {
        'paths': lambda _data: getYamlPaths(_data, data['__line__'], key),
        'binarycompare':
        lambda _data: getYamlBool(_data, data['__line__'], key),
        'strategy': lambda _data: _parseStrategy(_data, data['__line__'], key),
        'ignore': lambda _data: _parseignore(_data, data['__line__'], key)
    }
    for key in data:
        if key == "__line__": continue
        if not key.lower() in knownkeys.keys():
            raise GeneratorException(
                f"Only one of the following keys are allowed: {[*knownkeys.keys()]} at line {data['__line__']}"
            )
        args[key.lower()] = knownkeys[key.lower()](data[key])
    return DiffBlock(**args)
示例#13
0
def generateMakedirs(data):
    if not isinstance(data, str):
        raise GeneratorException("'makedirs' block not recognized")
    return MakedirsBlock(data)
示例#14
0
def generateRmdir(data):
    if not isinstance(data, str):
        raise GeneratorException(f"'rmdirs' block not recognized")
    return RmdirBlock(data)