Skip to content

Plugin info update #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 12, 2017
Prev Previous commit
Next Next commit
Added possibility to use __name__ to retrieve its own plugin instace
  • Loading branch information
Ayuto committed Jan 2, 2017
commit ea727307905751499eb6b4280fca7a79df265736
15 changes: 15 additions & 0 deletions addons/source-python/packages/source-python/plugins/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,34 @@ def plugins_directory(self):
def is_loaded(self, plugin_name):
"""Return whether or not a plugin is loaded.

:param str plugin_name:
The plugin to check.
:rtype: bool
"""
return plugin_name in self

def plugin_exists(self, plugin_name):
"""Return whether of not a plugin exists.

:param str plugin_name:
The plugin to check.
:rtype: bool
"""
return self.get_plugin_directory(plugin_name).isdir()

def get_plugin_instance(self, plugin_name):
"""Return a plugin's instance, if it is loaded.

:param str plugin_name:
The plugin to check. You can pass ``__name__`` from one of your
plugin files to retrieve its own plugin instance.
:rtype: LoadedPlugin
"""
# This allows passing __name__ to this method
if plugin_name.startswith(self.base_import):
plugin_name = plugin_name.replace(
self.base_import, '', 1).split('.', 1)[0]

if plugin_name in self:
return self[plugin_name]

Expand All @@ -207,6 +219,9 @@ def get_plugin_directory(self, plugin_name):
def get_plugin_info(self, plugin_name):
"""Return information about the given plugin.

:param str plugin_name:
The plugin to check. You can pass ``__name__`` from one of your
plugin files to retrieve its own plugin instance.
:rtype: PluginInfo
"""
plugin = self.get_plugin_instance(plugin_name)
Expand Down