Add 'quiet' option to loading-related functions

Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
This commit is contained in:
Christophe Bedard 2020-05-23 10:15:15 -04:00
parent 9304d1b30e
commit 28b61587cf

View file

@ -31,6 +31,7 @@ from ..convert import DEFAULT_CONVERT_FILE_NAME
def inspect_input_path( def inspect_input_path(
input_path: str, input_path: str,
force_conversion: bool = False, force_conversion: bool = False,
quiet: bool = False,
) -> Tuple[Optional[str], bool]: ) -> Tuple[Optional[str], bool]:
""" """
Check input path for a converted file or a trace directory. Check input path for a converted file or a trace directory.
@ -43,6 +44,7 @@ def inspect_input_path(
:param input_path: the path to a converted file or trace directory :param input_path: the path to a converted file or trace directory
:param force_conversion: whether to re-create converted file even if it is found :param force_conversion: whether to re-create converted file even if it is found
:param quiet: whether to not print any normal output
:return: :return:
the path to a converted file (or `None` if could not find), the path to a converted file (or `None` if could not find),
`True` if the given converted file should be (re-)created, `False` otherwise `True` if the given converted file should be (re-)created, `False` otherwise
@ -59,9 +61,13 @@ def inspect_input_path(
# Use that as the converted input file # Use that as the converted input file
converted_file_path = prospective_converted_file converted_file_path = prospective_converted_file
if force_conversion: if force_conversion:
print(f'found converted file but will re-create it: {prospective_converted_file}') if not quiet:
print(
f'found converted file but will re-create it: {prospective_converted_file}'
)
return prospective_converted_file, True return prospective_converted_file, True
else: else:
if not quiet:
print(f'found converted file: {prospective_converted_file}') print(f'found converted file: {prospective_converted_file}')
return prospective_converted_file, False return prospective_converted_file, False
else: else:
@ -81,6 +87,7 @@ def inspect_input_path(
converted_file_path = input_path converted_file_path = input_path
if force_conversion: if force_conversion:
# It's a file, but re-create it anyway # It's a file, but re-create it anyway
if not quiet:
print(f'found converted file but will re-create it: {converted_file_path}') print(f'found converted file but will re-create it: {converted_file_path}')
return converted_file_path, True return converted_file_path, True
else: else:
@ -92,15 +99,21 @@ def inspect_input_path(
def convert_if_needed( def convert_if_needed(
input_path: str, input_path: str,
force_conversion: bool = False, force_conversion: bool = False,
quiet: bool = False,
) -> Optional[str]: ) -> Optional[str]:
""" """
Inspect input path and convert trace directory to file if necessary. Inspect input path and convert trace directory to file if necessary.
:param input_path: the path to a converted file or trace directory :param input_path: the path to a converted file or trace directory
:param force_conversion: whether to re-create converted file even if it is found :param force_conversion: whether to re-create converted file even if it is found
:param quiet: whether to not print any output
:return: the path to the converted file, or `None` if it failed :return: the path to the converted file, or `None` if it failed
""" """
converted_file_path, create_converted_file = inspect_input_path(input_path, force_conversion) converted_file_path, create_converted_file = inspect_input_path(
input_path,
force_conversion,
quiet,
)
if converted_file_path is None: if converted_file_path is None:
return None return None
@ -118,6 +131,7 @@ def load_file(
input_path: str, input_path: str,
do_convert_if_needed: bool = True, do_convert_if_needed: bool = True,
force_conversion: bool = False, force_conversion: bool = False,
quiet: bool = False,
) -> List[Dict]: ) -> List[Dict]:
""" """
Load file containing converted trace events. Load file containing converted trace events.
@ -125,10 +139,11 @@ def load_file(
:param input_path: the path to a converted file or trace directory :param input_path: the path to a converted file or trace directory
:param do_convert_if_needed: whether to create the converted file if needed (else, let it fail) :param do_convert_if_needed: whether to create the converted file if needed (else, let it fail)
:param force_conversion: whether to re-create converted file even if it is found :param force_conversion: whether to re-create converted file even if it is found
:param quiet: whether to not print any output
:return: the list of events read from the file :return: the list of events read from the file
""" """
if do_convert_if_needed or force_conversion: if do_convert_if_needed or force_conversion:
file_path = convert_if_needed(input_path, force_conversion) file_path = convert_if_needed(input_path, force_conversion, quiet)
else: else:
file_path = input_path file_path = input_path