-
Notifications
You must be signed in to change notification settings - Fork 10
/
launcher.py
51 lines (40 loc) · 1.59 KB
/
launcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import subprocess
import platform
import os
import sys
# from dl4miceverywhere import windows_launch
# Function to determine resource path
def resource_path(relative_path):
"""Get absolute path to resource, works for dev and for PyInstaller"""
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
# Determine the OS
os_name = platform.system()
# Define the launch command based on the OS
if os_name == "Windows":
# windows_launch.main()
launch_command = resource_path("Windows_launch.bat")
elif os_name == "Darwin": # Darwin is the underlying OS for macOS
launch_command = resource_path("MacOS_launch.command")
elif os_name == "Linux":
launch_command = resource_path("Linux_launch.sh")
else:
raise ValueError("Unsupported operating system")
# Append './' if necessary, depending on your specific launch commands
# For example, if your script needs to be executed from its directory
# if os_name in ['Linux', 'Windows']: # Adjust based on your requirement
# Check if the launch file exists
if not os.path.exists(launch_command):
raise FileNotFoundError(f"{launch_command} does not exist")
# launch_command += " ./"
# Execute the launch command
try:
print(f"Executing {launch_command} on {os_name}")
result = subprocess.run(launch_command, check=True, shell=True)
print("Execution successful.")
except subprocess.CalledProcessError as e:
print(f"An error occurred while executing {launch_command}: {e}")