def get_schemas_linux(path_to_schemas):
    '''Linux version: Get the stem and path and create the a dictionary of stems to paths.'''
    list_of_files = MU.get_files(path_to_schemas, "json")
    schema_dict = {}
    for i in list_of_files:
        stem = i.split("\\")[-1].split(".")[0]
        schema_dict[stem] = i.replace("\\", "/")
    return schema_dict
def get_schemas(path_to_schemas):
    '''Get the stem and path and create the a dictionary of stems to paths.'''
    list_of_files = MU.get_files(path_to_schemas, "json")
    schema_dict = {}
    for i in list_of_files:
        stem = i.split("\\")[-1].split(".")[0]
        schema_dict[stem] = i
    return schema_dict
def main():
    '''
        Validate includes in the repo. (Main Logic for repo parsing)
    '''
    include_paths = MU.get_files(MODULES, "md")
    schema_paths = VAL.get_schemas(SCHEMAS)
    schema_set = set(schema_paths.keys())
    report = []
    report.append(["issueid", "validation status", "path", "error"])
    validatation_state = True
    for p in include_paths:
        split_path = p.split("\\")[-1].split("-")
        path_slug = "{}-{}".format(split_path[0], split_path[1])
        slug_index = len(path_slug)
        if path_slug in schema_set:
            in_body = MU.get_textfromMD(p)
            valid_id = p.split("\\")[-1][:-3]
            print("Validating module {} for {}".format(path_slug,
                                                       valid_id[slug_index:]))
            try:
                if VAL.validate_base_file(in_body):
                    body_parse = VAL.parse_module(in_body)
                    v_line = VAL.validate_module_ki(schema_paths[path_slug],
                                                    body_parse)
                    if v_line["summary"]:
                        report.append(
                            [valid_id, v_line["summary"], p, "No error."])
                    else:
                        validatation_state = False
                        fields = list(v_line["details"].keys())
                        for f in fields:
                            error_message = "{}: {}".format(
                                v_line["details"][f][0], f)
                            report.append([
                                valid_id, v_line["summary"], p, error_message
                            ])
                else:
                    report.append(
                        [valid_id, False, p, "Not a valid include file."])
                    validatation_state = False
            except Exception as e:
                report.append([
                    valid_id, False, p,
                    "Not a valid include file. {}".format(e)
                ])
                validatation_state = False
    MU.write_csv(report, VALIDATIONREPORT)
    print("The repository is valid: {}".format(validatation_state))
    print("The validation report saved to: " + VALIDATIONREPORT)
Exemple #4
0
def main():
    '''
        Validate includes in the repo. (Main Logic for repo parsing)
    '''
    include_paths = fix_path(MU.get_files(MODULES, "md"))
    schema_paths = VAL.get_schemas_linux(SCHEMAS)
    schema_set = set(schema_paths.keys())
    report = []
    report.append(["ID", "Valid", "Issue"])
    validatation_state = True
    for p in include_paths:
        split_path = p.split("/")[-1].split("-")
        path_slug = "{}-{}".format(split_path[0],split_path[1])
        slug_index = len(path_slug)
        if path_slug in schema_set:
            in_body = MU.get_textfromMD(p)
            valid_id = p.split("/")[-1][:-3]
            try:
                if VAL.validate_base_file(in_body):
                    body_parse = VAL.parse_module(in_body)
                    v_line = VAL.validate_module_ki(schema_paths[path_slug], body_parse)
                    if v_line["summary"]:
                        report.append([valid_id, v_line["summary"], "No error."])
                    else:
                        validatation_state = False
                        fields = list(v_line["details"].keys())
                        for f in fields:
                            error_message = "{}: {}".format(v_line["details"][f][0], f)
                            report.append([valid_id, v_line["summary"],error_message ])
                else:
                    report.append([valid_id, False, "Not a valid include file."])
                    validatation_state = False
            except Exception as e:
                    report.append([valid_id, False, "Not a valid include file. {}".format(e)])
                    validatation_state = False
    output_table(report)
    print("The repository is valid: {}".format(validatation_state))
    MU.write_text("{}".format(validatation_state), "state.txt")
def main():
    ''' Parse the include modules and create a report.'''
    include_paths = MU.get_files(MODULES, "md")
    report = []
    headers = []
    for p in include_paths:
        if p.find(SLUG) > -1:
            inbody = MU.get_textfromMD(p)
            valid_id = p.split("\\")[-1][:-3]
            print("Reporting on " + valid_id[6:])
            try:
                if VAL.validate_base_file(inbody):
                    parsed_body = VAL.parse_module(inbody)
                    if report == []:
                        headers = list(parsed_body.keys())
                        report.append(headers)
                    addrow = get_vals_as_list(headers, parsed_body)
                    report.append(addrow)
                else:
                    print("Error ingesting issue for {} : error: Not a valid include file".format(valid_id))
            except Exception as e:
                    print("Error ingesting issue for {} : error: {}".format(valid_id, e))
    MU.write_csv(report, POWERBIREPORT)
    print("The PowerBI report saved to: " + POWERBIREPORT)