-
Notifications
You must be signed in to change notification settings - Fork 3
/
extractor.py
68 lines (56 loc) · 2.73 KB
/
extractor.py
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
67
68
import os, sys
import argparse
from src.extractor import main
def check_files_extension(folder_path, extension):
for filename in os.listdir(folder_path):
if filename.endswith(extension):
return True
return False
def run_extractor(ros_version, start_time, end_time, file_path, filetype, input, time_space):
print(">>>> Bag File Extractor <<<<")
if start_time is None:
start_time = 'start'
if end_time is None:
end_time = 'end'
if ros_version == 'ros1':
if filetype == 'bag':
main.extractor(start_time, end_time, file_path, filetype, input, time_space)
else:
print("ROS1 only has filetype `bag`")
sys.exit()
elif ros_version == 'ros2':
if filetype == 'db3':
if check_files_extension(file_path, '.db3'):
main.extractor(start_time, end_time, file_path, filetype, input, time_space)
else:
print("Cannot find the correct file with the input filetype: " + filetype)
elif filetype == 'mcap':
if check_files_extension(file_path, '.mcap'):
main.extractor(start_time, end_time, file_path, filetype, input, time_space)
else:
print("Cannot find the correct file with the input filetype: " + filetype)
else:
print("Input the correct filetype. Valid filetypes in ROS2 are 'db3' and 'mcap'.")
else:
print("ROS version is unknown")
print(">>>>>>>>>>>>>><<<<<<<<<<<<<<<")
def run():
# Arguments definition and management
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--ros_version', help='ROS Version: ros1 or ros2', required=True, type=str)
parser.add_argument('-s', '--start_time', help='User-defined start time (in seconds)', required=False, type=str)
parser.add_argument('-e', '--end_time', help='User-defined end time (in seconds)', required=False, type=str)
parser.add_argument('-f', '--file_path', help='Path to FOLDER containing the ros bagfile.', required=True, type=str)
parser.add_argument('-ft', '--file_type', help='Bag file type: bag, db3 or mcap', required=True, type=str)
parser.add_argument('-i', '--input', help='Path to file containing nodes information', required=False, type=str)
parser.add_argument('-ts', '--time_space', help='Time in second to generate a series of interconnected graphs', required=False, type=str)
options = parser.parse_args()
run_extractor(options.ros_version,
options.start_time,
options.end_time,
options.file_path,
options.file_type,
options.input,
options.time_space)
if __name__ == "__main__":
run()