iterate through all rigctld binaries

This commit is contained in:
DJ2LS 2024-02-22 10:49:30 +01:00
parent 8ccff438d0
commit e284a58db9
2 changed files with 29 additions and 14 deletions

View file

@ -713,15 +713,16 @@ def get_flag(byte, flag_name, flag_dict):
return get_bit(byte, position)
def find_binary_path(binary_name="rigctld", search_system_wide=False):
def find_binary_paths(binary_name="rigctld", search_system_wide=False):
"""
Search for a binary within the current working directory and its subdirectories.
Optionally, check system-wide locations and PATH environment variable if not found.
Search for a binary within the current working directory, its subdirectories, and optionally,
system-wide locations and the PATH environment variable.
:param binary_name: The base name of the binary to search for, without extension.
:param search_system_wide: Boolean flag to enable or disable system-wide search.
:return: The full path to the binary if found, otherwise None.
:return: A list of full paths to the binary if found, otherwise an empty list.
"""
binary_paths = [] # Initialize an empty list to store found paths
# Adjust binary name for Windows
if platform.system() == 'Windows':
binary_name += ".exe"
@ -730,7 +731,7 @@ def find_binary_path(binary_name="rigctld", search_system_wide=False):
root_path = os.getcwd()
for dirpath, dirnames, filenames in os.walk(root_path):
if binary_name in filenames:
return os.path.join(dirpath, binary_name)
binary_paths.append(os.path.join(dirpath, binary_name))
# If system-wide search is enabled, look in system locations and PATH
if search_system_wide:
@ -739,13 +740,16 @@ def find_binary_path(binary_name="rigctld", search_system_wide=False):
if platform.system() != 'Windows':
system_paths.extend(['/usr/bin', '/usr/local/bin', '/bin'])
else:
system_paths.extend(glob.glob("C:\\Program Files\\Hamlib*\\bin"))
system_paths.extend(glob.glob("C:\\Program Files (x86)\\Hamlib*\\bin"))
system_paths.extend(glob.glob("C:\\Program Files\\Hamlib*\\bin"))
system_paths.extend(glob.glob("C:\\Program Files (x86)\\Hamlib*\\bin"))
for path in system_paths:
potential_path = os.path.join(path, binary_name)
if os.path.isfile(potential_path):
return potential_path
binary_paths.append(potential_path)
return binary_paths
def kill_and_execute(binary_path, additional_args=None):

View file

@ -260,15 +260,26 @@ class radio:
def start_service(self):
binary_name = "rigctld"
binary_path = helpers.find_binary_path(binary_name, search_system_wide=True)
binary_paths = helpers.find_binary_paths(binary_name, search_system_wide=True)
additional_args = self.format_rigctld_args()
if binary_path:
self.log.info(f"Rigctld binary found at: {binary_path}")
helpers.kill_and_execute(binary_path, additional_args)
self.log.info(f"Executed rigctld...")
if binary_paths:
for binary_path in binary_paths:
try:
self.log.info(f"Attempting to start rigctld using binary found at: {binary_path}")
helpers.kill_and_execute(binary_path, additional_args)
self.log.info("Successfully executed rigctld.")
break # Exit the loop after successful execution
except Exception as e:
pass
# let's keep this hidden for the user to avoid confusion
# self.log.warning(f"Failed to start rigctld with binary at {binary_path}: {e}")
else:
self.log.warning("Failed to start rigctld with all found binaries.", binaries=binary_paths)
else:
self.log.warning("Rigctld binary not found.")
def format_rigctld_args(self):
config = self.config['RADIO'] # Accessing the 'RADIO' section of the INI file
config_rigctld = self.config['RIGCTLD'] # Accessing the 'RIGCTLD' section of the INI file for custom args