2019-03-29 13:23:58 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
2023-10-26 13:11:05 +00:00
|
|
|
"""
|
|
|
|
|
Development utility to replay an ALS session based on a log file containing
|
|
|
|
|
the ALS.IN and ALS.OUT traces, and output it as protocol strings.
|
2019-03-29 13:23:58 +01:00
|
|
|
|
2023-10-26 13:11:05 +00:00
|
|
|
Usage: replay.py --log-file <path_to_log_file> --output-file <output_file>
|
2019-03-29 13:23:58 +01:00
|
|
|
"""
|
|
|
|
|
|
2023-10-26 13:11:05 +00:00
|
|
|
import argparse
|
2024-10-02 10:22:18 +00:00
|
|
|
import os
|
2019-03-29 13:23:58 +01:00
|
|
|
from json_transformations import python_to_protocol_string, traces_to_test
|
|
|
|
|
|
2023-10-26 13:11:05 +00:00
|
|
|
|
|
|
|
|
argParser = argparse.ArgumentParser()
|
|
|
|
|
argParser.add_argument(
|
|
|
|
|
"-l",
|
|
|
|
|
"--log-file",
|
|
|
|
|
help="Path to the log file containing ALS.IN and ALS.OUT traces.",
|
|
|
|
|
required=True,
|
|
|
|
|
)
|
|
|
|
|
argParser.add_argument(
|
|
|
|
|
"-o",
|
|
|
|
|
"--output-file",
|
|
|
|
|
help="Path to the output file containing all the ALS requests retrieved "
|
|
|
|
|
+ "from the log file. Then you can replay a session like this: "
|
|
|
|
|
+ "ada_language_server < <output_file>",
|
|
|
|
|
required=False,
|
|
|
|
|
)
|
|
|
|
|
args = argParser.parse_args()
|
|
|
|
|
|
|
|
|
|
inout_file = args.log_file
|
|
|
|
|
output_file = args.output_file
|
2019-07-30 14:00:29 -04:00
|
|
|
test = traces_to_test(inout_file, None, True)
|
2019-03-29 13:23:58 +01:00
|
|
|
result = ""
|
|
|
|
|
for x in test:
|
|
|
|
|
if "send" in x:
|
|
|
|
|
result += python_to_protocol_string([x["send"]["request"]])
|
2023-10-26 13:11:05 +00:00
|
|
|
|
|
|
|
|
# Print on stdout if no output file has been specified
|
|
|
|
|
if output_file:
|
|
|
|
|
with open(output_file, "w") as file:
|
2024-10-02 10:22:18 +00:00
|
|
|
file.write(result + os.linesep)
|
2023-10-26 13:11:05 +00:00
|
|
|
else:
|
2024-10-02 10:22:18 +00:00
|
|
|
print(result + os.linesep)
|