You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
git-test/plugin_manage/loader.py

24 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Zxy导入os模块用于操作路径
import os
# Zxy导入日志模块
import logging
# Zxy导入Django的配置模块
from django.conf import settings
# Zxy获取日志记录器
logger = logging.getLogger(__name__)
# Zxy动态加载插件
def load_plugins():
"""
Dynamically loads and initializes plugins from the 'plugins' directory.
This function is intended to be called when the Django app registry is ready.
"""
for plugin_name in settings.ACTIVE_PLUGINS: # Zxy遍历激活的插件
plugin_path = os.path.join(settings.PLUGINS_DIR, plugin_name) # Zxy获取插件路径
if os.path.isdir(plugin_path) and os.path.exists(os.path.join(plugin_path, 'plugin.py')): # Zxy检查插件目录和文件
try:
__import__(f'plugins.{plugin_name}.plugin') # Zxy动态导入插件模块
logger.info(f"Successfully loaded plugin: {plugin_name}") # Zxy记录加载成功日志
except ImportError as e:
logger.error(f"Failed to import plugin: {plugin_name}", exc_info=e) # Zxy记录加载失败日志