Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to close files when finished with them #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion rosbag_metadata/metadata_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def write_metadata_file(self, filename, metadata_string, overwrite_existing=Fals
return None
with open(filename,'w') as f:
f.write(metadata_string)
f.close()
return (filename, )

def write_metadata(self, filename, metadata, overwrite_existing=False):
Expand Down Expand Up @@ -108,6 +109,7 @@ def inject_to_bag(self, bagfile_name, metadata):
else:
t = rospy.Time(bag.get_end_time())
bag.write(self.default_topic, metadata_msg, t)
bag.close()


def find_split_files(self, bagfile_name):
Expand All @@ -121,6 +123,7 @@ def extract_from_bag(self, bagfile_name, use_yaml=True):
if msg_topic == self.default_topic:
found = True
break
bag.close()
if found:
if use_yaml: # Try to parse data as yaml unless told not to
try:
Expand Down Expand Up @@ -153,6 +156,7 @@ def extract_from_file(self, filename):
# try reading the file
with open(filename, 'r') as f:
data = f.read()
f.close()
return (filename, yaml.load(data))
return None

Expand Down Expand Up @@ -181,7 +185,9 @@ def extract(self, filename, use_yaml=True, find_all=False):

def get_info(self, bagfile_name, freq=True):
b = rosbag.Bag(bagfile_name, 'r',skip_index=not freq)
return yaml.load(b._get_yaml_info())
yaml_info = b._get_yaml_info()
b.close()
return yaml.load(yaml_info)


def get_full_info(self, bagfile_name, freq=True):
Expand Down