-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.py
83 lines (56 loc) · 1.66 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#0 12 * * * python3 /var/www/html/update.py &
import os
import sys
import json
import time
import traceback
sys.path.append("/var/www/html/lib/")
from helper import *
import helper as h
file_name = os.path.basename(__file__)
local_debug = True
try:
def version_control():
version_file = "version.txt"
if os.path.exists(h.app_base_path+version_file) == False:
return False
local_version = log_and_run(read_from_file, h.app_base_path+version_file)
remote_version = http_get(h.update_base_url+version_file)
return local_version == remote_version
def run():
log_and_run(unlimit_bandwith)
if log_and_run(version_control): return
files = http_get(h.update_base_url+"fileList.txt")
for file in files.split("\n"):
file = file.replace("\r", "")
if len(file) == 0: continue
temp = file.split(".")
ext = temp[-1]
url = h.update_base_url+file
path = h.app_base_path+file
if ext == "py" or ext == "txt":
log(INFO, "File read from server: " + file)
txt = http_get(url)
if txt == None:
log(WARNING, "File not found: " + path)
return
log(INFO, "File write to local: " + path)
write_to_file(path, txt)
else:
if download_file(url, path, sllDisable = True) == False:
log(WARNING, "wget error")
return
cmd = "python3 "+h.after_update_subs_py_file_path
command(cmd)
#Ana Fonksiyon
if __name__ == "__main__":
preload(file_name)
h.debug = local_debug
if h.connected:
log_and_run(run)
else:
log(ERROR, "Connected false")
log_and_run(endload)
except Exception as e:
fn = os.path.basename(__file__)
root_ex(fn, e)