Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
reindex_active_rosbags.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3# Copyright (C) 2021 LEIDOS.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16
17import os
18import subprocess
19import sys
20
21# Usage:
22# python reindex_active_rosbags.py <path to folder containing .bag.active files>
23
24def reindex_bag_files(source_folder):
25 # List of bag files to re-index
26 # Note: This example list includes .bag.active files from TIM use case testing 5/25-5/27
27 files_to_reindex = ["_2021-05-25-17-47-01.bag.active",
28 "_2021-05-25-17-53-47.bag.active",
29 "_2021-05-25-18-14-12.bag.active",
30 "_2021-05-25-18-19-06.bag.active",
31 "_2021-05-25-18-24-50.bag.active",
32 "_2021-05-25-18-54-32.bag.active",
33 "_2021-05-25-19-06-02.bag.active",
34 "_2021-05-25-19-19-45.bag.active",
35 "_2021-05-25-20-32-22.bag.active",
36 "_2021-05-25-20-49-05.bag.active",
37 "_2021-05-26-13-09-39.bag.active",
38 "_2021-05-26-13-33-10.bag.active",
39 "_2021-05-26-17-26-06.bag.active",
40 "_2021-05-26-19-45-45.bag.active",
41 "_2021-05-27-20-34-31.bag.active"]
42
43 # Logic to re-index bag files
44 for filename in files_to_reindex:
45 print("Reindexing " + str(filename))
46
47 # Issue command to re-index the bag file
48 # References example from https://github.com/bierschi/reindexBags
49 command = "rosbag reindex " + str(filename)
50 reindex_proc = subprocess.Popen(command, stdin=subprocess.PIPE, shell=True, cwd=source_folder,
51 executable='/bin/bash')
52 reindex_proc.wait()
53
54 # If a .orig.active file was created, then the .bag.active file was re-indexed
55 temp_file_name = str(filename[:-7]) + ".orig.active"
56 if (temp_file_name in os.listdir(source_folder)):
57
58 # Not removing the .bag.orig.active file for now, can delete manually afterwards in case the re-indexed file is corrupted
59 #os.remove(temp_file_name)
60
61 # Rename the re-indexed .bag.active to '.bag' only
62 os.rename(filename, filename[:-7])
63
64 # Print finished statement
65 print("Finished re-indexing " + str(filename))
66
67 return
68
69def main():
70 if len(sys.argv) < 2:
71 print("Need 1 arguments: process_bag.py <path to source folder with .bag.active files> ")
72 exit()
73
74 source_folder = sys.argv[1]
75
76 reindex_bag_files(source_folder)
77
78 return
79
80if __name__ == "__main__":
81 main()
def reindex_bag_files(source_folder)