genocide 205__tar.gz → 207__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {genocide-205 → genocide-207}/PKG-INFO +1 -1
- {genocide-205 → genocide-207}/genocide/__init__.py +1 -2
- {genocide-205 → genocide-207}/genocide/__main__.py +157 -166
- genocide-207/genocide/command.py +234 -0
- genocide-207/genocide/handler.py +238 -0
- genocide-207/genocide/methods.py +216 -0
- {genocide-205 → genocide-207}/genocide/modules/req.py +1 -1
- {genocide-205 → genocide-207}/genocide/modules/slg.py +1 -1
- {genocide-205 → genocide-207}/genocide/modules/tbl.py +2 -3
- genocide-207/genocide/objects.py +124 -0
- genocide-207/genocide/persist.py +215 -0
- genocide-207/genocide/runtime.py +132 -0
- {genocide-205 → genocide-207}/genocide.egg-info/PKG-INFO +1 -1
- {genocide-205 → genocide-207}/genocide.egg-info/SOURCES.txt +12 -14
- {genocide-205 → genocide-207}/pyproject.toml +3 -3
- genocide-205/genocide/client.py +0 -95
- genocide-205/genocide/handler.py +0 -128
- genocide-205/genocide/json.py +0 -84
- genocide-205/genocide/modules/__init__.py +0 -395
- genocide-205/genocide/object.py +0 -72
- genocide-205/genocide/store.py +0 -257
- genocide-205/genocide/thread.py +0 -179
- genocide-205/setup.py +0 -11
- {genocide-205 → genocide-207}/README.rst +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/ECHAabilify.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/ECHAclozapine.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/ECHAhaldol.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/ECHAzyprexa.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/OTP111.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/OTP222.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/abilifypubchem.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/ack3.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/bevestigd.jpg +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/clozapinepubchem.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/genocide.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/haldolpubchem.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/informed.jpg +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/kamer2.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/skull3.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_images/zyprexapubchem.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/alabaster.css +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/basic.css +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/custom.css +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/doctools.js +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/documentation_options.js +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/file.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/genocide.css +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/language_data.js +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/minus.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/opensearch.xml +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/plus.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/pygments.css +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/searchtools.js +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/sitemap.xml +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/skull3.png +0 -0
- {genocide-205 → genocide-207}/genocide/html/_static/sphinx_highlight.js +0 -0
- {genocide-205 → genocide-207}/genocide/html/about.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/evidence.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/genindex-all.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/genindex.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/guilty.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/index.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/manual.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/objects.inv +0 -0
- {genocide-205/genocide → genocide-207/genocide/html}/pdf/EM_Ack_OTP-CR-117_19.pdf +0 -0
- {genocide-205/genocide → genocide-207/genocide/html}/pdf/EM_T04_OTP-CR-117_19.pdf +0 -0
- {genocide-205/genocide → genocide-207/genocide/html}/pdf/EM_T07_OTP-CR-117_19_001.pdf +0 -0
- {genocide-205/genocide → genocide-207/genocide/html}/pdf/Kamer.pdf +0 -0
- {genocide-205/genocide → genocide-207/genocide/html}/pdf/Rome-Statute.pdf +0 -0
- {genocide-205/genocide → genocide-207/genocide/html}/pdf/bevestigd.pdf +0 -0
- {genocide-205 → genocide-207}/genocide/html/pubchem.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/reconsider.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/request.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/robots.txt +0 -0
- {genocide-205 → genocide-207}/genocide/html/search.html +0 -0
- {genocide-205 → genocide-207}/genocide/html/searchindex.js +0 -0
- {genocide-205 → genocide-207}/genocide/html/writings.html +0 -0
- {genocide-205 → genocide-207}/genocide/modules/pth.py +0 -0
- {genocide-205 → genocide-207}/genocide.egg-info/dependency_links.txt +0 -0
- {genocide-205 → genocide-207}/genocide.egg-info/entry_points.txt +0 -0
- {genocide-205 → genocide-207}/genocide.egg-info/top_level.txt +0 -0
- {genocide-205 → genocide-207}/setup.cfg +0 -0
|
@@ -4,23 +4,42 @@
|
|
|
4
4
|
"main program"
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
import json
|
|
8
|
+
import logging
|
|
7
9
|
import os
|
|
10
|
+
import os.path
|
|
8
11
|
import pathlib
|
|
9
12
|
import sys
|
|
10
13
|
import time
|
|
11
14
|
import _thread
|
|
12
15
|
|
|
13
16
|
|
|
14
|
-
from .
|
|
15
|
-
from .
|
|
16
|
-
from .
|
|
17
|
-
from .
|
|
18
|
-
from .
|
|
19
|
-
from .
|
|
20
|
-
from .
|
|
17
|
+
from .command import Commands, command, getmod, importer
|
|
18
|
+
from .command import md5sum, modules, parse, scanner, table
|
|
19
|
+
from .handler import Client, Event, Fleet
|
|
20
|
+
from .methods import level, spl
|
|
21
|
+
from .objects import update
|
|
22
|
+
from .persist import Workdir, pidname, setwd
|
|
23
|
+
from .runtime import launch
|
|
21
24
|
|
|
22
25
|
|
|
23
|
-
"
|
|
26
|
+
CHECKSUM = "77ef78cd3fbe505f68343b785b7d3917"
|
|
27
|
+
NAME = Workdir.name
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Config:
|
|
31
|
+
|
|
32
|
+
debug = False
|
|
33
|
+
default = "irc,mdl,rss"
|
|
34
|
+
gets = {}
|
|
35
|
+
init = ""
|
|
36
|
+
level = "warn"
|
|
37
|
+
mod = ""
|
|
38
|
+
opts = ""
|
|
39
|
+
otxt = ""
|
|
40
|
+
sets = {}
|
|
41
|
+
verbose = False
|
|
42
|
+
version = 207
|
|
24
43
|
|
|
25
44
|
|
|
26
45
|
class CLI(Client):
|
|
@@ -29,19 +48,23 @@ class CLI(Client):
|
|
|
29
48
|
Client.__init__(self)
|
|
30
49
|
self.register("command", command)
|
|
31
50
|
|
|
51
|
+
def announce(self, txt):
|
|
52
|
+
self.raw(txt)
|
|
53
|
+
|
|
32
54
|
def raw(self, txt):
|
|
33
|
-
|
|
55
|
+
out(txt.encode('utf-8', 'replace').decode("utf-8"))
|
|
34
56
|
|
|
35
57
|
|
|
36
58
|
class Console(CLI):
|
|
37
59
|
|
|
38
60
|
def announce(self, txt):
|
|
39
|
-
#output(txt)
|
|
40
61
|
pass
|
|
41
62
|
|
|
42
|
-
def callback(self,
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
def callback(self, event):
|
|
64
|
+
if not event.txt:
|
|
65
|
+
return
|
|
66
|
+
super().callback(event)
|
|
67
|
+
event.wait()
|
|
45
68
|
|
|
46
69
|
def poll(self):
|
|
47
70
|
evt = Event()
|
|
@@ -50,56 +73,71 @@ class Console(CLI):
|
|
|
50
73
|
return evt
|
|
51
74
|
|
|
52
75
|
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def handler(signum, frame):
|
|
57
|
-
_thread.interrupt_main()
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"output"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def doprint(txt):
|
|
64
|
-
print(txt.rstrip())
|
|
65
|
-
sys.stdout.flush()
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def output(txt):
|
|
69
|
-
doprint(txt)
|
|
76
|
+
"scripts"
|
|
70
77
|
|
|
71
78
|
|
|
72
|
-
def
|
|
73
|
-
|
|
79
|
+
def background():
|
|
80
|
+
daemon("-v" in sys.argv)
|
|
81
|
+
privileges()
|
|
82
|
+
boot(False)
|
|
83
|
+
pidfile(pidname(NAME))
|
|
84
|
+
inits(Config.init or Config.default)
|
|
85
|
+
forever()
|
|
74
86
|
|
|
75
87
|
|
|
76
|
-
def
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
def console():
|
|
89
|
+
import readline # noqa: F401
|
|
90
|
+
boot()
|
|
91
|
+
for _mod, thr in inits(Config.init):
|
|
92
|
+
if "w" in Config.opts:
|
|
93
|
+
thr.join(30.0)
|
|
94
|
+
csl = Console()
|
|
95
|
+
csl.start(daemon=True)
|
|
96
|
+
forever()
|
|
79
97
|
|
|
80
98
|
|
|
81
|
-
def
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
def control():
|
|
100
|
+
if len(sys.argv) == 1:
|
|
101
|
+
return
|
|
102
|
+
boot()
|
|
103
|
+
Commands.add(md5)
|
|
104
|
+
Commands.add(srv)
|
|
105
|
+
Commands.add(tbl)
|
|
106
|
+
csl = CLI()
|
|
107
|
+
evt = Event()
|
|
108
|
+
evt.orig = repr(csl)
|
|
109
|
+
evt.type = "command"
|
|
110
|
+
evt.txt = Config.otxt
|
|
111
|
+
command(evt)
|
|
112
|
+
evt.wait()
|
|
84
113
|
|
|
85
114
|
|
|
86
|
-
|
|
115
|
+
def service():
|
|
116
|
+
privileges()
|
|
117
|
+
boot(False)
|
|
118
|
+
pidfile(pidname(NAME))
|
|
119
|
+
inits(Config.init or Config.default)
|
|
120
|
+
forever()
|
|
87
121
|
|
|
88
122
|
|
|
89
|
-
def
|
|
90
|
-
|
|
91
|
-
|
|
123
|
+
def boot(doparse=True):
|
|
124
|
+
if doparse:
|
|
125
|
+
parse(Config, " ".join(sys.argv[1:]))
|
|
126
|
+
update(Config, Config.sets, empty=False)
|
|
127
|
+
if "m" in Config.opts:
|
|
128
|
+
Commands.mod = Config.mod = "mods"
|
|
129
|
+
if "a" in Config.opts:
|
|
130
|
+
Config.init = ",".join(modules())
|
|
131
|
+
level(Config.level)
|
|
132
|
+
if "v" in Config.opts:
|
|
133
|
+
banner()
|
|
134
|
+
setwd(NAME)
|
|
135
|
+
table(CHECKSUM)
|
|
136
|
+
Commands.add(cmd)
|
|
137
|
+
Commands.add(ver)
|
|
92
138
|
|
|
93
139
|
|
|
94
|
-
|
|
95
|
-
args = sys.argv[1:]
|
|
96
|
-
for arg in args:
|
|
97
|
-
if not arg.startswith("-"):
|
|
98
|
-
continue
|
|
99
|
-
for char in txt:
|
|
100
|
-
if char in arg:
|
|
101
|
-
return True
|
|
102
|
-
return False
|
|
140
|
+
"daemon"
|
|
103
141
|
|
|
104
142
|
|
|
105
143
|
def daemon(verbose=False):
|
|
@@ -122,23 +160,20 @@ def daemon(verbose=False):
|
|
|
122
160
|
os.nice(10)
|
|
123
161
|
|
|
124
162
|
|
|
125
|
-
def
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
output(line)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def forever():
|
|
132
|
-
while True:
|
|
163
|
+
def inits(names):
|
|
164
|
+
modz = []
|
|
165
|
+
for name in sorted(spl(names)):
|
|
133
166
|
try:
|
|
134
|
-
|
|
135
|
-
|
|
167
|
+
module = getmod(name)
|
|
168
|
+
if not module:
|
|
169
|
+
continue
|
|
170
|
+
if "init" in dir(module):
|
|
171
|
+
thr = launch(module.init)
|
|
172
|
+
modz.append((module, thr))
|
|
173
|
+
except Exception as ex:
|
|
174
|
+
logging.exception(ex)
|
|
136
175
|
_thread.interrupt_main()
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def nodebug():
|
|
140
|
-
with open('/dev/null', 'a+', encoding="utf-8") as ses:
|
|
141
|
-
os.dup2(ses.fileno(), sys.stderr.fileno())
|
|
176
|
+
return modz
|
|
142
177
|
|
|
143
178
|
|
|
144
179
|
def pidfile(filename):
|
|
@@ -158,115 +193,96 @@ def privileges():
|
|
|
158
193
|
os.setuid(pwnam2.pw_uid)
|
|
159
194
|
|
|
160
195
|
|
|
161
|
-
def setwd(name, path=""):
|
|
162
|
-
Main.name = name
|
|
163
|
-
path = path or os.path.expanduser(f"~/.{name}")
|
|
164
|
-
Workdir.wdr = path
|
|
165
|
-
|
|
166
|
-
|
|
167
196
|
"commands"
|
|
168
197
|
|
|
169
198
|
|
|
170
199
|
def cmd(event):
|
|
171
|
-
event.reply(",".join(sorted(
|
|
200
|
+
event.reply(",".join(sorted(Commands.names)))
|
|
172
201
|
|
|
173
202
|
|
|
174
203
|
def md5(event):
|
|
175
|
-
|
|
176
|
-
|
|
204
|
+
tbl = getmod("tbl")
|
|
205
|
+
if tbl:
|
|
206
|
+
event.reply(md5sum(tbl.__file__))
|
|
207
|
+
else:
|
|
208
|
+
event.reply("table is not there.")
|
|
177
209
|
|
|
178
210
|
|
|
179
211
|
def srv(event):
|
|
180
212
|
import getpass
|
|
181
213
|
name = getpass.getuser()
|
|
182
|
-
event.reply(TXT % (
|
|
214
|
+
event.reply(TXT % (NAME.upper(), name, name, name, NAME))
|
|
183
215
|
|
|
184
216
|
|
|
185
217
|
def tbl(event):
|
|
186
218
|
if not check("f"):
|
|
187
219
|
Commands.names = {}
|
|
188
|
-
|
|
189
|
-
scan(mod)
|
|
220
|
+
scanner()
|
|
190
221
|
event.reply("# This file is placed in the Public Domain.")
|
|
191
222
|
event.reply("")
|
|
192
223
|
event.reply("")
|
|
193
224
|
event.reply('"lookup tables"')
|
|
194
225
|
event.reply("")
|
|
195
226
|
event.reply("")
|
|
196
|
-
event.reply(f"NAMES = {dumps(Commands.names, indent=4, sort_keys=True)}")
|
|
197
|
-
event.reply("")
|
|
227
|
+
event.reply(f"NAMES = {json.dumps(Commands.names, indent=4, sort_keys=True)}")
|
|
198
228
|
event.reply("")
|
|
199
229
|
event.reply("MD5 = {")
|
|
200
|
-
for
|
|
201
|
-
event.reply(f' "{
|
|
230
|
+
for module in scanner():
|
|
231
|
+
event.reply(f' "{module.__name__.split(".")[-1]}": "{md5sum(module.__file__)}",')
|
|
202
232
|
event.reply("}")
|
|
203
233
|
|
|
204
234
|
|
|
205
|
-
|
|
235
|
+
def ver(event):
|
|
236
|
+
event.reply(f"{NAME.upper()} {Config.version}")
|
|
206
237
|
|
|
207
238
|
|
|
208
|
-
|
|
209
|
-
daemon("-v" in sys.argv)
|
|
210
|
-
setwd(Main.name)
|
|
211
|
-
privileges()
|
|
212
|
-
disable()
|
|
213
|
-
pidfile(pidname(Main.name))
|
|
214
|
-
settable()
|
|
215
|
-
Commands.add(cmd)
|
|
216
|
-
inits(Main.init or "irc,rss")
|
|
217
|
-
forever()
|
|
239
|
+
"utilities"
|
|
218
240
|
|
|
219
241
|
|
|
220
|
-
def
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
enable()
|
|
224
|
-
settable()
|
|
225
|
-
Commands.add(cmd)
|
|
226
|
-
parse(Main, " ".join(sys.argv[1:]))
|
|
227
|
-
Main.init = Main.sets.init or Main.init
|
|
228
|
-
Main.verbose = Main.sets.verbose or Main.verbose
|
|
229
|
-
if "v" in Main.opts:
|
|
230
|
-
banner()
|
|
231
|
-
for _mod, thr in inits(Main.init):
|
|
232
|
-
if "w" in Main.opts:
|
|
233
|
-
thr.join(30.0)
|
|
234
|
-
csl = Console()
|
|
235
|
-
csl.start()
|
|
236
|
-
forever()
|
|
242
|
+
def banner():
|
|
243
|
+
tme = time.ctime(time.time()).replace(" ", " ")
|
|
244
|
+
out(f"{NAME.upper()} {Config.version} since {tme} ({Config.level.upper()})")
|
|
237
245
|
|
|
238
246
|
|
|
239
|
-
def
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
Commands.add(tbl)
|
|
249
|
-
parse(Main, " ".join(sys.argv[1:]))
|
|
250
|
-
csl = CLI()
|
|
251
|
-
evt = Event()
|
|
252
|
-
evt.orig = repr(csl)
|
|
253
|
-
evt.type = "command"
|
|
254
|
-
evt.txt = Main.otxt
|
|
255
|
-
command(evt)
|
|
256
|
-
evt.wait()
|
|
247
|
+
def check(txt):
|
|
248
|
+
args = sys.argv[1:]
|
|
249
|
+
for arg in args:
|
|
250
|
+
if not arg.startswith("-"):
|
|
251
|
+
continue
|
|
252
|
+
for char in txt:
|
|
253
|
+
if char in arg:
|
|
254
|
+
return True
|
|
255
|
+
return False
|
|
257
256
|
|
|
258
257
|
|
|
259
|
-
def
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
258
|
+
def forever():
|
|
259
|
+
while True:
|
|
260
|
+
try:
|
|
261
|
+
time.sleep(0.1)
|
|
262
|
+
except (KeyboardInterrupt, EOFError):
|
|
263
|
+
break
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def out(txt):
|
|
267
|
+
print(txt)
|
|
268
|
+
sys.stdout.flush()
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
"data"
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
TXT = """[Unit]
|
|
275
|
+
Description=%s
|
|
276
|
+
After=network-online.target
|
|
277
|
+
|
|
278
|
+
[Service]
|
|
279
|
+
Type=simple
|
|
280
|
+
User=%s
|
|
281
|
+
Group=%s
|
|
282
|
+
ExecStart=/home/%s/.local/bin/%s -s
|
|
283
|
+
|
|
284
|
+
[Install]
|
|
285
|
+
WantedBy=multi-user.target"""
|
|
270
286
|
|
|
271
287
|
|
|
272
288
|
"runtime"
|
|
@@ -276,8 +292,8 @@ def wrapped(func):
|
|
|
276
292
|
try:
|
|
277
293
|
func()
|
|
278
294
|
except (KeyboardInterrupt, EOFError):
|
|
279
|
-
|
|
280
|
-
|
|
295
|
+
out("")
|
|
296
|
+
Fleet.shutdown()
|
|
281
297
|
|
|
282
298
|
|
|
283
299
|
def wrap(func):
|
|
@@ -294,32 +310,7 @@ def wrap(func):
|
|
|
294
310
|
termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, old)
|
|
295
311
|
|
|
296
312
|
|
|
297
|
-
"data"
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
TXT = """[Unit]
|
|
301
|
-
Description=%s
|
|
302
|
-
After=network-online.target
|
|
303
|
-
|
|
304
|
-
[Service]
|
|
305
|
-
Type=simple
|
|
306
|
-
User=%s
|
|
307
|
-
Group=%s
|
|
308
|
-
ExecStart=/home/%s/.local/bin/%s -s
|
|
309
|
-
|
|
310
|
-
[Install]
|
|
311
|
-
WantedBy=multi-user.target"""
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
"main"
|
|
315
|
-
|
|
316
|
-
|
|
317
313
|
def main():
|
|
318
|
-
if check("a"):
|
|
319
|
-
Main.init = ",".join(modules())
|
|
320
|
-
if check("v"):
|
|
321
|
-
setattr(Main.opts, "v", True)
|
|
322
|
-
enable()
|
|
323
314
|
if check("c"):
|
|
324
315
|
wrap(console)
|
|
325
316
|
elif check("d"):
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# This file is placed in the Public Domain.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
"commands"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import hashlib
|
|
8
|
+
import importlib
|
|
9
|
+
import importlib.util
|
|
10
|
+
import inspect
|
|
11
|
+
import logging
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
import threading
|
|
15
|
+
import _thread
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from .methods import j, rlog, spl
|
|
19
|
+
from .handler import Fleet
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
lock = threading.RLock()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Commands:
|
|
26
|
+
|
|
27
|
+
cmds = {}
|
|
28
|
+
debug = False
|
|
29
|
+
md5s = {}
|
|
30
|
+
mod = j(os.path.dirname(__file__), "modules")
|
|
31
|
+
package = __name__.split(".")[0] + "." + "modules"
|
|
32
|
+
names = {}
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def add(func) -> None:
|
|
36
|
+
name = func.__name__
|
|
37
|
+
modname = func.__module__.split(".")[-1]
|
|
38
|
+
Commands.cmds[name] = func
|
|
39
|
+
Commands.names[name] = modname
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def get(cmd):
|
|
43
|
+
func = Commands.cmds.get(cmd, None)
|
|
44
|
+
if func:
|
|
45
|
+
return func
|
|
46
|
+
name = Commands.names.get(cmd, None)
|
|
47
|
+
if not name:
|
|
48
|
+
return
|
|
49
|
+
module = getmod(name)
|
|
50
|
+
if not module:
|
|
51
|
+
return
|
|
52
|
+
scan(module)
|
|
53
|
+
if Commands.debug:
|
|
54
|
+
module.DEBUG = True
|
|
55
|
+
return Commands.cmds.get(cmd, None)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def command(evt):
|
|
59
|
+
parse(evt)
|
|
60
|
+
func = Commands.get(evt.cmd)
|
|
61
|
+
if func:
|
|
62
|
+
func(evt)
|
|
63
|
+
Fleet.display(evt)
|
|
64
|
+
evt.ready()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
"modules"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def getmod(name, path=None):
|
|
71
|
+
with lock:
|
|
72
|
+
mname = Commands.package + "." + name
|
|
73
|
+
module = sys.modules.get(mname, None)
|
|
74
|
+
if module:
|
|
75
|
+
return module
|
|
76
|
+
if not path:
|
|
77
|
+
path = Commands.mod
|
|
78
|
+
pth = j(path, f"{name}.py")
|
|
79
|
+
if not os.path.exists(pth):
|
|
80
|
+
return
|
|
81
|
+
if name != "tbl" and md5sum(pth) != Commands.md5s.get(name, None):
|
|
82
|
+
rlog("warn", f"md5 error on {pth.split(os.sep)[-1]}")
|
|
83
|
+
return importer(mname, pth)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def modules():
|
|
87
|
+
if not os.path.exists(Commands.mod):
|
|
88
|
+
return {}
|
|
89
|
+
return {
|
|
90
|
+
x[:-3] for x in os.listdir(Commands.mod)
|
|
91
|
+
if x.endswith(".py") and not x.startswith("__")
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def scan(module):
|
|
96
|
+
for key, cmdz in inspect.getmembers(module, inspect.isfunction):
|
|
97
|
+
if key.startswith("cb"):
|
|
98
|
+
continue
|
|
99
|
+
if 'event' in inspect.signature(cmdz).parameters:
|
|
100
|
+
Commands.add(cmdz)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def scanner(names=None):
|
|
104
|
+
res = []
|
|
105
|
+
for nme in sorted(modules()):
|
|
106
|
+
if names and nme not in spl(names):
|
|
107
|
+
continue
|
|
108
|
+
module = getmod(nme)
|
|
109
|
+
if not module:
|
|
110
|
+
continue
|
|
111
|
+
scan(module)
|
|
112
|
+
res.append(module)
|
|
113
|
+
return res
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def table(checksum=""):
|
|
117
|
+
pth = j(Commands.mod, "tbl.py")
|
|
118
|
+
if os.path.exists(pth):
|
|
119
|
+
if checksum and md5sum(pth) != checksum:
|
|
120
|
+
rlog("warn", "table checksum error.")
|
|
121
|
+
tbl = getmod("tbl")
|
|
122
|
+
if tbl:
|
|
123
|
+
if "NAMES" in dir(tbl):
|
|
124
|
+
Commands.names.update(tbl.NAMES)
|
|
125
|
+
if "MD5" in dir(tbl):
|
|
126
|
+
Commands.md5s.update(tbl.MD5)
|
|
127
|
+
else:
|
|
128
|
+
scanner()
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
"utilities"
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def importer(name, pth):
|
|
135
|
+
try:
|
|
136
|
+
spec = importlib.util.spec_from_file_location(name, pth)
|
|
137
|
+
if not spec:
|
|
138
|
+
rlog("info", f"misiing {pth}")
|
|
139
|
+
return
|
|
140
|
+
module = importlib.util.module_from_spec(spec)
|
|
141
|
+
if not module:
|
|
142
|
+
rlog("info", f"{pth} not importable")
|
|
143
|
+
return
|
|
144
|
+
sys.modules[name] = module
|
|
145
|
+
spec.loader.exec_module(module)
|
|
146
|
+
rlog("info", f"load {pth}")
|
|
147
|
+
return module
|
|
148
|
+
except Exception as ex:
|
|
149
|
+
logging.exception(ex)
|
|
150
|
+
_thread.interrupt_main()
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def md5sum(path):
|
|
154
|
+
with open(path, "r", encoding="utf-8") as file:
|
|
155
|
+
txt = file.read().encode("utf-8")
|
|
156
|
+
return hashlib.md5(txt).hexdigest()
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def parse(obj, txt=None):
|
|
160
|
+
if txt is None:
|
|
161
|
+
if "txt" in dir(obj):
|
|
162
|
+
txt = obj.txt
|
|
163
|
+
else:
|
|
164
|
+
txt = ""
|
|
165
|
+
args = []
|
|
166
|
+
obj.args = getattr(obj, "args", [])
|
|
167
|
+
obj.cmd = getattr(obj, "cmd", "")
|
|
168
|
+
obj.gets = getattr(obj, "gets", "")
|
|
169
|
+
obj.index = getattr(obj, "index", None)
|
|
170
|
+
obj.inits = getattr(obj, "inits", "")
|
|
171
|
+
obj.mod = getattr(obj, "mod", "")
|
|
172
|
+
obj.opts = getattr(obj, "opts", "")
|
|
173
|
+
obj.result = getattr(obj, "result", "")
|
|
174
|
+
obj.sets = getattr(obj, "sets", {})
|
|
175
|
+
obj.silent = getattr(obj, "silent", "")
|
|
176
|
+
obj.txt = txt or getattr(obj, "txt", "")
|
|
177
|
+
obj.otxt = obj.txt or getattr(obj, "otxt", "")
|
|
178
|
+
_nr = -1
|
|
179
|
+
for spli in obj.otxt.split():
|
|
180
|
+
if spli.startswith("-"):
|
|
181
|
+
try:
|
|
182
|
+
obj.index = int(spli[1:])
|
|
183
|
+
except ValueError:
|
|
184
|
+
obj.opts += spli[1:]
|
|
185
|
+
continue
|
|
186
|
+
if "-=" in spli:
|
|
187
|
+
key, value = spli.split("-=", maxsplit=1)
|
|
188
|
+
obj.silent[key] = value
|
|
189
|
+
obj.gets[key] = value
|
|
190
|
+
continue
|
|
191
|
+
if "==" in spli:
|
|
192
|
+
key, value = spli.split("==", maxsplit=1)
|
|
193
|
+
obj.gets[key] = value
|
|
194
|
+
continue
|
|
195
|
+
if "=" in spli:
|
|
196
|
+
key, value = spli.split("=", maxsplit=1)
|
|
197
|
+
if key == "mod":
|
|
198
|
+
if obj.mod:
|
|
199
|
+
obj.mod += f",{value}"
|
|
200
|
+
else:
|
|
201
|
+
obj.mod = value
|
|
202
|
+
continue
|
|
203
|
+
obj.sets[key] = value
|
|
204
|
+
continue
|
|
205
|
+
_nr += 1
|
|
206
|
+
if _nr == 0:
|
|
207
|
+
obj.cmd = spli
|
|
208
|
+
continue
|
|
209
|
+
args.append(spli)
|
|
210
|
+
if args:
|
|
211
|
+
obj.args = args
|
|
212
|
+
obj.txt = obj.cmd or ""
|
|
213
|
+
obj.rest = " ".join(obj.args)
|
|
214
|
+
obj.txt = obj.cmd + " " + obj.rest
|
|
215
|
+
else:
|
|
216
|
+
obj.txt = obj.cmd or ""
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
"interface"
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def __dir__():
|
|
223
|
+
return (
|
|
224
|
+
'Commands',
|
|
225
|
+
'command',
|
|
226
|
+
'getmod',
|
|
227
|
+
'importer',
|
|
228
|
+
'md5sum',
|
|
229
|
+
'modules',
|
|
230
|
+
'parse',
|
|
231
|
+
'scan',
|
|
232
|
+
'scanner',
|
|
233
|
+
'table'
|
|
234
|
+
)
|