From 8cceff887fc0c7a25ef61413b410dc66c0b98444 Mon Sep 17 00:00:00 2001 From: Eiko Thomas Date: Fri, 15 Nov 2024 15:18:53 +0100 Subject: [PATCH 1/3] add the sort_dict helper script --- sort_dict.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 sort_dict.py diff --git a/sort_dict.py b/sort_dict.py new file mode 100644 index 0000000..8082cad --- /dev/null +++ b/sort_dict.py @@ -0,0 +1,66 @@ +import json +import argparse +import sys + +description = """Takes two JSON files as input +and aligns the order of the input file with the provided order by master +""" + + +parser = argparse.ArgumentParser(prog='sort_dict', description=description) +parser.add_argument('--master', help='path to the JSON file that provides the desired order') +parser.add_argument('--input', help='path to JSON file that needs the aligned order') +parser.add_argument('--output', help='path to the desired output file') + + +def load_json(file_path): + with open(file_path, 'r') as file: + return json.load(file) + +def sort_dict(inputDict, masterDict): + outputDict = {} + if masterDict is not None: + for k, v in masterDict.items(): + value = inputDict.get(k, None) + if value is not None: + outputDict[k] = value + if isinstance(value, dict): + outputDict[k] = sort_dict(value, v) + else: + outputDict[k] = value + inputDict.pop(k) + for k, v in inputDict.items(): + outputDict[k] = v + return outputDict + +if __name__ == '__main__': + args = parser.parse_args() + if args.master is None: + print("\nmissing input parameter '--master' for the file that provides the structure\n") + sys.exit(1) + if args.input is None: + print("\nmissing parameter '--input' for the file to read\n") + sys.exit(1) + if args.output is None: + print("\nmissing parameter '--output' for the output file to write\n") + sys.exit(1) + + masterDict = load_json(args.master) + inputDict = load_json(args.input) + + outputDict = {} + + for k, v in masterDict.items(): + value = inputDict.get(k, None) + if value is not None: + if isinstance(value, dict): + outputDict[k] = sort_dict(value, v) + else: + outputDict[k] = value + inputDict.pop(k) + for k, v in inputDict.items(): + outputDict[k] = v + + with open(args.output, 'w') as outfile: + json.dump(outputDict, outfile, indent=2) + From 82a7e0eff402137ac456db90f542ec9bf7ad9577 Mon Sep 17 00:00:00 2001 From: Eiko Thomas Date: Fri, 15 Nov 2024 15:20:02 +0100 Subject: [PATCH 2/3] add sort_dict to the dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 5c720b8..44dd95b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ ADD randomDataServer.py randomDataServer.py ADD customRandomConstraints.py customRandomConstraints.py ADD validate.py validate.py ADD validateSchemas.py validateSchemas.py +ADD sort_dict.py sort_dict.py ADD version.txt version.txt ADD requirements.txt requirements.txt #ADD start_debug.sh start_debug.sh From 0e2924d1728fcba5c50d2416cc439c235d9b2e7e Mon Sep 17 00:00:00 2001 From: Eiko Thomas Date: Fri, 15 Nov 2024 15:20:32 +0100 Subject: [PATCH 3/3] bump version --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 97f5781..cf79bf9 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -6.9.0 +6.10.0