forked from curtinlv/gd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
21 lines (19 loc) · 769 Bytes
/
utils.py
File metadata and controls
21 lines (19 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import sys
import importlib
import os
from . import logger
def load_module(module, path):
files = os.listdir(path)
for file in files:
try:
if file.endswith('.py') or file.endswith('.pyc'):
filename = file.replace('.pyc', '').replace('.py', '')
name = "jbot.{}.{}".format(module, filename)
spec = importlib.util.spec_from_file_location(name, path+file)
load = importlib.util.module_from_spec(spec)
spec.loader.exec_module(load)
sys.modules[f"jbot.{module}.{filename}"] = load
logger.info(f"加载成功 {filename}")
except Exception as e:
logger.info(f"加载失败 {file} {str(e)}")
continue