forked from adangert/JoustMania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
65 lines (52 loc) · 2.33 KB
/
update.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
62
63
64
import common
import subprocess
from piaudio import Audio, InitAudio
import time
import shlex
import os
if __name__ == "__main__":
InitAudio()
check_for_update('ivy')
def run_command(command):
process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
outout = ""
while True:
output = process.stdout.readline().decode("utf-8")
if (output == "b''" or output == '') and process.poll() is not None:
break
if output:
outout += output
print(output.strip())
rc = process.poll()
return outout
def big_update(voice):
Audio('audio/Menu/vox/' + voice + '/update_started.wav').start_effect_and_wait()
current_hash = run_command("sudo runuser -l pi -c 'cd {};git rev-parse HEAD'".format(os.getcwd())).strip()
run_command("sudo runuser -l pi -c 'cd {};git checkout master'".format(os.getcwd()))
run_command("sudo runuser -l pi -c 'cd {};git pull'".format(os.getcwd()))
run_command("sudo /home/{}/JoustMania/setup.sh".format(os.getlogin()))
#it failed if it got this far
time.sleep(3)
run_command("sudo runuser -l pi -c 'cd {};git checkout {}'".format(os.getcwd(),current_hash))
Audio('audio/Menu/vox/' + voice + '/joustmania_failed.wav').start_effect_and_wait()
def tester():
current_hash = run_command("sudo runuser -l pi -c 'git rev-parse HEAD'").strip()
print(current_hash)
def check_for_update(voice):
print("checking out login@@@@@@@@@@@@@@@@@@@")
print(os.getcwd())
print(os.path.expanduser('~'))
print(os.environ.get("USERNAME"))
#print(os.getlogin())
process = run_command("sudo runuser -l pi -c 'cd {};pwd'".format(os.getcwd()))
process = run_command("sudo runuser -l pi -c 'cd {};git fetch'".format(os.getcwd()))
diff_files = run_command("sudo runuser -l pi -c 'cd {};git diff origin/master --name-only --cached'".format(os.getcwd())).split()
print(diff_files)
if('setup.sh' in diff_files):
Audio('audio/Menu/vox/' + voice + '/large_update.wav').start_effect_and_wait()
return True
elif (len(diff_files) >= 1):
print("doing small pull")
pull = run_command("sudo runuser -l pi -c 'cd {};git pull'".format(os.getcwd()))
Audio('audio/Menu/vox/' + voice + '/joustmania_updated.wav').start_effect_and_wait()
return False