Merge branch '26-validate-conversion-processing-paths-and-handle-exceptions-better' into 'master'

Validate conversion/processing paths

Closes #26

See merge request micro-ROS/ros_tracing/tracetools_analysis!52
This commit is contained in:
Christophe Bedard 2020-03-07 22:04:07 +00:00
commit 936fc31dca
2 changed files with 14 additions and 1 deletions

View file

@ -17,6 +17,7 @@
import argparse import argparse
import os import os
import sys
import time import time
from typing import Optional from typing import Optional
@ -58,8 +59,13 @@ def convert(
:param trace_directory: the path to the trace directory to import :param trace_directory: the path to the trace directory to import
:param outout_file_name: the name of the output file :param outout_file_name: the name of the output file
""" """
trace_directory = os.path.expanduser(trace_directory)
if not os.path.isdir(trace_directory):
print(f'trace directory does not exist: {trace_directory}', file=sys.stderr)
return 1
print(f'converting trace directory: {trace_directory}') print(f'converting trace directory: {trace_directory}')
output_file_path = os.path.join(os.path.expanduser(trace_directory), output_file_name) output_file_path = os.path.join(trace_directory, output_file_name)
start_time = time.time() start_time = time.time()
count = ctf.convert(trace_directory, output_file_path) count = ctf.convert(trace_directory, output_file_path)
time_diff = time.time() - start_time time_diff = time.time() - start_time

View file

@ -16,6 +16,8 @@
"""Entrypoint/script to process events from a converted file to build a ROS model.""" """Entrypoint/script to process events from a converted file to build a ROS model."""
import argparse import argparse
import os
import sys
import time import time
from typing import Optional from typing import Optional
@ -60,6 +62,11 @@ def process(
:param force_conversion: whether to re-creating converted file even if it is found :param force_conversion: whether to re-creating converted file even if it is found
:param hide_results: whether to hide results and not print them :param hide_results: whether to hide results and not print them
""" """
input_path = os.path.expanduser(input_path)
if not os.path.exists(input_path):
print(f'input path does not exist: {input_path}', file=sys.stderr)
return 1
start_time = time.time() start_time = time.time()
events = load_file(input_path, do_convert_if_needed=True, force_conversion=force_conversion) events = load_file(input_path, do_convert_if_needed=True, force_conversion=force_conversion)