PluginManager: get plugins path via import

* skip __pycache__ when loading
This commit is contained in:
redfish 2019-04-07 18:50:23 -04:00
parent 226f7dea65
commit 73814550e5
2 changed files with 6 additions and 1 deletions

0
plugins/__init__.py Normal file
View File

View File

@ -7,13 +7,16 @@ from collections import defaultdict
from Debug import Debug from Debug import Debug
from Config import config from Config import config
import plugins
import importlib import importlib
class PluginManager: class PluginManager:
def __init__(self): def __init__(self):
self.log = logging.getLogger("PluginManager") self.log = logging.getLogger("PluginManager")
self.plugin_path = "plugins" # Plugin directory self.plugin_path = os.path.abspath(os.path.dirname(plugins.__file__))
self.plugins = defaultdict(list) # Registered plugins (key: class name, value: list of plugins for class) self.plugins = defaultdict(list) # Registered plugins (key: class name, value: list of plugins for class)
self.subclass_order = {} # Record the load order of the plugins, to keep it after reload self.subclass_order = {} # Record the load order of the plugins, to keep it after reload
self.pluggable = {} self.pluggable = {}
@ -40,6 +43,8 @@ class PluginManager:
s = time.time() s = time.time()
for dir_name in sorted(os.listdir(self.plugin_path)): for dir_name in sorted(os.listdir(self.plugin_path)):
dir_path = os.path.join(self.plugin_path, dir_name) dir_path = os.path.join(self.plugin_path, dir_name)
if dir_name == "__pycache__":
continue # skip
if dir_name.startswith("disabled"): if dir_name.startswith("disabled"):
continue # Dont load if disabled continue # Dont load if disabled
if not os.path.isdir(dir_path): if not os.path.isdir(dir_path):