-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.py
More file actions
65 lines (48 loc) · 1.87 KB
/
update.py
File metadata and controls
65 lines (48 loc) · 1.87 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
import os
import subprocess
import sys
def y_n(q):
while True:
ri = input("{} (y/n): ".format(q))
if ri.lower() in ["yes", "y"]:
return True
elif ri.lower() in ["no", "n"]:
return False
def update_deps():
print("Attempting to install dependencies...")
try:
subprocess.check_call(
'"{}" -m pip install --no-warn-script-location -r requirements/all.txt'.format(sys.executable)
, shell=True)
except subprocess.CalledProcessError:
raise OSError("Failed to install dependencies. Please install them manually.")
def main():
print("Starting updates...")
if not os.path.isdir(".git"):
raise EnvironmentError("This script must be run from the root of the repository.")
try:
subprocess.check_call("git --version", shell=True, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError:
raise OSError("Git not found. Please install it manually.")
print("Passed Git checks...")
sp = subprocess.check_output("git status --porcelain", shell=True, universal_newlines=True)
if sp:
oshit = y_n("You have uncommitted changes. Do you want to continue?")
if oshit:
try:
subprocess.check_call("git reset --hard", shell=True)
except subprocess.CalledProcessError:
raise OSError("Failed to reset repository. Please do it manually.")
else:
wowee = y_n("Do you want to update dependencies?")
if wowee:
update_deps()
print("Checking if we need to update the program...")
try:
subprocess.check_call("git pull", shell=True)
except subprocess.CalledProcessError:
print("Failed to update the program. Please do it manually.")
update_deps()
print("Done!")
if __name__ == '__main__':
main()