From a915fa55f0bb10950e026364fc35bf7af890d152 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 14 May 2020 10:25:30 -0400 Subject: [PATCH] Make sure platform is Linux before checking if LTTng is installed Signed-off-by: Christophe Bedard --- .../tracetools_trace/tools/lttng.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tracetools_trace/tracetools_trace/tools/lttng.py b/tracetools_trace/tracetools_trace/tools/lttng.py index 4a75b07..31a7d93 100644 --- a/tracetools_trace/tracetools_trace/tools/lttng.py +++ b/tracetools_trace/tracetools_trace/tools/lttng.py @@ -14,6 +14,7 @@ """Interface for tracing with LTTng.""" +import platform import subprocess import sys from typing import List @@ -89,10 +90,19 @@ def is_lttng_installed() -> bool: """ Check if LTTng is installed. - Simply checks for the 'lttng' command. + It first checks if the OS can support LTTng. + If so, it then simply checks if LTTng is installed using the 'lttng' command. :return: True if it is installed, False otherwise """ + message_doc = ( + 'Cannot trace. See documentation at: ' + 'https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing' + ) + system = platform.system() + if 'Linux' != system: + print(f"System '{system}' does not support LTTng.\n{message_doc}", file=sys.stderr) + return False try: process = subprocess.Popen( ['lttng', '--version'], @@ -104,12 +114,5 @@ def is_lttng_installed() -> bool: raise RuntimeError(stderr.decode()) return True except Exception as e: - print( - ( - f'LTTng not found: {e}\n' - 'Cannot trace. See documentation at: ' - 'https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing' - ), - file=sys.stderr, - ) + print(f'LTTng not found: {e}\n{message_doc}', file=sys.stderr) return False