Skip to content

Commit

Permalink
fix up some code; fix primary iteration issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lacraig2 authored and Andrew Fasano committed Sep 13, 2023
1 parent f102126 commit 9dd93c2
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions panda/python/core/pandare/pypluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def set(self, k, v):
self.data[k] = v

def __str__(self):
return str([x for x in self.data.keys()])
return str(list(self.data.keys()))

def __getattr__(self, name):
raise NotImplementedError("Subclass must implement this virtual method")
Expand Down Expand Up @@ -215,7 +215,7 @@ def load(self, pluginclasses, args=None, template_dir=None):

bp = self.blueprint(name, __name__, template_folder=template_dir)
self.plugins[name].webserver_init(bp)
self.app.register_blueprint(bp, url_prefix="/" + name)
self.app.register_blueprint(bp, url_prefix=f"/{name}")

def load_all(self, plugin_file, args=None, template_dir=None):
'''
Expand Down Expand Up @@ -249,35 +249,25 @@ def load_all(self, plugin_file, args=None, template_dir=None):
return names

def unload(self, pluginclass, do_del=True):
if isinstance(pluginclass, str):
name = pluginclass
else:
name = pluginclass.__name__

name = pluginclass if isinstance(pluginclass, str) else pluginclass.__name__
if callable(getattr(self.plugins[name], "uninit", None)):
self.plugins[name].uninit()

if do_del:
del self.plugins[name]

def unload_all(self):
for name in self.plugins.keys():
while self.plugins:
name, _ = self.plugins.popitem()
self.unload(name, do_del=False)
self.plugins.clear()

def is_loaded(self, pluginclass):
if isinstance(pluginclass, str):
name = pluginclass
else:
name = pluginclass.__name__
name = pluginclass if isinstance(pluginclass, str) else pluginclass.__name__
return name in self.plugins

def get_plugin(self, pluginclass):
# Lookup name
if isinstance(pluginclass, str):
name = pluginclass
else:
name = pluginclass.__name__
name = pluginclass if isinstance(pluginclass, str) else pluginclass.__name__
if not self.is_loaded(pluginclass, name):
raise ValueError(f"Plugin {name} is not loaded")
return self.plugins[name]
Expand Down

0 comments on commit 9dd93c2

Please sign in to comment.