Esempio n. 1
0
def generate_diff(after, before, name_formater='stylish'):

    after = parse(after)
    before = parse(before)
    diff = make_diff(after, before)
    make_diff_format = select_formater(name_formater)

    return make_diff_format(diff)
Esempio n. 2
0
def generate_diff(file_path_1, file_path_2, format="stylish"):
    data_1 = open(abspath(file_path_1))
    data_2 = open(abspath(file_path_2))

    parsed_data_1 = parser.parse(data_1, get_file_format(file_path_1))
    parsed_data_2 = parser.parse(data_2, get_file_format(file_path_2))

    diff_tree = tree.build_diff(parsed_data_1, parsed_data_2)
    return formatter.format(diff_tree, format)
Esempio n. 3
0
def generate_diff(path1, path2, format='stylish'):
    """Generate diff of two files

    Args:
        path1 (str): Path to the first file
        path2 (str): Path to the second file
        format (str): Output format

    Returns:
        string: Difference between two files in selected format
    """

    file1 = parse(path1)
    file2 = parse(path2)

    keys1 = set(file1.keys())
    keys2 = set(file2.keys())

    diff = []

    for key in keys1 | keys2:
        if key in keys1 and key in keys2:
            if file1[key] == file2[key]:
                diff.append({
                    "key": key,
                    "value1": file1[key],
                    "value2": file2[key],
                    "status": "unchanged"
                })
            else:
                diff.append({
                    "key": key,
                    "value1": file1[key],
                    "value2": file2[key],
                    "status": "updated",
                })

        elif key in keys1:
            diff.append({
                "key": key,
                "value1": file1[key],
                "value2": None,
                "status": "removed",
            })

        elif key in keys2:
            diff.append({
                "key": key,
                "value1": None,
                "value2": file2[key],
                "status": "added",
            })

    return diff
Esempio n. 4
0
def get_data(path: str) -> dict:
    """Read data from file."""
    fullpath = os.path.abspath(path)
    _, ext = os.path.splitext(path)
    with open(fullpath, 'r', encoding='utf-8') as raw_data:
        return parse(raw_data.read(), ext)
Esempio n. 5
0
def get_data(filepath):
    data = open_if_files_exists(filepath)
    input_format = get_file_format(filepath).upper()
    return parse(data, input_format)