2022-05-22 22:47:33 +01:00
|
|
|
import pathlib
|
2022-05-28 16:15:19 +01:00
|
|
|
import subprocess
|
2022-07-30 21:33:31 +01:00
|
|
|
import asyncio
|
|
|
|
import os
|
2022-04-18 22:21:51 +01:00
|
|
|
|
2022-07-30 21:33:31 +01:00
|
|
|
HOME_DIR = str(pathlib.Path(os.getcwd()).parent.parent.resolve())
|
|
|
|
PARENT_DIR = str(pathlib.Path(__file__).parent.resolve())
|
2022-04-30 02:01:24 +01:00
|
|
|
|
2022-04-21 19:01:49 +01:00
|
|
|
class Plugin:
|
2022-07-30 21:33:31 +01:00
|
|
|
backend_proc = None
|
2022-04-18 22:21:51 +01:00
|
|
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
|
|
|
async def _main(self):
|
2022-07-30 21:33:31 +01:00
|
|
|
# startup
|
2023-02-10 22:22:26 +00:00
|
|
|
print("PowerTools starting...")
|
2023-02-22 02:28:59 +00:00
|
|
|
env_proc = dict(os.environ)
|
|
|
|
if "LD_LIBRARY_PATH" in env_proc:
|
|
|
|
env_proc["LD_LIBRARY_PATH"] += ":"+PARENT_DIR+"/bin"
|
|
|
|
else:
|
|
|
|
env_proc["LD_LIBRARY_PATH"] = ":"+PARENT_DIR+"/bin"
|
2023-02-11 04:36:22 +00:00
|
|
|
self.backend_proc = subprocess.Popen(
|
|
|
|
[PARENT_DIR + "/bin/backend"],
|
2023-02-22 02:28:59 +00:00
|
|
|
env = env_proc)
|
2022-05-13 19:01:48 +01:00
|
|
|
while True:
|
2022-09-01 01:18:15 +01:00
|
|
|
await asyncio.sleep(1)
|
2023-02-10 22:22:26 +00:00
|
|
|
|
|
|
|
async def _unload(self):
|
|
|
|
# shutdown
|
|
|
|
print("PowerTools unloading...")
|
|
|
|
if self.backend_proc is not None:
|
|
|
|
self.backend_proc.terminate()
|
|
|
|
try:
|
|
|
|
self.backend_proc.wait(timeout=5) # 5 seconds timeout
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
self.backend_proc.kill()
|
|
|
|
self.backend_proc = None
|