-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathosi2read.py
More file actions
66 lines (52 loc) · 1.49 KB
/
osi2read.py
File metadata and controls
66 lines (52 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
This program converts serialized osi trace files into a human readable txth file.
Example usage:
python3 osi2read.py -d trace.osi -o myreadableosifile
"""
from osi3trace.osi_trace import OSITrace
import argparse
import pathlib
def command_line_arguments():
"""Define and handle command line interface"""
parser = argparse.ArgumentParser(
description="Convert a serialized osi trace file to a readable txth output.",
prog="osi2read",
)
parser.add_argument(
"--data",
"-d",
help="Path to the file with serialized data.",
type=str,
required=True,
)
parser.add_argument(
"--type",
"-t",
help="Name of the type used to serialize data.",
choices=["SensorView", "GroundTruth", "SensorData"],
default="SensorView",
type=str,
required=False,
)
parser.add_argument(
"--output",
"-o",
help="Output name of the file.",
type=str,
required=False,
)
return parser.parse_args()
def main():
# Handling of command line arguments
args = command_line_arguments()
# Initialize the OSI trace class
trace = OSITrace(args.data, args.type)
if not args.output:
path = pathlib.Path(args.data).with_suffix(".txth")
args.output = str(path)
with open(args.output, "wt") as f:
for message in trace:
f.write(str(message))
trace.close()
if __name__ == "__main__":
main()