genocide 207__tar.gz → 210__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-207 → genocide-210}/PKG-INFO +1 -1
- genocide-207/genocide/__main__.py → genocide-210/bin/genocide +92 -115
- genocide-210/genocide/brokers.py +48 -0
- genocide-210/genocide/caching.py +111 -0
- genocide-210/genocide/clients.py +79 -0
- genocide-210/genocide/command.py +85 -0
- genocide-210/genocide/handler.py +90 -0
- genocide-210/genocide/methods.py +160 -0
- genocide-210/genocide/modules/flt.py +18 -0
- genocide-210/genocide/modules/fnd.py +32 -0
- genocide-210/genocide/modules/irc.py +643 -0
- genocide-210/genocide/modules/log.py +35 -0
- genocide-210/genocide/modules/lst.py +15 -0
- genocide-210/genocide/modules/mod.py +11 -0
- {genocide-207 → genocide-210}/genocide/modules/pth.py +2 -2
- {genocide-207 → genocide-210}/genocide/modules/req.py +1 -2
- genocide-210/genocide/modules/rss.py +508 -0
- genocide-210/genocide/modules/sil.py +19 -0
- genocide-210/genocide/modules/tdo.py +51 -0
- genocide-210/genocide/modules/thr.py +36 -0
- genocide-210/genocide/modules/upt.py +17 -0
- {genocide-207 → genocide-210}/genocide/objects.py +3 -59
- genocide-210/genocide/package.py +115 -0
- genocide-210/genocide/serials.py +46 -0
- genocide-207/genocide/runtime.py → genocide-210/genocide/threads.py +13 -34
- genocide-210/genocide/utility.py +164 -0
- genocide-210/genocide/workdir.py +118 -0
- {genocide-207 → genocide-210}/genocide.egg-info/PKG-INFO +1 -1
- genocide-210/genocide.egg-info/SOURCES.txt +86 -0
- {genocide-207 → genocide-210}/pyproject.toml +10 -14
- genocide-210/setup.py +13 -0
- genocide-207/genocide/__init__.py +0 -4
- genocide-207/genocide/command.py +0 -234
- genocide-207/genocide/handler.py +0 -238
- genocide-207/genocide/methods.py +0 -216
- genocide-207/genocide/modules/slg.py +0 -11
- genocide-207/genocide/modules/tbl.py +0 -18
- genocide-207/genocide/persist.py +0 -215
- genocide-207/genocide.egg-info/SOURCES.txt +0 -72
- genocide-207/genocide.egg-info/entry_points.txt +0 -2
- {genocide-207 → genocide-210}/README.rst +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/ECHAabilify.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/ECHAclozapine.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/ECHAhaldol.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/ECHAzyprexa.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/OTP111.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/OTP222.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/abilifypubchem.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/ack3.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/bevestigd.jpg +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/clozapinepubchem.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/genocide.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/haldolpubchem.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/informed.jpg +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/kamer2.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/skull3.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_images/zyprexapubchem.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/alabaster.css +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/basic.css +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/custom.css +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/doctools.js +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/documentation_options.js +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/file.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/genocide.css +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/language_data.js +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/minus.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/opensearch.xml +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/plus.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/pygments.css +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/searchtools.js +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/sitemap.xml +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/skull3.png +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/_static/sphinx_highlight.js +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/about.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/evidence.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/genindex-all.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/genindex.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/guilty.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/index.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/manual.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/objects.inv +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/pdf/EM_Ack_OTP-CR-117_19.pdf +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/pdf/EM_T04_OTP-CR-117_19.pdf +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/pdf/EM_T07_OTP-CR-117_19_001.pdf +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/pdf/Kamer.pdf +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/pdf/Rome-Statute.pdf +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/pdf/bevestigd.pdf +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/pubchem.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/reconsider.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/request.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/robots.txt +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/search.html +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/searchindex.js +0 -0
- {genocide-207/genocide/html → genocide-210/genocide/network}/writings.html +0 -0
- {genocide-207 → genocide-210}/genocide.egg-info/dependency_links.txt +0 -0
- {genocide-207 → genocide-210}/genocide.egg-info/top_level.txt +0 -0
- {genocide-207 → genocide-210}/setup.cfg +0 -0
|
@@ -1,45 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
1
2
|
# This file is placed in the Public Domain.
|
|
2
3
|
|
|
3
4
|
|
|
4
|
-
"main program"
|
|
5
|
-
|
|
6
|
-
|
|
7
5
|
import json
|
|
8
6
|
import logging
|
|
9
7
|
import os
|
|
10
8
|
import os.path
|
|
11
|
-
import pathlib
|
|
12
9
|
import sys
|
|
13
10
|
import time
|
|
14
|
-
import _thread
|
|
15
11
|
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
from .
|
|
21
|
-
from .
|
|
22
|
-
from .
|
|
23
|
-
from .
|
|
13
|
+
sys.path.insert(0, os.getcwd())
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from genocide.clients import Client
|
|
17
|
+
from genocide.command import Commands, command, scanner, table
|
|
18
|
+
from genocide.methods import parse
|
|
19
|
+
from genocide.handler import Event
|
|
20
|
+
from genocide.objects import update
|
|
21
|
+
from genocide.package import NAME, Mods
|
|
22
|
+
from genocide.package import getmod, inits, md5sum, modules, setdirs, sums
|
|
23
|
+
from genocide.utility import level, spl
|
|
24
|
+
from genocide.workdir import Workdir, moddir, pidfile, pidname, setwd
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
CHECKSUM = "
|
|
27
|
-
|
|
27
|
+
CHECKSUM = ""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
"config"
|
|
28
31
|
|
|
29
32
|
|
|
30
33
|
class Config:
|
|
31
34
|
|
|
32
|
-
debug
|
|
33
|
-
default
|
|
34
|
-
gets
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
debug = False
|
|
36
|
+
default = "irc,rss"
|
|
37
|
+
gets = {}
|
|
38
|
+
index = None
|
|
39
|
+
init = ""
|
|
40
|
+
level = "warn"
|
|
41
|
+
mod = ""
|
|
42
|
+
opts = ""
|
|
43
|
+
otxt = ""
|
|
44
|
+
sets = {}
|
|
45
|
+
verbose = False
|
|
46
|
+
version = 210
|
|
47
|
+
wdr = ""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
"clients"
|
|
43
51
|
|
|
44
52
|
|
|
45
53
|
class CLI(Client):
|
|
@@ -48,18 +56,12 @@ class CLI(Client):
|
|
|
48
56
|
Client.__init__(self)
|
|
49
57
|
self.register("command", command)
|
|
50
58
|
|
|
51
|
-
def announce(self, txt):
|
|
52
|
-
self.raw(txt)
|
|
53
|
-
|
|
54
59
|
def raw(self, txt):
|
|
55
60
|
out(txt.encode('utf-8', 'replace').decode("utf-8"))
|
|
56
61
|
|
|
57
62
|
|
|
58
63
|
class Console(CLI):
|
|
59
64
|
|
|
60
|
-
def announce(self, txt):
|
|
61
|
-
pass
|
|
62
|
-
|
|
63
65
|
def callback(self, event):
|
|
64
66
|
if not event.txt:
|
|
65
67
|
return
|
|
@@ -81,18 +83,18 @@ def background():
|
|
|
81
83
|
privileges()
|
|
82
84
|
boot(False)
|
|
83
85
|
pidfile(pidname(NAME))
|
|
84
|
-
inits(Config.init or Config.default)
|
|
86
|
+
inits(spl(Config.init or Config.default))
|
|
85
87
|
forever()
|
|
86
88
|
|
|
87
89
|
|
|
88
90
|
def console():
|
|
89
91
|
import readline # noqa: F401
|
|
90
92
|
boot()
|
|
91
|
-
for _mod, thr in inits(Config.init):
|
|
93
|
+
for _mod, thr in inits(spl(Config.init)):
|
|
92
94
|
if "w" in Config.opts:
|
|
93
95
|
thr.join(30.0)
|
|
94
96
|
csl = Console()
|
|
95
|
-
csl.start(
|
|
97
|
+
csl.start()
|
|
96
98
|
forever()
|
|
97
99
|
|
|
98
100
|
|
|
@@ -116,7 +118,8 @@ def service():
|
|
|
116
118
|
privileges()
|
|
117
119
|
boot(False)
|
|
118
120
|
pidfile(pidname(NAME))
|
|
119
|
-
|
|
121
|
+
banner()
|
|
122
|
+
inits(spl(Config.init or Config.default))
|
|
120
123
|
forever()
|
|
121
124
|
|
|
122
125
|
|
|
@@ -124,73 +127,23 @@ def boot(doparse=True):
|
|
|
124
127
|
if doparse:
|
|
125
128
|
parse(Config, " ".join(sys.argv[1:]))
|
|
126
129
|
update(Config, Config.sets, empty=False)
|
|
127
|
-
|
|
128
|
-
Commands.mod = Config.mod = "mods"
|
|
129
|
-
if "a" in Config.opts:
|
|
130
|
-
Config.init = ",".join(modules())
|
|
130
|
+
Workdir.wdr = Config.wdr
|
|
131
131
|
level(Config.level)
|
|
132
|
+
setwd(NAME)
|
|
133
|
+
if "m" in Config.opts:
|
|
134
|
+
Mods.dir("mods", "mods")
|
|
135
|
+
if "n" in Config.opts:
|
|
136
|
+
Mods.dir("network")
|
|
137
|
+
setdirs("n" in Config.opts, "m" in Config.opts)
|
|
132
138
|
if "v" in Config.opts:
|
|
133
139
|
banner()
|
|
134
|
-
|
|
140
|
+
if "a" in Config.opts:
|
|
141
|
+
Config.init = ",".join(modules())
|
|
142
|
+
sums(CHECKSUM)
|
|
135
143
|
table(CHECKSUM)
|
|
136
144
|
Commands.add(cmd)
|
|
137
145
|
Commands.add(ver)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
"daemon"
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def daemon(verbose=False):
|
|
144
|
-
pid = os.fork()
|
|
145
|
-
if pid != 0:
|
|
146
|
-
os._exit(0)
|
|
147
|
-
os.setsid()
|
|
148
|
-
pid2 = os.fork()
|
|
149
|
-
if pid2 != 0:
|
|
150
|
-
os._exit(0)
|
|
151
|
-
if not verbose:
|
|
152
|
-
with open('/dev/null', 'r', encoding="utf-8") as sis:
|
|
153
|
-
os.dup2(sis.fileno(), sys.stdin.fileno())
|
|
154
|
-
with open('/dev/null', 'a+', encoding="utf-8") as sos:
|
|
155
|
-
os.dup2(sos.fileno(), sys.stdout.fileno())
|
|
156
|
-
with open('/dev/null', 'a+', encoding="utf-8") as ses:
|
|
157
|
-
os.dup2(ses.fileno(), sys.stderr.fileno())
|
|
158
|
-
os.umask(0)
|
|
159
|
-
os.chdir("/")
|
|
160
|
-
os.nice(10)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def inits(names):
|
|
164
|
-
modz = []
|
|
165
|
-
for name in sorted(spl(names)):
|
|
166
|
-
try:
|
|
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)
|
|
175
|
-
_thread.interrupt_main()
|
|
176
|
-
return modz
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def pidfile(filename):
|
|
180
|
-
if os.path.exists(filename):
|
|
181
|
-
os.unlink(filename)
|
|
182
|
-
path2 = pathlib.Path(filename)
|
|
183
|
-
path2.parent.mkdir(parents=True, exist_ok=True)
|
|
184
|
-
with open(filename, "w", encoding="utf-8") as fds:
|
|
185
|
-
fds.write(str(os.getpid()))
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
def privileges():
|
|
189
|
-
import getpass
|
|
190
|
-
import pwd
|
|
191
|
-
pwnam2 = pwd.getpwnam(getpass.getuser())
|
|
192
|
-
os.setgid(pwnam2.pw_gid)
|
|
193
|
-
os.setuid(pwnam2.pw_uid)
|
|
146
|
+
logging.info("workdir is %s", Workdir.wdr)
|
|
194
147
|
|
|
195
148
|
|
|
196
149
|
"commands"
|
|
@@ -215,8 +168,7 @@ def srv(event):
|
|
|
215
168
|
|
|
216
169
|
|
|
217
170
|
def tbl(event):
|
|
218
|
-
|
|
219
|
-
Commands.names = {}
|
|
171
|
+
Commands.names = {}
|
|
220
172
|
scanner()
|
|
221
173
|
event.reply("# This file is placed in the Public Domain.")
|
|
222
174
|
event.reply("")
|
|
@@ -226,6 +178,7 @@ def tbl(event):
|
|
|
226
178
|
event.reply("")
|
|
227
179
|
event.reply(f"NAMES = {json.dumps(Commands.names, indent=4, sort_keys=True)}")
|
|
228
180
|
event.reply("")
|
|
181
|
+
event.reply("")
|
|
229
182
|
event.reply("MD5 = {")
|
|
230
183
|
for module in scanner():
|
|
231
184
|
event.reply(f' "{module.__name__.split(".")[-1]}": "{md5sum(module.__file__)}",')
|
|
@@ -241,7 +194,7 @@ def ver(event):
|
|
|
241
194
|
|
|
242
195
|
def banner():
|
|
243
196
|
tme = time.ctime(time.time()).replace(" ", " ")
|
|
244
|
-
out(
|
|
197
|
+
out("%s %s since %s (%s)" % (NAME.upper(), Config.version, tme, Config.level.upper()))
|
|
245
198
|
|
|
246
199
|
|
|
247
200
|
def check(txt):
|
|
@@ -255,6 +208,26 @@ def check(txt):
|
|
|
255
208
|
return False
|
|
256
209
|
|
|
257
210
|
|
|
211
|
+
def daemon(verbose=False):
|
|
212
|
+
pid = os.fork()
|
|
213
|
+
if pid != 0:
|
|
214
|
+
os._exit(0)
|
|
215
|
+
os.setsid()
|
|
216
|
+
pid2 = os.fork()
|
|
217
|
+
if pid2 != 0:
|
|
218
|
+
os._exit(0)
|
|
219
|
+
if not verbose:
|
|
220
|
+
with open('/dev/null', 'r', encoding="utf-8") as sis:
|
|
221
|
+
os.dup2(sis.fileno(), sys.stdin.fileno())
|
|
222
|
+
with open('/dev/null', 'a+', encoding="utf-8") as sos:
|
|
223
|
+
os.dup2(sos.fileno(), sys.stdout.fileno())
|
|
224
|
+
with open('/dev/null', 'a+', encoding="utf-8") as ses:
|
|
225
|
+
os.dup2(ses.fileno(), sys.stderr.fileno())
|
|
226
|
+
os.umask(0)
|
|
227
|
+
os.chdir("/")
|
|
228
|
+
os.nice(10)
|
|
229
|
+
|
|
230
|
+
|
|
258
231
|
def forever():
|
|
259
232
|
while True:
|
|
260
233
|
try:
|
|
@@ -268,21 +241,12 @@ def out(txt):
|
|
|
268
241
|
sys.stdout.flush()
|
|
269
242
|
|
|
270
243
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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"""
|
|
244
|
+
def privileges():
|
|
245
|
+
import getpass
|
|
246
|
+
import pwd
|
|
247
|
+
pwnam2 = pwd.getpwnam(getpass.getuser())
|
|
248
|
+
os.setgid(pwnam2.pw_gid)
|
|
249
|
+
os.setuid(pwnam2.pw_uid)
|
|
286
250
|
|
|
287
251
|
|
|
288
252
|
"runtime"
|
|
@@ -293,7 +257,6 @@ def wrapped(func):
|
|
|
293
257
|
func()
|
|
294
258
|
except (KeyboardInterrupt, EOFError):
|
|
295
259
|
out("")
|
|
296
|
-
Fleet.shutdown()
|
|
297
260
|
|
|
298
261
|
|
|
299
262
|
def wrap(func):
|
|
@@ -321,5 +284,19 @@ def main():
|
|
|
321
284
|
wrapped(control)
|
|
322
285
|
|
|
323
286
|
|
|
287
|
+
TXT = """[Unit]
|
|
288
|
+
Description=%s
|
|
289
|
+
After=network-online.target
|
|
290
|
+
|
|
291
|
+
[Service]
|
|
292
|
+
Type=simple
|
|
293
|
+
User=%s
|
|
294
|
+
Group=%s
|
|
295
|
+
ExecStart=/home/%s/.local/bin/%s -s
|
|
296
|
+
|
|
297
|
+
[Install]
|
|
298
|
+
WantedBy=multi-user.target"""
|
|
299
|
+
|
|
300
|
+
|
|
324
301
|
if __name__ == "__main__":
|
|
325
302
|
main()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# This file is placed in the Public Domain.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
"client for a string"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Fleet:
|
|
8
|
+
|
|
9
|
+
clients = {}
|
|
10
|
+
|
|
11
|
+
@staticmethod
|
|
12
|
+
def add(client):
|
|
13
|
+
Fleet.clients[repr(client)] = client
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def all():
|
|
17
|
+
return Fleet.clients.values()
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def announce(txt):
|
|
21
|
+
for client in Fleet.all():
|
|
22
|
+
client.announce(txt)
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def display(evt):
|
|
26
|
+
client = Fleet.get(evt.orig)
|
|
27
|
+
client.display(evt)
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def get(orig):
|
|
31
|
+
return Fleet.clients.get(orig, None)
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def say(orig, channel, txt):
|
|
35
|
+
client = Fleet.get(orig)
|
|
36
|
+
client.say(channel, txt)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def shutdown():
|
|
40
|
+
for client in Fleet.all():
|
|
41
|
+
client.wait()
|
|
42
|
+
client.stop()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def __dir__():
|
|
46
|
+
return (
|
|
47
|
+
'Fleet',
|
|
48
|
+
)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# This file is placed in the Public Domain.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
"object for a string"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import json.decoder
|
|
8
|
+
import os
|
|
9
|
+
import threading
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from .methods import deleted, search
|
|
13
|
+
from .objects import Object, update
|
|
14
|
+
from .serials import dump, load
|
|
15
|
+
from .workdir import cdir, fqn, getpath, j, long, store
|
|
16
|
+
from .utility import fntime
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
lock = threading.RLock()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Cache:
|
|
23
|
+
|
|
24
|
+
objs = {}
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def add(path, obj):
|
|
28
|
+
Cache.objs[path] = obj
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def get(path):
|
|
32
|
+
return Cache.objs.get(path, None)
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def update(path, obj):
|
|
36
|
+
if path in Cache.objs:
|
|
37
|
+
update(Cache.objs[path], obj)
|
|
38
|
+
else:
|
|
39
|
+
Cache.add(path, obj)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def find(clz, selector=None, removed=False, matching=False):
|
|
43
|
+
clz = long(clz)
|
|
44
|
+
if selector is None:
|
|
45
|
+
selector = {}
|
|
46
|
+
for pth in fns(clz):
|
|
47
|
+
obj = Cache.get(pth)
|
|
48
|
+
if not obj:
|
|
49
|
+
obj = Object()
|
|
50
|
+
read(obj, pth)
|
|
51
|
+
Cache.add(pth, obj)
|
|
52
|
+
if not removed and deleted(obj):
|
|
53
|
+
continue
|
|
54
|
+
if selector and not search(obj, selector, matching):
|
|
55
|
+
continue
|
|
56
|
+
yield pth, obj
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def fns(clz):
|
|
60
|
+
pth = store(clz)
|
|
61
|
+
for rootdir, dirs, _files in os.walk(pth, topdown=False):
|
|
62
|
+
for dname in dirs:
|
|
63
|
+
ddd = j(rootdir, dname)
|
|
64
|
+
for fll in os.listdir(ddd):
|
|
65
|
+
yield j(ddd, fll)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def last(obj, selector=None):
|
|
69
|
+
if selector is None:
|
|
70
|
+
selector = {}
|
|
71
|
+
result = sorted(
|
|
72
|
+
find(fqn(obj), selector),
|
|
73
|
+
key=lambda x: fntime(x[0])
|
|
74
|
+
)
|
|
75
|
+
res = ""
|
|
76
|
+
if result:
|
|
77
|
+
inp = result[-1]
|
|
78
|
+
update(obj, inp[-1])
|
|
79
|
+
res = inp[0]
|
|
80
|
+
return res
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def read(obj, path):
|
|
84
|
+
with lock:
|
|
85
|
+
with open(path, "r", encoding="utf-8") as fpt:
|
|
86
|
+
try:
|
|
87
|
+
update(obj, load(fpt))
|
|
88
|
+
except json.decoder.JSONDecodeError as ex:
|
|
89
|
+
ex.add_note(path)
|
|
90
|
+
raise ex
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def write(obj, path=None):
|
|
94
|
+
with lock:
|
|
95
|
+
if path is None:
|
|
96
|
+
path = getpath(obj)
|
|
97
|
+
cdir(path)
|
|
98
|
+
with open(path, "w", encoding="utf-8") as fpt:
|
|
99
|
+
dump(obj, fpt, indent=4)
|
|
100
|
+
Cache.update(path, obj)
|
|
101
|
+
return path
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def __dir__():
|
|
105
|
+
return (
|
|
106
|
+
'Cache',
|
|
107
|
+
'find',
|
|
108
|
+
'last',
|
|
109
|
+
'read',
|
|
110
|
+
'write'
|
|
111
|
+
)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# This file is placed in the Public Domain.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
"client events"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import queue
|
|
8
|
+
import threading
|
|
9
|
+
import _thread
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from .brokers import Fleet
|
|
13
|
+
from .handler import Handler
|
|
14
|
+
from .threads import launch
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Client(Handler):
|
|
18
|
+
|
|
19
|
+
def __init__(self):
|
|
20
|
+
Handler.__init__(self)
|
|
21
|
+
self.olock = threading.RLock()
|
|
22
|
+
self.oqueue = queue.Queue()
|
|
23
|
+
self.silent = True
|
|
24
|
+
Fleet.add(self)
|
|
25
|
+
|
|
26
|
+
def announce(self, txt):
|
|
27
|
+
if not self.silent:
|
|
28
|
+
self.raw(txt)
|
|
29
|
+
|
|
30
|
+
def display(self, event):
|
|
31
|
+
with self.olock:
|
|
32
|
+
for tme in sorted(event.result):
|
|
33
|
+
self.dosay(
|
|
34
|
+
event.channel,
|
|
35
|
+
event.result[tme]
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def dosay(self, channel, txt):
|
|
39
|
+
self.say(channel, txt)
|
|
40
|
+
|
|
41
|
+
def raw(self, txt):
|
|
42
|
+
raise NotImplementedError("raw")
|
|
43
|
+
|
|
44
|
+
def say(self, channel, txt):
|
|
45
|
+
self.raw(txt)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Output(Client):
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def output(self):
|
|
52
|
+
while True:
|
|
53
|
+
event = self.oqueue.get()
|
|
54
|
+
if event is None:
|
|
55
|
+
self.oqueue.task_done()
|
|
56
|
+
break
|
|
57
|
+
self.display(event)
|
|
58
|
+
self.oqueue.task_done()
|
|
59
|
+
|
|
60
|
+
def start(self):
|
|
61
|
+
launch(self.output)
|
|
62
|
+
super().start()
|
|
63
|
+
|
|
64
|
+
def stop(self):
|
|
65
|
+
self.oqueue.put(None)
|
|
66
|
+
super().stop()
|
|
67
|
+
|
|
68
|
+
def wait(self):
|
|
69
|
+
try:
|
|
70
|
+
self.oqueue.join()
|
|
71
|
+
except Exception:
|
|
72
|
+
_thread.interrupt_main()
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def __dir__():
|
|
76
|
+
return (
|
|
77
|
+
'Client',
|
|
78
|
+
'Output'
|
|
79
|
+
)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# This file is placed in the Public Domain.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
"write your own commands"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import inspect
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from .brokers import Fleet
|
|
11
|
+
from .methods import parse
|
|
12
|
+
from .package import getmod, modules
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Commands:
|
|
16
|
+
|
|
17
|
+
cmds = {}
|
|
18
|
+
names = {}
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def add(func) -> None:
|
|
22
|
+
name = func.__name__
|
|
23
|
+
modname = func.__module__.split(".")[-1]
|
|
24
|
+
Commands.cmds[name] = func
|
|
25
|
+
Commands.names[name] = modname
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def get(cmd):
|
|
29
|
+
func = Commands.cmds.get(cmd, None)
|
|
30
|
+
if func:
|
|
31
|
+
return func
|
|
32
|
+
name = Commands.names.get(cmd, None)
|
|
33
|
+
if name:
|
|
34
|
+
module = getmod(name)
|
|
35
|
+
if module:
|
|
36
|
+
scan(module)
|
|
37
|
+
return Commands.cmds.get(cmd, None)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def command(evt):
|
|
41
|
+
parse(evt)
|
|
42
|
+
func = Commands.get(evt.cmd)
|
|
43
|
+
if func:
|
|
44
|
+
func(evt)
|
|
45
|
+
Fleet.display(evt)
|
|
46
|
+
evt.ready()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def scan(module):
|
|
50
|
+
for key, cmdz in inspect.getmembers(module, inspect.isfunction):
|
|
51
|
+
if key.startswith("cb"):
|
|
52
|
+
continue
|
|
53
|
+
if 'event' in inspect.signature(cmdz).parameters:
|
|
54
|
+
Commands.add(cmdz)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def scanner(names=[]):
|
|
58
|
+
res = []
|
|
59
|
+
for nme in sorted(modules()):
|
|
60
|
+
if names and nme not in names:
|
|
61
|
+
continue
|
|
62
|
+
module = getmod(nme)
|
|
63
|
+
if not module:
|
|
64
|
+
continue
|
|
65
|
+
scan(module)
|
|
66
|
+
res.append(module)
|
|
67
|
+
return res
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def table(checksum=""):
|
|
71
|
+
tbl = getmod("tbl")
|
|
72
|
+
if tbl and "NAMES" in dir(tbl):
|
|
73
|
+
Commands.names.update(tbl.NAMES)
|
|
74
|
+
else:
|
|
75
|
+
scanner()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def __dir__():
|
|
79
|
+
return (
|
|
80
|
+
'Commands',
|
|
81
|
+
'command',
|
|
82
|
+
'scan',
|
|
83
|
+
'scanner',
|
|
84
|
+
'table'
|
|
85
|
+
)
|