-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathstart.py
58 lines (47 loc) · 1.32 KB
/
start.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
import os
from dotenv import load_dotenv
import requests
import time
import subprocess
import shutil
load_dotenv()
def downloadSA(salink):
res = requests.get(salink)
if res.status_code == 200:
with open('accounts.zip', 'wb') as f:
f.truncate(0)
f.write(res.content)
subprocess.run(["unzip", "-q", "-o", "accounts.zip"])
os.remove("accounts.zip")
print("Service accounts downloaded")
else:
raise KeyError
if not "accounts" in os.listdir():
downloadSA(os.environ["accounts_zip_url"])
safile = open("sa","w")
safile.write(os.environ["accounts_zip_url"])
safile.close()
else:
safile = open("sa","r")
oldLink = safile.readline()
if oldLink != os.environ["accounts_zip_url"]:
print("new SA detected")
shutil.rmtree("accounts")
downloadSA(os.environ["accounts_zip_url"])
else:
print("no new SA")
pass
drives = os.environ["drive_ids"]
drives_list = drives.split(",")
f = open("process.sh","w")
for drives in drives_list:
drive1 = drives.split(" ")[0]
drive2 = drives.split(" ")[1]
text_to_write = "python3 process.py -s {} -d {} -sp / -dp / -b 1 -e 600\n".format(drive1, drive2)
f.write(text_to_write)
f.close()
time.sleep(3)
seconds_to_wait = int(os.environ["rest_seconds"])
while(True):
subprocess.call(['sh', './process.sh'])
time.sleep(seconds_to_wait)