aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/core
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-07-04 13:51:48 +0800
committerGitHub <noreply@github.com>2023-07-04 13:51:48 +0800
commit491c8642b821f67f12e53ee4ef1e86734d415e91 (patch)
treed276b849316a92f96464c4eb87b74c458f215e02 /core
parent6bd2f18eb7ecb82c5fe9c08a5eb89c1fe0ac9f58 (diff)
downloadinfini-491c8642b821f67f12e53ee4ef1e86734d415e91.tar.gz
infini-491c8642b821f67f12e53ee4ef1e86734d415e91.zip
Rename rule.py to rule.py
Diffstat (limited to 'core')
-rw-r--r--core/rule.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/rule.py b/core/rule.py
new file mode 100644
index 00000000..bdc24369
--- /dev/null
+++ b/core/rule.py
@@ -0,0 +1,30 @@
+import os
+import importlib.util
+
+__all__ = ["Rule"]
+
+class Rule:
+ def __init__(self, folder_path):
+ self.folder_path = folder_path
+
+ def load_modules(self):
+ # 获取指定文件夹下的所有文件和文件夹
+ file_list = os.listdir(self.folder_path)
+ module_list = []
+
+ # 遍历文件列表
+ for file_name in file_list:
+ file_path = os.path.join(self.folder_path, file_name)
+
+ # 判断是否为Python文件或者包
+ if file_name.startswith('_') or not file_name.endswith(".py"):
+ continue
+
+ # 尝试加载模块
+ module_name = os.path.splitext(file_name)[0]
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ module_list.append(module)
+
+ return module_list