This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.py
61 lines (48 loc) · 1.9 KB
/
install.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
52
53
54
55
56
57
58
59
60
61
#!/bin/python3
# Add aliases to .bash_aliases and .zhsrc
import os
import platform
from colorama import Fore
def windowsError():
print(f"{Fore.RED}ERROR: Running Localtest on Windows is not recommended "
"for use with CSE work")
print(f"{Fore.RESET}Continuing to use it may produce different output "
"from your programs compared to CSE systems")
print("Please install Windows Subsystem for Linux using the linked"
"instructions:")
print("https://docs.microsoft.com/en-us/windows/wsl/install-win10")
exit(1)
def quotePath(path: str):
# Return path with escaped quote marks around each token with a space
return '/'.join([r"'"+s+r"'" if ' ' in s else s
for s in path.split('/')])
def install():
print("Installing localtest...")
sys = platform.system()
# Linux
if sys == "Linux":
print("System: Linux")
# MacOS
elif sys == "Darwin":
print("System: MacOS")
elif sys == "Windows":
windowsError()
# Yuck
alias = r'alias \"localtest=\\\"' + quotePath(os.path.join(os.path.dirname(__file__), "localtest.py")) + r'\\\"\"'
# Print decoded version of what we generated
print(f"Generated alias:{Fore.CYAN} ", end='')
print(alias.encode('utf-8').decode('unicode_escape'))
print(f"{Fore.RESET}", end='')
# Look for zsh config
zsh_path = os.path.join(os.path.expanduser('~'), '.zshrc')
if os.path.exists(zsh_path):
print("Adding to ZSH...")
os.system(f'sudo sh -c "echo {alias} >> {quotePath(zsh_path)}"')
# Look for bash config
bash_rc = os.path.join(os.path.expanduser('~'), '.bashrc')
if os.path.exists(bash_rc):
print("Adding to Bash...")
bash_aliases = os.path.join(os.path.expanduser('~'), '.bash_aliases')
os.system(f'sudo sh -c "echo {alias} >> {quotePath(bash_aliases)}"')
if __name__ == "__main__":
install()