forked from colomoto/pyMaBoSS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaboss_setup_experimental.py
More file actions
88 lines (69 loc) · 2.59 KB
/
Copy pathmaboss_setup_experimental.py
File metadata and controls
88 lines (69 loc) · 2.59 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import platform
import os
import stat
import shutil
import sys
import zipfile
from urllib.request import urlretrieve
def get_url(os_type, arch):
base_url = "https://github.com/sysbio-curie/MaBoSS/releases/latest/download/"
if os_type == 'linux':
return base_url + "MaBoSS-linux64.zip"
elif os_type == 'darwin':
if arch == 'arm64':
return base_url + "MaBoSS-osx-arm64.zip"
elif arch == 'x86_64':
return base_url + "MaBoSS-osx64.zip"
else:
print(f"Unsupported architecture: {os_type} : {arch}")
sys.exit(1)
elif os_type.startswith('win'):
return base_url + "MaBoSS-win64.zip"
else:
print(f"Unsupported OS: {os_type}")
sys.exit(1)
def ensure_directory_exists(path):
"""Create directory if it does not exist."""
if not os.path.exists(path):
os.makedirs(path)
def download_and_extract(url, dest_path):
"""Download and extract a package from a URL."""
# Ensure the destination directory exists
ensure_directory_exists(dest_path)
filename = url.split('/')[-1]
file_path = os.path.join(dest_path, filename)
# Download the file
print(f"Downloading {filename} from {url}...")
urlretrieve(url, file_path)
# Extract the file
print(f"Extracting {filename}...")
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall(dest_path)
for item in os.listdir(dest_path):
st = os.stat(os.path.join(dest_path, item))
os.chmod(os.path.join(dest_path, item), st.st_mode | stat.S_IEXEC)
# Clean up
os.remove(file_path)
print(f"{filename} installed successfully.\n")
def is_installed(progname):
return shutil.which(progname) is not None
def get_bin_path(os_type):
if platform.system() == "Windows":
bin_path = os.path.join(os.getenv("APPDATA"), "maboss", "bin")
else:
bin_path = os.path.join(os.path.expanduser("~"), ".local", "share", "maboss", "bin")
if not os.path.exists(bin_path):
os.makedirs(bin_path)
if platform.system() == "Windows":
os.environ["PATH"] = "%s;%s" % (bin_path, os.environ["PATH"])
else:
os.environ["PATH"] = "%s:%s" % (bin_path, os.environ["PATH"])
return bin_path
os_type = platform.system().lower()
arch = platform.machine().lower()
url = get_url(os_type, arch)
dest_path = get_bin_path(os_type)
if not is_installed("MaBoSS"):
download_and_extract(url, dest_path)
print("MaBoSS is installed and ready to use.")
print(shutil.which("MaBoSS" if platform.system() != "Windows" else "MaBoSS.exe"))