Seregon/PkgToolBox

Toolbox for analyzing and editing pkg application files for psp,ps3, ps4 and ps5, includes the most useful functions you might need.

Python/57.3 KB/No license
GraphicUserInterface/plugins/__init__.py
1import os
2import importlib
3import logging
4 
5class PluginManager:
6 def __init__(self):
7 self.plugins = {}
8 self.plugin_dir = os.path.join(os.path.dirname(__file__), 'plugins')
9 self.load_plugins()
10
11 def load_plugins(self):
12 """Load all plugins from plugins directory"""
13 if not os.path.exists(self.plugin_dir):
14 os.makedirs(self.plugin_dir)
15
16 for file in os.listdir(self.plugin_dir):
17 if file.endswith('.py') and not file.startswith('_'):
18 try:
19 module_name = file[:-3]
20 spec = importlib.util.spec_from_file_location(
21 module_name,
22 os.path.join(self.plugin_dir, file)
23 )
24 module = importlib.util.module_from_spec(spec)
25 spec.loader.exec_module(module)
26
27 if hasattr(module, 'register_plugin'):
28 plugin = module.register_plugin()
29 self.plugins[plugin.name] = plugin
30 logging.info(f"Loaded plugin: {plugin.name}")
31 except Exception as e:
32 logging.error(f"Failed to load plugin {file}: {str(e)}")