Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VIGNET Pierre
cadbiom
Commits
b96339db
Commit
b96339db
authored
Jan 22, 2020
by
VIGNET Pierre
Browse files
[cmd] Move write_json() outside functions, for its reuse
parent
2f78dd9e
Changes
1
Hide whitespace changes
Inline
Side-by-side
command_line/cadbiom_cmd/solution_sort.py
View file @
b96339db
...
...
@@ -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!"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment