80 lines
2.9 KiB
Python
80 lines
2.9 KiB
Python
#region Imports
|
|
import time, os, tomllib, sys
|
|
from plugin_base import PrivilegedPluginBase, SelfContainedPluginBase
|
|
|
|
from utils.Logger import Log
|
|
from utils.WatchdogHandler import DirWatcher
|
|
from utils.Scanner import scan
|
|
#endregion
|
|
|
|
#region Initialize
|
|
t = time.time()
|
|
with open("config.toml", "rb") as f:
|
|
data = tomllib.load(f)
|
|
|
|
Log.v(str(data))
|
|
path = data['DETECTION']['watchdogPath']
|
|
|
|
|
|
Log.v("""
|
|
|
|
o o 8
|
|
8b 8 8
|
|
8`b 8 .oPYo. o o .oPYo. 8
|
|
8 `b 8 8 8 Y. .P 8oooo8 8
|
|
8 `b8 8 8 `b..d' 8. 8
|
|
8 `8 `YooP' `YP' `Yooo' 8
|
|
..:::..:.....:::...:::.....:..
|
|
::::::::::::::::::::::::::::::
|
|
|
|
Product - ANTI-ABUSE
|
|
Release - {}
|
|
License - GNU GENERAL PUBLIC LICENSE, Version 3
|
|
|
|
""".format(data['ver']))
|
|
#endregion
|
|
|
|
def load_plugins(plugin_dir, scanner, logger, watchdog, config):
|
|
plugins = []
|
|
sys.path.insert(0, plugin_dir) # Add plugin directory to sys.path
|
|
|
|
for filename in os.listdir(plugin_dir):
|
|
if filename.endswith(".py") and filename != "__init__.py":
|
|
module_name = filename[:-3]
|
|
try:
|
|
module = __import__(module_name)
|
|
for attr in dir(module):
|
|
plugin_class = getattr(module, attr)
|
|
if isinstance(plugin_class, type):
|
|
if issubclass(plugin_class, PrivilegedPluginBase) and plugin_class is not PrivilegedPluginBase:
|
|
logger.s(f"Loaded privileged plugin {module_name}")
|
|
plugin_instance = plugin_class(module_name, scanner, logger, watchdog, config)
|
|
plugins.append(plugin_instance)
|
|
elif issubclass(plugin_class, SelfContainedPluginBase) and plugin_class is not SelfContainedPluginBase:
|
|
logger.s(f"Loaded self-contained plugin {module_name}")
|
|
restricted_scanner = lambda src: logger.e(f"Access denied to plugin {module_name}")
|
|
plugin_instance = plugin_class(module_name, restricted_scanner, logger, watchdog, config)
|
|
plugins.append(plugin_instance)
|
|
except Exception as e:
|
|
logger.e(f"Failed to load plugin {module_name}: {e}")
|
|
|
|
return plugins
|
|
|
|
if __name__ == "__main__":
|
|
logger = Log()
|
|
scanner = scan
|
|
watchdog = DirWatcher(path, interval=1)
|
|
|
|
logger.s(data['LANGUGAE']['english']['novelStarted'].format(str(round(time.time() - t, 1))))
|
|
try:
|
|
plugin_dir = "plugins"
|
|
plugins = load_plugins(plugin_dir, scanner, logger, watchdog, data)
|
|
for plugin in plugins:
|
|
plugin.execute()
|
|
with watchdog as watcher:
|
|
watcher.run()
|
|
except KeyboardInterrupt:
|
|
exit()
|
|
|
|
|