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 <ville.voutilainen@qt.io>
This commit is contained in:
Assam Boudjelthia 2024-12-02 15:04:55 +02:00
parent df3f5d88d3
commit 2eeb35539c

View File

@ -10,8 +10,6 @@ import time
import signal import signal
import argparse import argparse
from datetime import datetime
def status(msg): def status(msg):
print(f"\n-- {msg}") print(f"\n-- {msg}")
@ -70,10 +68,10 @@ try:
serial = line.split('\t')[0] serial = line.split('\t')[0]
devices.append(serial) devices.append(serial)
if not devices: if not devices:
die(f"No devices are connected.") die("No devices are connected.")
if args.serial and not args.serial in devices: 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: except Exception as e:
die(f"Failed to check for running devices, received error: {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) signal.signal(signal.SIGINT, terminate_app)
# Show app's logs # Show app's logs
logcat_process = None;
try: try:
format_arg = "-v brief -v color" format_arg = "-v brief -v color"
time_arg = f"-T '{start_timestamp}'" time_arg = f"-T '{start_timestamp}'"
# escape char and color followed with fatal tag # 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}):'" pid_regex = f"-e '([ ]*{pid}):'"
logcat_cmd = f"{adb} shell \"logcat {time_arg} {format_arg} | grep {pid_regex} {fatal_regex}\"" logcat_cmd = f"{adb} shell \"logcat {time_arg} {format_arg} | grep {pid_regex} {fatal_regex}\""
logcat_process = subprocess.Popen(logcat_cmd, shell=True) logcat_process = subprocess.Popen(logcat_cmd, shell=True)
@ -199,7 +198,8 @@ try:
status(f"The app \"{package_name}\" has exited") status(f"The app \"{package_name}\" has exited")
break break
finally: finally:
logcat_process.terminate() if logcat_process:
logcat_process.terminate()
if interrupted: if interrupted:
try: try: