Skip to content

Commit 94ab3d7

Browse files
Improve the replay.py script
Add proper arguments to specify the log file and the output file. For eng/ide/ada_language_server#1197
1 parent c317f66 commit 94ab3d7

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

scripts/replay.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
11
#!/usr/bin/env python
22

3-
""" Development utility to replay the most recent trace file, and output it
4-
as protocol strings. This assumes that the trace file is in ~/.als/in.txt
5-
6-
To use this, do
7-
8-
replay.py > log
9-
10-
then you can replay at will with
3+
"""
4+
Development utility to replay an ALS session based on a log file containing
5+
the ALS.IN and ALS.OUT traces, and output it as protocol strings.
116
12-
ada_language_server < log
7+
Usage: replay.py --log-file <path_to_log_file> --output-file <output_file>
138
"""
149

15-
import os
10+
import argparse
1611
from json_transformations import python_to_protocol_string, traces_to_test
1712

18-
als_dir = os.path.join(os.path.expanduser('~'), '.als')
19-
inout_file = os.path.join(als_dir, 'inout.txt')
13+
14+
argParser = argparse.ArgumentParser()
15+
argParser.add_argument(
16+
"-l",
17+
"--log-file",
18+
help="Path to the log file containing ALS.IN and ALS.OUT traces.",
19+
required=True,
20+
)
21+
argParser.add_argument(
22+
"-o",
23+
"--output-file",
24+
help="Path to the output file containing all the ALS requests retrieved "
25+
+ "from the log file. Then you can replay a session like this: "
26+
+ "ada_language_server < <output_file>",
27+
required=False,
28+
)
29+
args = argParser.parse_args()
30+
31+
inout_file = args.log_file
32+
output_file = args.output_file
2033
test = traces_to_test(inout_file, None, True)
2134
result = ""
2235
for x in test:
2336
if "send" in x:
2437
result += python_to_protocol_string([x["send"]["request"]])
25-
print(result + "\r")
38+
39+
# Print on stdout if no output file has been specified
40+
if output_file:
41+
with open(output_file, "w") as file:
42+
file.write(result + "\r")
43+
else:
44+
print(result + "\r")

0 commit comments

Comments
 (0)