From 2eeb35539c4ab0cf1f4d1d15cb974b4d6b7ff720 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Mon, 2 Dec 2024 15:04:55 +0200 Subject: [PATCH] Android: fix warnings in runner script Remove f-format prints that uses no placeholders. Check if logcat_process is initialized before accessing it. Remove unused import. Pick-to: 6.8 Change-Id: I72cc34666460300b3b6b58174b3c7cefac27da7d Reviewed-by: Ville Voutilainen --- libexec/qt-android-runner.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libexec/qt-android-runner.py b/libexec/qt-android-runner.py index dbddfcf58c4..20ae3b0d098 100644 --- a/libexec/qt-android-runner.py +++ b/libexec/qt-android-runner.py @@ -10,8 +10,6 @@ import time import signal import argparse -from datetime import datetime - def status(msg): print(f"\n-- {msg}") @@ -70,10 +68,10 @@ try: serial = line.split('\t')[0] devices.append(serial) if not devices: - die(f"No devices are connected.") + die("No devices are connected.") if args.serial and not args.serial in devices: - die(f"No connected devices with the specified serial number.") + die("No connected devices with the specified serial number.") except Exception as e: die(f"Failed to check for running devices, received error: {e}") @@ -174,11 +172,12 @@ def terminate_app(signum, frame): signal.signal(signal.SIGINT, terminate_app) # Show app's logs +logcat_process = None; try: format_arg = "-v brief -v color" time_arg = f"-T '{start_timestamp}'" # escape char and color followed with fatal tag - fatal_regex = f"-e $'^\x1b\\[[0-9]*mF/'" + fatal_regex = "-e $'^\x1b\\[[0-9]*mF/'" pid_regex = f"-e '([ ]*{pid}):'" logcat_cmd = f"{adb} shell \"logcat {time_arg} {format_arg} | grep {pid_regex} {fatal_regex}\"" logcat_process = subprocess.Popen(logcat_cmd, shell=True) @@ -199,7 +198,8 @@ try: status(f"The app \"{package_name}\" has exited") break finally: - logcat_process.terminate() + if logcat_process: + logcat_process.terminate() if interrupted: try: