-
Notifications
You must be signed in to change notification settings - Fork 0
/
persistent.py
115 lines (107 loc) · 3.34 KB
/
persistent.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import sys, time, ast, os, threading
from LOaBIS import log, say
from datetime import datetime
def main():
logpers("Initialising")
threading.Thread(name="Shutdown",target=chkshut).start()
time.sleep(1)
_funcs,_start=_fetchfuncs()
logpers("Initialisation complete")
if _start:
logpers("Running "+str(len(_start))+" startup functions, "+str(_start))
a=[]
for x in _start:
try:
globals()[str(x)]()
except:
a.append(x)
_start.remove(x)
logpers("Could not execute: "+str(a))
else:
logpers("No startup functions found")
if _funcs:
a,b=[],30
while not closed:
if checktime(b):
logpers("Running "+str(len(_funcs))+" persistence functions, "+str(_funcs))
for x in _funcs:
try:
globals()[str(x)]()
except:
a.append(x)
_funcs.remove(x)
logpers("Could not execute: "+str(a))
else:
logpers("No persistence functions found")
def checktime(wait_time=1):
a=datetime.now()
if int(a.minute)%wait_time==0:
if a.second==0:
time.sleep(2)
return True
else:
return False
def _fetchfuncs():
try:
_modinfo=ast.literal_eval(sys.argv[1])
except:
_modinfo=_fetchmods()
logpers("fetching persistence functions")
_funcs,_start=[],[]
for x in _modinfo:
for y in x[10]:
_funcs.append(y)
for y in x[11]:
_start.append(y)
core=getdat(_modinfo,"LOaBIS Core")
subprocess.call("title "+str(core[0])+" v"+str(core[1])+" - Persistence module",shell=True)
return _funcs, _start
def chkshut():
globals()["closed"]=False
try:
server=startsock(False)[0]
logpers("LOaBIS synchronisation established")
while True:
if "shutdown" in msg(server):
break
globals()["closed"]=True
logpers("Shutting down")
except:
logpers("LOaBIS not available, running seperately")
def _fetchmods():
modinfo,_mods=[],[]
for x in modules:
modinfo.append(getinfo(x))
_mods.append(getinfo(x))
logpers("Loading modules")
for x in _mods:
a,tmp=[],[]
if x[6]:
for y in x[6]:
if getdat(getexcept(modinfo,x[0]),y):
a.append(modinfo.index(getdat(modinfo,y)))
else:
tmp.append(y)
if tmp:
logpers(str(x[0])+" missing "+str(len(tmp))+" dependancies: "+str(tmp))
modinfo.remove(x)
elif a:
modinfo.insert(1+max(a),x)
logpers("Modules loaded")
return modinfo
def logpers(text="null"):
log("Persistence module: "+str(text))
def eplog(err ="",sy=1):
log("Persistence Error: "+str(type(err))+"; "+str(err))
if sy:
say("Software encountered an error, consider submitting log to developers","Error",1)
if __name__=="__main__":
from _core import getexcept
avoid=["__pycache__",".git"]
globals()["modules"]=getexcept(next(os.walk(os.getcwd()))[1],avoid)
modules.sort()
for x in modules:
exec("from "+str(x)+" import *")
main()
#except Exception as e:
#eplog(e)