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

Review API: sol_digging() no longer write file, but returns json data; fix typos; add doc

parent 23a71366
......@@ -108,7 +108,7 @@ def load_solutions(file):
:param: File name
:type: <str>
:return:A tuple of "frontier places" and a list of events in each step.
:return: A tuple of "frontier places" and a list of events in each step.
("Bx Ax", [[u'h2', u'h00'], [u'h3'], [u'h0', u'h1'], [u'hlast']])
:rtype: <tuple <str>, <list>>
"""
......@@ -885,27 +885,29 @@ def test_main():
def sol_digging(decompiled_filename, sol_steps, transitions, conditions=True):
def sol_digging(sol_steps, transitions, conditions=True):
"""Convert all events for all solutions in a complete MAC file
and write them in a separate file in the json format.
This is a function to quickly search all transition attributes involved
in a solution.
:param arg1: Path of the json file.
:param arg2: List of steps involved in a solution. See load_solutions().
:param arg3: A dictionnary of events as keys, and transitions as values.
:param arg1: List of steps involved in a solution. See load_solutions().
A tuple of "frontier places" and a list of events in each step.
("Bx Ax", [[u'h2', u'h00'], [u'h3'], [u'h0', u'h1'], [u'hlast']])
:param arg2: A dictionnary of events as keys, and transitions as values.
Since many transitions can define an event, values are lists.
Each transition is a tuple with: origin node, final node, attributes
like label and condition.
{u'h00': [('Ax', 'n1', {u'label': u'h00[]'}),]
See get_transitions().
:param arg4: (Optional) Integrate in the final file,
:param arg3: (Optional) Integrate in the final file,
the conditions for each transition.
:type arg1: <str>
:type arg2: <list>
:type arg3: <dict <list <tuple <str>, <str>, <dict <str>: <str>>>>
:type arg4: <bool>
:type arg1: <list>
:type arg2: <dict <list <tuple <str>, <str>, <dict <str>: <str>>>>
:type arg3: <bool>
:return: Return the JSON data for the given steps.
:rtype: <list>
"""
def get_transition_def(step_event):
......@@ -972,9 +974,8 @@ def sol_digging(decompiled_filename, sol_steps, transitions, conditions=True):
# Debugging only
if LOGGER.getEffectiveLevel() == DEBUG:
LOGGER.debug(json.dumps(decomp_solutions, sort_keys=True, indent=4))
# Write file
with open(decompiled_filename, 'w') as f_d:
json.dump(decomp_solutions, f_d, sort_keys=True, indent=4)
return decomp_solutions
def sol_digging_main(output_dir, model_file, solution_path, conditions=True):
......@@ -984,19 +985,25 @@ def sol_digging_main(output_dir, model_file, solution_path, conditions=True):
or just a file.
"""
def write_json_file(decompiled_filename, decomp_solutions):
# Write file
with open(decompiled_filename, 'w') as f_d:
json.dump(decomp_solutions, f_d, sort_keys=True, indent=4)
# Get transitions from the model
model_transitions = get_transitions(model_file)
decompiled_filename = output_dir + filename + '_decomp' + file_extension
if os.path.isfile(solution_path):
# The given path is a solution file
# Add _decomp to the solution filename
filename, file_extension = os.path.splitext(solution_path)
sol_digging(
output_dir + filename + '_decomp' + file_extension,
decomp_solutions = sol_digging(
load_solutions(solution_path),
model_transitions,
conditions=conditions,
)
write_json_file(decompiled_filename, decomp_solutions)
elif os.path.isdir(solution_path):
# The given path is a directory
......@@ -1009,12 +1016,12 @@ def sol_digging_main(output_dir, model_file, solution_path, conditions=True):
# Add _decomp to the solution filename
filename, file_extension = os.path.splitext(solution_file)
sol_digging(
output_dir + filename + '_decomp' + file_extension,
decomp_solutions = sol_digging(
load_solutions(solution_file),
model_transitions,
conditions=conditions,
)
write_json_file(decompiled_filename, decomp_solutions)
LOGGER.info("Files processed: " + str(file_number))
......
Markdown is supported
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