fixed plugin error message

This commit is contained in:
vabene1111 2023-07-03 05:55:12 +02:00
parent 766ed31f8e
commit 1e85c8587b

View File

@ -128,34 +128,36 @@ INSTALLED_APPS = [
'treebeard', 'treebeard',
] ]
PLUGINS_DIRECTORY = os.path.join(BASE_DIR, 'recipes', 'plugins')
PLUGINS = [] PLUGINS = []
try: try:
for d in os.listdir(os.path.join(BASE_DIR, 'recipes', 'plugins')): if os.path.isdir(PLUGINS_DIRECTORY):
if d != '__pycache__': for d in os.listdir():
try: if d != '__pycache__':
apps_path = f'recipes.plugins.{d}.apps' try:
__import__(apps_path) apps_path = f'recipes.plugins.{d}.apps'
app_config_classname = dir(sys.modules[apps_path])[1] __import__(apps_path)
plugin_module = f'recipes.plugins.{d}.apps.{app_config_classname}' app_config_classname = dir(sys.modules[apps_path])[1]
if plugin_module not in INSTALLED_APPS: plugin_module = f'recipes.plugins.{d}.apps.{app_config_classname}'
INSTALLED_APPS.append(plugin_module) if plugin_module not in INSTALLED_APPS:
plugin_class = getattr( INSTALLED_APPS.append(plugin_module)
sys.modules[apps_path], app_config_classname) plugin_class = getattr(
plugin_config = { sys.modules[apps_path], app_config_classname)
'name': plugin_class.verbose_name if hasattr(plugin_class, 'verbose_name') else plugin_class.name, plugin_config = {
'module': f'recipes.plugins.{d}', 'name': plugin_class.verbose_name if hasattr(plugin_class, 'verbose_name') else plugin_class.name,
'base_path': os.path.join(BASE_DIR, 'recipes', 'plugins', d), 'module': f'recipes.plugins.{d}',
'base_url': plugin_class.base_url, 'base_path': os.path.join(BASE_DIR, 'recipes', 'plugins', d),
'bundle_name': plugin_class.bundle_name if hasattr(plugin_class, 'bundle_name') else '', 'base_url': plugin_class.base_url,
'api_router_name': plugin_class.api_router_name if hasattr(plugin_class, 'api_router_name') else '', 'bundle_name': plugin_class.bundle_name if hasattr(plugin_class, 'bundle_name') else '',
'nav_main': plugin_class.nav_main if hasattr(plugin_class, 'nav_main') else '', 'api_router_name': plugin_class.api_router_name if hasattr(plugin_class, 'api_router_name') else '',
'nav_dropdown': plugin_class.nav_dropdown if hasattr(plugin_class, 'nav_dropdown') else '', 'nav_main': plugin_class.nav_main if hasattr(plugin_class, 'nav_main') else '',
} 'nav_dropdown': plugin_class.nav_dropdown if hasattr(plugin_class, 'nav_dropdown') else '',
PLUGINS.append(plugin_config) }
except Exception: PLUGINS.append(plugin_config)
if DEBUG: except Exception:
traceback.print_exc() if DEBUG:
print(f'ERROR failed to initialize plugin {d}') traceback.print_exc()
print(f'ERROR failed to initialize plugin {d}')
except Exception: except Exception:
if DEBUG: if DEBUG:
print('ERROR failed to initialize plugins') print('ERROR failed to initialize plugins')