From ac9d27b853596d0146067d6d925bdb4ae8e0e3ce Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:04:01 -0600 Subject: [PATCH] Update launcher.py --- launcher.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/launcher.py b/launcher.py index 832c92a..5223ca7 100644 --- a/launcher.py +++ b/launcher.py @@ -112,17 +112,14 @@ def main(): args = parser.parse_args() # Get the branch name from the BRANCH environment variable or default to 'main' - branch_name = args.branch or os.getenv("BRANCH", "main") - + branch_name = args.branch if args.branch != 'main' else os.getenv('BRANCH', 'main') # Determine the script name based on the branch name script_name = f"-{branch_name}.py" if branch_name != "main" else ".py" - - # Check if the script exists or if the UPDATE environment variable is set to True - if not os.path.exists(script_name) or convert_to_bool(os.getenv("UPDATE", "False")): - print(f"Downloading launcher.py from GitHub branch {branch_name}...") + # Check we need to update the launcher + + if args.launcher_update or convert_to_bool(os.getenv('LAUNCHER_UPDATE')): + print(f"Updating launcher.py from GitHub branch {branch_name}...") download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/{branch_name}/launcher.py", f'launcher{script_name}') - else: - print("File exists and UPDATE is not set to True, skipping download.") # Prepare the arguments to exclude update triggers excluded_args = ['--launcher-update', '-l'] @@ -130,9 +127,9 @@ def main(): if branch_name == 'main' and args.launcher_update: print("Running launcher.py for the 'main' branch.") os.execl(sys.executable, sys.executable, "launcher.py", *new_args) - else: + elif args.launcher_update: print(f"Running launcher-{branch_name}.py for the '{branch_name}' branch.") - os.execl(sys.executable, sys.executable, f"launcher-{branch_name}.py", *new_args) + os.execl(sys.executable, sys.executable, f"launcher{script_name}", *new_args) # Set environment variables based on the parsed arguments os.environ['DEBUG'] = str(args.debug) @@ -152,15 +149,15 @@ def main(): install_packages_from_requirements(requirements_file) # Check if the script exists or if the UPDATE environment variable is set to True - if not os.path.exists(script_name) or convert_to_bool(os.getenv("UPDATE", "False")): + if not os.path.exists(f'subgen{script_name}') or args.update or convert_to_bool(os.getenv('UPDATE')): print(f"Downloading subgen.py from GitHub branch {branch_name}...") download_from_github(f"https://raw.githubusercontent.com/McCloudS/subgen/{branch_name}/subgen.py", f'subgen{script_name}') else: - print("File exists and UPDATE is not set to True, skipping download.") + print("subgen.py exists and UPDATE is set to False, skipping download.") if not args.exit_early: if branch_name != 'main': - subprocess.run([f'{python_cmd}', '-u', f'subgen-{branch_name}.py'], check=True) + subprocess.run([f'{python_cmd}', '-u', f'subgen{script_name}'], check=True) else: subprocess.run([f'{python_cmd}', '-u', 'subgen.py'], check=True) else: