-
Notifications
You must be signed in to change notification settings - Fork 1
/
caller.py
53 lines (46 loc) · 1.76 KB
/
caller.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
import subprocess
import atexit
import datetime
import sys
popen = None
def execute(cmd, log_timestamps=False):
try:
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
print(f'New child created [{datetime.datetime.now()}]') if log_timestamps else print('New child created')
for stdout_line in iter(popen.stdout.readline, ""):
yield stdout_line
popen.stdout.close()
return_code = popen.wait()
if return_code:
print(return_code)
return
except KeyboardInterrupt:
print("Manual shutdown requested... killing process and child.")
popen.kill()
sys.exit()
def update():
print(f'{"-"*10}\n\n\n\n')
for path in execute(["yes", "|", "git", "pull", "https://github.com/thenamesweretakenalready/Folding-At-Home-Team-Data-for-Discord"]):
print(path, end="")
print(f'{"-"*10}\n\n\n\n')
if __name__ == "__main__":
print(sys.argv)
if len(sys.argv) > 1:
if sys.argv[1] == "-log_timestamps":
while True:
for path in execute(["python3", "bot.py"], log_timestamps=True):
print(path, end="")
else:
while True:
for path in execute(["python3", "bot.py"]):
if path in ['restart', 'update']:
if path == 'restart':
print('Automatic restart requested... killing child and restarting.')
popen.kill()
else:
print('Automatic update requested... killing child and beginning update.')
popen.kill()
update()
else:
print(path, end="")
atexit.register(popen.kill)