#! /usr/bin/env python import sys import subprocess from pathlib import Path import os # Import the 'os' module for path manipulation # --- Configuration --- # Add the names of the scripts you want to run in order. scripts_to_run = ['log_to_csv.py', 'log_add_diff.py', 'log_to_human.py', 'log_merge_nav_usbl.py'] # ------------------- def main(): """ Runs a list of scripts, modifying arguments for specific scripts as needed. """ # Get the absolute path of the directory where this launcher script is located. launcher_dir = Path(__file__).parent.resolve() # Get all arguments passed to this launcher. args = sys.argv[1:] if not args: print("āŒ Error: No arguments provided.") print(f"Usage: python {sys.argv[0]} ARGUMENT1 ARGUMENT2 ...") sys.exit(1) print(f"šŸš€ Starting launcher with arguments: {', '.join(args)}\n") # Iterate through each script defined in the list. for script_name in scripts_to_run: # Construct the full, absolute path to the target script. script_path = launcher_dir / script_name # For each script, iterate through each argument provided. for arg in args: # This is our new logic block # --------------------------------------------------------------- arg_for_script = arg # Default to the original argument if script_name == 'log_add_diff.py' and arg.lower().endswith('.csv'): # Split the argument into the part before the extension and the extension itself basename, extension = os.path.splitext(arg) # Create the new, modified argument arg_for_script = f"{basename}_csv{extension}" # --------------------------------------------------------------- # The command now uses the potentially modified argument. command = ['python', str(script_path), arg_for_script] print(f"ā–¶ļø Running: {' '.join(command)}") try: subprocess.run(command, check=True, text=True) except FileNotFoundError: print(f"āŒ Error: Script '{script_path}' not found.") sys.exit(1) except subprocess.CalledProcessError as e: print(f"āŒ Error running '{' '.join(command)}'. Returned code: {e.returncode}") sys.exit(1) print("\nāœ… All scripts completed successfully!") if __name__ == "__main__": main()