Commit b96339db authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[cmd] Move write_json() outside functions, for its reuse

parent 2f78dd9e
......@@ -153,6 +153,29 @@ def solutions_sort(path):
## Conversion functions ########################################################
def write_json(output_dir, file_path, file_suffix, data):
"""Write decompiled solutions to a JSON formated file
Called by :meth:`solutions_2_json TODO` and :meth:`queries_2_common_graph`
:param output_dir: Output directory
:param file_path: Filepath of the original solution file.
We extract the basename in order to name the JSON file.
:param file_suffix: String added to the solution filename.
Ex: filename + file_suffix + ".json"
:param data: Data to be serialized in JSON
:type output_dir: <str>
:type file_path: <str>
:type file_suffix: <str>
:type data: <list> or <dict> or <whatever>
"""
# Add file_suffix to the solution filename
filename = os.path.basename(os.path.splitext(file_path)[0])
with open(output_dir + filename + file_suffix + '.json', 'w') as f_d:
json.dump(data, f_d, sort_keys=True, indent=2)
## query - json
def solutions_2_json(output_dir, model_file, path, conditions=True):
"""Entry point for solutions_2_json
......@@ -176,16 +199,6 @@ def solutions_2_json(output_dir, model_file, path, conditions=True):
:type path: <str>
:type conditions: <boolean>
"""
def write_json_file(file_path, decomp_solutions):
"""Write decompiled solutions to a JSON formated file"""
# Add _decomp to the solution filename
filename = os.path.basename(os.path.splitext(file_path)[0])
with open(output_dir + filename + '_decomp.json', 'w') as f_d:
json.dump(decomp_solutions, f_d, sort_keys=True, indent=2)
# Check valid input file/directory
assert os.path.isfile(path) or os.path.isdir(path)
......@@ -199,7 +212,7 @@ def solutions_2_json(output_dir, model_file, path, conditions=True):
model_transitions,
conditions=conditions,
)
write_json_file(path, decomp_solutions)
write_json(output_dir, path, "_decomp", decomp_solutions)
elif os.path.isdir(path):
# The given path is a directory
......@@ -215,7 +228,7 @@ def solutions_2_json(output_dir, model_file, path, conditions=True):
model_transitions,
conditions=conditions,
)
write_json_file(solution_file, decomp_solutions)
write_json(solution_file, path, "_decomp", decomp_solutions)
LOGGER.info("Files processed: %s", file_number)
assert file_number != 0, "No *mac_complete.txt files found!"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment