Add 'quiet' option to loading-related functions
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
This commit is contained in:
parent
9304d1b30e
commit
28b61587cf
1 changed files with 20 additions and 5 deletions
|
@ -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,10 +61,14 @@ 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:
|
||||||
print(f'found converted file: {prospective_converted_file}')
|
if not quiet:
|
||||||
|
print(f'found converted file: {prospective_converted_file}')
|
||||||
return prospective_converted_file, False
|
return prospective_converted_file, False
|
||||||
else:
|
else:
|
||||||
# Check if it is a trace directory
|
# Check if it is a trace directory
|
||||||
|
@ -81,7 +87,8 @@ 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
|
||||||
print(f'found converted file but will re-create it: {converted_file_path}')
|
if not quiet:
|
||||||
|
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:
|
||||||
# Simplest use-case: given path is an existing converted file
|
# Simplest use-case: given path is an existing converted file
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue