def get_path_line_number(self, path, with_attrs=False):
        path = path.split("| ")[1] if (with_attrs is True) else path

        orig = self.parsed
        path = get_dict_from_path(path, self.separator)
        res = traverse_and_remove_path(orig, path)
        orig = json.dumps(orig, indent=4).split("\n")

        if(len(orig) != self.file_line_number):
            raise ValueError("This json file formatting is not compatible. Please run `python -m json.tool file`")

        with_del = json.dumps(res, indent=4).split("\n")
        return(list_compare_idx(orig, with_del) + 1)
def get_yaml_path_line_python(file, path, include_type=False):
    if(not os.path.isfile(file)):
        sys.exit(1)
    path = path.split("| ")[1] if (include_type is True) else path
    orig = ""
    with open(file) as f:
        orig = yaml.load(f)
    path = get_dict_from_path(path)
    res = traverse_and_remove_path(orig, path)
    yaml_dump_options = {"indent": 4, "default_flow_style": False, "explicit_start": False}
    orig = yaml.dump(orig, **yaml_dump_options).split("\n")
    with_del = yaml.dump(dict(res), **yaml_dump_options).split("\n")
    return(list_compare_idx(orig, with_del) + 1)
    def get_path_line_number(self, path, with_attrs=False):
        path = path.split("| ")[1] if (with_attrs is True) else path

        orig = self.parsed
        path = get_dict_from_path(path, self.separator)
        res = traverse_and_remove_path(orig, path)
        orig = json.dumps(orig, indent=4).split("\n")

        if(len(orig) != self.file_line_number):
            raise ValueError("This json file formatting is not compatible. Please run `python -m json.tool file`")

        with_del = json.dumps(res, indent=4).split("\n")
        return(list_compare_idx(orig, with_del) + 1)
Exemple #4
0
def get_yaml_path_line_python(file, path, include_type=False):
    if (not os.path.isfile(file)):
        sys.exit(1)
    path = path.split("| ")[1] if (include_type is True) else path
    orig = ""
    with open(file) as f:
        orig = yaml.load(f)
    path = get_dict_from_path(path)
    res = traverse_and_remove_path(orig, path)
    yaml_dump_options = {
        "indent": 4,
        "default_flow_style": False,
        "explicit_start": False
    }
    orig = yaml.dump(orig, **yaml_dump_options).split("\n")
    with_del = yaml.dump(dict(res), **yaml_dump_options).split("\n")
    return (list_compare_idx(orig, with_del) + 1)