1. import os
  2. import subprocess
  3. import sys
  4. import platform
  5. def bootstrap_runtime(script_path, version="latest"):
  6. """
  7. Bootstraps a script with a runtime environment, supporting older versions.
  8. Development-only functionality.
  9. """
  10. os_name = platform.system()
  11. if os_name == "Windows":
  12. # Windows bootstrap
  13. if version == "latest":
  14. runtime_script = "bootstrap_windows_latest.bat" #example
  15. else:
  16. runtime_script = f"bootstrap_windows_{version}.bat"
  17. if not os.path.exists(runtime_script):
  18. print(f"Error: {runtime_script} not found.")
  19. return False
  20. try:
  21. subprocess.run([runtime_script, script_path], shell=True, check=True)
  22. except subprocess.CalledProcessError as e:
  23. print(f"Error running bootstrap script: {e}")
  24. return False
  25. elif os_name == "Linux" or os_name == "Darwin": #Darwin is macOS
  26. # Linux/macOS bootstrap
  27. if version == "latest":
  28. runtime_script = "bootstrap_linux_latest.sh" #example
  29. else:
  30. runtime_script = f"bootstrap_linux_{version}.sh"
  31. if not os.path.exists(runtime_script):
  32. print(f"Error: {runtime_script} not found.")
  33. return False
  34. try:
  35. subprocess.run(["bash", runtime_script, script_path], check=True)
  36. except subprocess.CalledProcessError as e:
  37. print(f"Error running bootstrap script: {e}")
  38. return False
  39. else:
  40. print(f"Unsupported operating system: {os_name}")
  41. return False
  42. return True
  43. if __name__ == "__main__":
  44. if len(sys.argv) < 2:
  45. print("Usage: python bootstrap.py <script_path> [version]")
  46. sys.exit(1)
  47. script_path = sys.argv[1]
  48. version = sys.argv[2] if len(sys.argv) > 2 else "latest"
  49. if bootstrap_runtime(script_path, version):
  50. print(f"Successfully bootstrapped {script_path} with version {version}")
  51. else:
  52. print(f"Failed to bootstrap {script_path}")

Add your comment