import os
import subprocess
import sys
import platform
def bootstrap_runtime(script_path, version="latest"):
"""
Bootstraps a script with a runtime environment, supporting older versions.
Development-only functionality.
"""
os_name = platform.system()
if os_name == "Windows":
# Windows bootstrap
if version == "latest":
runtime_script = "bootstrap_windows_latest.bat" #example
else:
runtime_script = f"bootstrap_windows_{version}.bat"
if not os.path.exists(runtime_script):
print(f"Error: {runtime_script} not found.")
return False
try:
subprocess.run([runtime_script, script_path], shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Error running bootstrap script: {e}")
return False
elif os_name == "Linux" or os_name == "Darwin": #Darwin is macOS
# Linux/macOS bootstrap
if version == "latest":
runtime_script = "bootstrap_linux_latest.sh" #example
else:
runtime_script = f"bootstrap_linux_{version}.sh"
if not os.path.exists(runtime_script):
print(f"Error: {runtime_script} not found.")
return False
try:
subprocess.run(["bash", runtime_script, script_path], check=True)
except subprocess.CalledProcessError as e:
print(f"Error running bootstrap script: {e}")
return False
else:
print(f"Unsupported operating system: {os_name}")
return False
return True
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python bootstrap.py <script_path> [version]")
sys.exit(1)
script_path = sys.argv[1]
version = sys.argv[2] if len(sys.argv) > 2 else "latest"
if bootstrap_runtime(script_path, version):
print(f"Successfully bootstrapped {script_path} with version {version}")
else:
print(f"Failed to bootstrap {script_path}")
Add your comment