コード例 #1
0
def getJobConfigurationsFromConfigFile(configFile,
                                       additionalVarsDict={},
                                       jobsToInclude=[],
                                       tasksToInclude=[]):
    if not doesFileExist(configFile):
        printError('\ncan not find config file: {}'.format(configFile))
        return []
    configurations = None
    if configFile.endswith('.json'):
        with open(configFile) as configFileContent:
            configurations = json.load(configFileContent)
    elif configFile.endswith('.yaml') or configFile.endswith('.yaml'):
        with open(configFile) as configFileContent:
            configurations = yaml.load(configFileContent)
    else:
        printError(
            '\nunknown config file extension, only json or yaml are supportted'
        )
        return []
    jobArray = []
    for conf in configurations:
        job = config.Job(conf)
        if (len(jobsToInclude) > 0) and (job.name not in jobsToInclude):
            continue
        __removeUndesiredTasksIfNeeded(tasksToInclude, job)
        jobArray.append(job)
    __replaceEnvVars(jobArray, additionalVarsDict)
    return jobArray
コード例 #2
0
ファイル: yacg.py プロジェクト: OkieOth/yacg
def _getVars(args):
    vars = {}
    if args.vars is not None:
        for v in args.vars:
            keyValueArray = v.split('=')
            if (len(keyValueArray) == 2):
                vars[keyValueArray[0]] = keyValueArray[1]
            else:
                printError(
                    '\nvar param with wrong structure found ... skipped: {}'.
                    format(v))
    return vars
コード例 #3
0
def main():
    args = parser.parse_args()
    if not doesFileExist(args.model):
        printError('\nModel file not found ... cancel: {}'.format(args.model))
        sys.exit(1)
    if not _checkValidVersion(args.version):
        printError(
            '\nNo valid version argument was given, check the help: {}'.format(
                args.version))
        sys.exit(1)
    if not _checkDirToCheckForRefs(args.dirToCheckForRefs):
        printError(
            "\nThe given directory to check for references isn't a valid dir: {}"
            .format(args.dirToCheckForRefs))
        sys.exit(1)
    parsedSchema = builder.getParsedSchemaFromJson(args.model)
    currentVersion = parsedSchema.get("version", None)
    if currentVersion is None:
        printInfo('\nModel file does not contain a version: {}'.format(
            args.model))
        sys.exit(0)
    if not _checkValidVersion(currentVersion):
        printError(
            '\nCurrent version is no valid semver: {}'.format(currentVersion))
        sys.exit(1)
    newVersion = _calcNewVersion(currentVersion, args.version, True)
    logging.info("modelFile: {}, currentVersion: {}, newVersion: {}".format(
        args.model, currentVersion, newVersion))
    _printOutput(args.model, args.backupExt, args.dryRun, newVersion,
                 parsedSchema, currentVersion)
    if args.dirToCheckForRefs is not None:
        filesToCheckList = _getJsonSchemaFileNames(args.dirToCheckForRefs)
        _checkForReferences(args, newVersion, args.model, filesToCheckList,
                            [args.model])
コード例 #4
0
def main():
    args = parser.parse_args()
    if not args.stdin:
        if args.model is None:
            printError(
                '\nModel file not given. It can be passed as parameter or over stdin ... cancel'
            )
            sys.exit(1)
        model = args.model
    else:
        model = readStdin()
    if (not args.dryRun) and ((args.destDir is None) or
                              (not os.path.isdir(args.destDir))):
        printError(
            '\nDest dir for yaml output not found ... cancel: {}'.format(
                args.destDir))
        sys.exit(1)
    convertModel(model, args.dryRun, args.destDir)
コード例 #5
0
ファイル: yacg.py プロジェクト: OkieOth/yacg
def _getTemplateParameters(args):
    """extracts the per command line given template parameters, copies them
    into a dictionary and return this dictonary
    """

    templateParameters = []
    if args.templateParameters is not None:
        for parameter in args.templateParameters:
            keyValueArray = parameter.split('=')
            if (len(keyValueArray) == 2):
                templateParam = config.TemplateParam()
                templateParam.name = keyValueArray[0]
                templateParam.value = keyValueArray[1]
                templateParameters.append(templateParam)
            else:
                printError(
                    '\ntemplate param with wrong structure found ... skipped: {}'
                    .format(parameter))
    return templateParameters
コード例 #6
0
def getJobConfigurationsFromConfigFile(configFile, additionalVarsDict={}):
    if not doesFileExist(configFile):
        printError('\ncan not find config file: {}'.format(configFile))
        return []
    configurations = None
    if configFile.endswith('.json'):
        with open(configFile) as configFileContent:
            configurations = json.load(configFileContent)
    elif configFile.endswith('.yaml') or configFile.endswith('.yaml'):
        with open(configFile) as configFileContent:
            configurations = yaml.load(configFileContent)
    else:
        printError('\nunknown config file extension, only json or yaml are supportted')
        return []
    jobArray = []
    for conf in configurations:
        job = config.Job(conf)
        jobArray.append(job)
    __replaceEnvVars(jobArray, additionalVarsDict)
    return jobArray