From be30af9240d5b9ae2804068c1130e87df8553ee7 Mon Sep 17 00:00:00 2001 From: DSungatulin Date: Sun, 7 Jan 2024 01:00:59 +0600 Subject: [PATCH] step 5 --- gendiff/engine.py | 19 +++++++++++++++++++ gendiff/json_diff.py | 6 ++++++ gendiff/scripts/json_diff.py | 6 ------ gendiff/scripts/yaml_diff.py | 6 ------ gendiff/yaml_diff.py | 6 ++++++ 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 gendiff/engine.py create mode 100644 gendiff/json_diff.py delete mode 100644 gendiff/scripts/json_diff.py delete mode 100644 gendiff/scripts/yaml_diff.py create mode 100644 gendiff/yaml_diff.py diff --git a/gendiff/engine.py b/gendiff/engine.py new file mode 100644 index 0000000..a4e8542 --- /dev/null +++ b/gendiff/engine.py @@ -0,0 +1,19 @@ +from gendiff.json_diff import open_json +from gendiff.yaml_diff import open_yaml + + +def convert_bool_value(val): + bool_value = {'True': 'true', 'False': 'false'} + if isinstance(val, bool): + return bool_value[str(val)] + else: + return val + + +def format_decoder(filepath): + if filepath.endswith('json'): + return open_json(filepath) + elif filepath.endswith('yml') or filepath.endswith('yaml'): + return open_yaml(filepath) + else: + raise ValueError("Invalid file format!") \ No newline at end of file diff --git a/gendiff/json_diff.py b/gendiff/json_diff.py new file mode 100644 index 0000000..9fc47bd --- /dev/null +++ b/gendiff/json_diff.py @@ -0,0 +1,6 @@ +import json + + +def open_json(filepath): + deserialized_file = json.load(open(filepath)) + return deserialized_file diff --git a/gendiff/scripts/json_diff.py b/gendiff/scripts/json_diff.py deleted file mode 100644 index 04d3c95..0000000 --- a/gendiff/scripts/json_diff.py +++ /dev/null @@ -1,6 +0,0 @@ -import json - - -def open_json(file_path): - deserialized_file = json.load(open(file_path)) - return deserialized_file \ No newline at end of file diff --git a/gendiff/scripts/yaml_diff.py b/gendiff/scripts/yaml_diff.py deleted file mode 100644 index 9c8cfff..0000000 --- a/gendiff/scripts/yaml_diff.py +++ /dev/null @@ -1,6 +0,0 @@ -import yaml - - -def open_yaml(file_path): - deserialized_file = yaml.safe_load(open(file_path)) - return deserialized_file diff --git a/gendiff/yaml_diff.py b/gendiff/yaml_diff.py new file mode 100644 index 0000000..3af3d9f --- /dev/null +++ b/gendiff/yaml_diff.py @@ -0,0 +1,6 @@ +import yaml + + +def open_yaml(filepath): + deserialized_file = yaml.safe_load(open(filepath)) + return deserialized_file