|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
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. |
11 | 6 |
|
12 |
| - ada_language_server < log |
| 7 | +Usage: replay.py --log-file <path_to_log_file> --output-file <output_file> |
13 | 8 | """
|
14 | 9 |
|
15 |
| -import os |
| 10 | +import argparse |
16 | 11 | from json_transformations import python_to_protocol_string, traces_to_test
|
17 | 12 |
|
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 |
20 | 33 | test = traces_to_test(inout_file, None, True)
|
21 | 34 | result = ""
|
22 | 35 | for x in test:
|
23 | 36 | if "send" in x:
|
24 | 37 | 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