-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·44 lines (41 loc) · 1.67 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·44 lines (41 loc) · 1.67 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
#!/usr/bin/env python3
import os
import sys
import subprocess
import re
import glob
import csv
def ask_yes_no(question):
while True:
answer = input(question + " (y/n): ").lower()
if answer in ['y', 'n']:
return answer == 'y'
else:
print("Please enter y or n.")
def main(platform):
required_list = []
cmd_list = []
with open(f"packages-{platform}.csv", 'r') as f:
reader = list(csv.reader(f))
for row in reader[1:]:
if ask_yes_no(f"you need {row[0]}?"):
required_list.append(row[0])
cmd_list.append(row[1] if row[1] != "./setup" else f"./{row[0]}/setup-{platform}.sh")
if len(cmd_list) > 0:
print("The chosen packages are:")
print("\n".join([f" {name}" for name in required_list]))
if ask_yes_no("Are you sure want to install these packages?"):
process = subprocess.Popen("bash", stdin=subprocess.PIPE)
process.communicate(input="\n".join(cmd_list).encode())
if __name__ == "__main__":
script_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(script_dir)
# `packages-[platform name].csv`があれば[platform name]をサポート済みと認識
supported_platform_list = [re.sub("packages-(.*).csv", "\\1", list_path) for list_path in glob.glob("packages-*.csv")]
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} [platform]", file=sys.stderr)
print(f"Supported platforms:", file=sys.stderr)
print("\n".join([f" {platform}" for platform in supported_platform_list]), file=sys.stderr)
exit(1)
elif sys.argv[1] in supported_platform_list:
main(sys.argv[1])