From 3f8fcc359d7ecac482b87b37a929f94ede9ca932 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 7 Aug 2023 16:40:38 +0800 Subject: [PATCH] bugfix --- ahserver/configuredServer.py | 3 ++- ahserver/loadplugins.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 ahserver/loadplugins.py diff --git a/ahserver/configuredServer.py b/ahserver/configuredServer.py index ac60eb0..14141c8 100755 --- a/ahserver/configuredServer.py +++ b/ahserver/configuredServer.py @@ -16,6 +16,7 @@ from .auth_api import AuthAPI from .myTE import setupTemplateEngine from .globalEnv import initEnv from .filestorage import TmpFileRecord +from .loadplugins import load_plugins class ConfiguredServer(AppLogger): def __init__(self, auth_klass=AuthAPI, workdir=None): @@ -37,7 +38,7 @@ class ConfiguredServer(AppLogger): if config.website.client_max_size: client_max_size = config.website.client_max_size - print(f'{client_max_size=}') + load_plugins(self.workdir) self.app = web.Application(client_max_size=client_max_size) async def init_auth(self): diff --git a/ahserver/loadplugins.py b/ahserver/loadplugins.py new file mode 100644 index 0000000..47d6774 --- /dev/null +++ b/ahserver/loadplugins.py @@ -0,0 +1,21 @@ +import os +import sys + +from appPublic.folderUtils import listFile +from appPublic.ExecFile import ExecFile +from ahserver.serverenv import ServerEnv + +def load_plugins(p_dir): + ef = ExecFile() + pdir = os.path.join(p_dir, 'plugins') + if not os.path.isdir(pdir): + print('load_plugins:%s not exists' % pdir) + return + sys.path.append(pdir) + ef.set('sys',sys) + ef.set('ServerEnv', ServerEnv) + for m in listFile(pdir, subfixs='.py'): + if m.endswith('__init__.py'): + continue + __import__(m[:-3], locals(), globals()) +