From 00a7015527f251a64dffc2b151662a10e4cf03d1 Mon Sep 17 00:00:00 2001 From: StarrryNight Date: Sun, 8 Feb 2026 17:16:17 -0800 Subject: [PATCH 1/4] finish implementation --- .../binary_context_managers/full_system.py | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/src/software/thunderscope/binary_context_managers/full_system.py b/src/software/thunderscope/binary_context_managers/full_system.py index 8e8abc4e48..d7f0d540ba 100644 --- a/src/software/thunderscope/binary_context_managers/full_system.py +++ b/src/software/thunderscope/binary_context_managers/full_system.py @@ -2,9 +2,11 @@ import logging import os +import subprocess import threading import time from subprocess import Popen, TimeoutExpired +import re from software.py_constants import * from software.python_bindings import * @@ -53,6 +55,26 @@ def __init__( self.log_level = log_level self.thread = threading.Thread(target=self.__restart__, daemon=True) + def discover_supported_flags(self, path_to_binary: str) -> set[str]: + """Discover what binary flags are supported by provided binary + + :param path_to_binary path to specific binary + :return a set of supported flags + """ + try: + result = subprocess.run( + [path_to_binary, "--help"], + capture_output=True, + text=True, + timeout=3 + ) + flags = re.findall(r'--(\w+)', result.stdout) + return set(flags) + except (subprocess.TimeoutExpired, FileNotFoundError, PermissionError): + return set() + + + def __enter__(self) -> FullSystem: """Enter the full_system context manager. @@ -69,13 +91,28 @@ def __enter__(self) -> FullSystem: except: pass - self.full_system = "{} --runtime_dir={} {} {} --log_level={}".format( - self.path_to_binary, - self.full_system_runtime_dir, - "--friendly_colour_yellow" if self.friendly_colour_yellow else "", - "--ci" if not self.running_in_realtime else "", - self.log_level.value, - ) + supported_flags = self.discover_supported_flags(self.path_to_binary) + + cmd_parts = [self.path_to_binary] + # runtime_dir is always required (core functionality) + cmd_parts.append("--runtime_dir={}".format(self.full_system_runtime_dir)) + + # Optional flags - only add if supported + if self.friendly_colour_yellow and "friendly_colour_yellow" in supported_flags: + cmd_parts.append("--friendly_colour_yellow") + if not self.running_in_realtime and "ci" in supported_flags: + cmd_parts.append("--ci") + if "log_level" in supported_flags: + cmd_parts.append("--log_level={}".format(self.log_level.value)) + + # Log supported flags info based on importance level + if supported_flags: + logging.debug("Binary support flags: {}".format(supported_flags)) + else: + logging.warning("Could not discovery flags for path: '{}'. Continuing...".format(self.path_to_binary)) + + + self.full_system = " ".join(cmd_parts) if self.should_run_under_sudo: if not is_cmd_running( @@ -152,7 +189,7 @@ def __restart__(self) -> None: "--runtime_dir={}".format(self.full_system_runtime_dir), ] ): - self.full_system_proc = Popen(self.full_system.split(" ")) + relf.full_system_proc = Popen(self.full_system.split(" ")) logging.info("FullSystem has restarted.") time.sleep(1) From 1a9ec663f5d460ba5f062270de63afc7392c88f2 Mon Sep 17 00:00:00 2001 From: StarrryNight Date: Sun, 8 Feb 2026 17:23:24 -0800 Subject: [PATCH 2/4] fix typo --- .../thunderscope/binary_context_managers/full_system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/software/thunderscope/binary_context_managers/full_system.py b/src/software/thunderscope/binary_context_managers/full_system.py index d7f0d540ba..fca8ea986f 100644 --- a/src/software/thunderscope/binary_context_managers/full_system.py +++ b/src/software/thunderscope/binary_context_managers/full_system.py @@ -189,7 +189,7 @@ def __restart__(self) -> None: "--runtime_dir={}".format(self.full_system_runtime_dir), ] ): - relf.full_system_proc = Popen(self.full_system.split(" ")) + self.full_system_proc = Popen(self.full_system.split(" ")) logging.info("FullSystem has restarted.") time.sleep(1) From 12c6e85ec37dfdaed60f5060be76b89a4433ce8d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 9 Feb 2026 01:31:41 +0000 Subject: [PATCH 3/4] [pre-commit.ci lite] apply automatic fixes --- .../binary_context_managers/full_system.py | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/software/thunderscope/binary_context_managers/full_system.py b/src/software/thunderscope/binary_context_managers/full_system.py index fca8ea986f..b11758584f 100644 --- a/src/software/thunderscope/binary_context_managers/full_system.py +++ b/src/software/thunderscope/binary_context_managers/full_system.py @@ -62,18 +62,13 @@ def discover_supported_flags(self, path_to_binary: str) -> set[str]: :return a set of supported flags """ try: - result = subprocess.run( - [path_to_binary, "--help"], - capture_output=True, - text=True, - timeout=3 - ) - flags = re.findall(r'--(\w+)', result.stdout) - return set(flags) + result = subprocess.run( + [path_to_binary, "--help"], capture_output=True, text=True, timeout=3 + ) + flags = re.findall(r"--(\w+)", result.stdout) + return set(flags) except (subprocess.TimeoutExpired, FileNotFoundError, PermissionError): - return set() - - + return set() def __enter__(self) -> FullSystem: """Enter the full_system context manager. @@ -94,23 +89,26 @@ def __enter__(self) -> FullSystem: supported_flags = self.discover_supported_flags(self.path_to_binary) cmd_parts = [self.path_to_binary] - # runtime_dir is always required (core functionality) + # runtime_dir is always required (core functionality) cmd_parts.append("--runtime_dir={}".format(self.full_system_runtime_dir)) - - # Optional flags - only add if supported - if self.friendly_colour_yellow and "friendly_colour_yellow" in supported_flags: + + # Optional flags - only add if supported + if self.friendly_colour_yellow and "friendly_colour_yellow" in supported_flags: cmd_parts.append("--friendly_colour_yellow") - if not self.running_in_realtime and "ci" in supported_flags: - cmd_parts.append("--ci") - if "log_level" in supported_flags: + if not self.running_in_realtime and "ci" in supported_flags: + cmd_parts.append("--ci") + if "log_level" in supported_flags: cmd_parts.append("--log_level={}".format(self.log_level.value)) - + # Log supported flags info based on importance level if supported_flags: logging.debug("Binary support flags: {}".format(supported_flags)) else: - logging.warning("Could not discovery flags for path: '{}'. Continuing...".format(self.path_to_binary)) - + logging.warning( + "Could not discovery flags for path: '{}'. Continuing...".format( + self.path_to_binary + ) + ) self.full_system = " ".join(cmd_parts) From b745ad636ad7dcc3a01a58f9937dc537a13d9a92 Mon Sep 17 00:00:00 2001 From: Samuel <92961466+StarrryNight@users.noreply.github.com> Date: Tue, 10 Feb 2026 10:59:56 -0800 Subject: [PATCH 4/4] typo: discovery --> discover --- .../thunderscope/binary_context_managers/full_system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/software/thunderscope/binary_context_managers/full_system.py b/src/software/thunderscope/binary_context_managers/full_system.py index b11758584f..a42d13fb81 100644 --- a/src/software/thunderscope/binary_context_managers/full_system.py +++ b/src/software/thunderscope/binary_context_managers/full_system.py @@ -105,7 +105,7 @@ def __enter__(self) -> FullSystem: logging.debug("Binary support flags: {}".format(supported_flags)) else: logging.warning( - "Could not discovery flags for path: '{}'. Continuing...".format( + "Could not discover flags for path: '{}'. Continuing...".format( self.path_to_binary ) )