mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 17:42:20 +03:00
plug.py: Some docstrings, change to plugin loading
* Plugin loading: Avoid using .format()
This commit is contained in:
parent
8628efa0a1
commit
413b2f06f8
24
plug.py
24
plug.py
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""Plugin API."""
|
||||||
Plugin hooks for EDMC - Ian Norton, Jonathan Harris
|
|
||||||
"""
|
|
||||||
import copy
|
import copy
|
||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
@ -29,15 +27,17 @@ last_error = {
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(object):
|
class Plugin(object):
|
||||||
|
"""An EDMC plugin."""
|
||||||
|
|
||||||
def __init__(self, name: str, loadfile: str, plugin_logger: Optional[logging.Logger]):
|
def __init__(self, name: str, loadfile: str, plugin_logger: Optional[logging.Logger]):
|
||||||
"""
|
"""
|
||||||
Load a single plugin
|
Load a single plugin.
|
||||||
:param name: module name
|
|
||||||
:param loadfile: the main .py file
|
:param name: Base name of the file being loaded from.
|
||||||
|
:param loadfile: Full path/filename of the plugin.
|
||||||
|
:param plugin_logger: The logging instance for this plugin to use.
|
||||||
:raises Exception: Typically ImportError or OSError
|
:raises Exception: Typically ImportError or OSError
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.name = name # Display name.
|
self.name = name # Display name.
|
||||||
self.folder = name # basename of plugin folder. None for internal plugins.
|
self.folder = name # basename of plugin folder. None for internal plugins.
|
||||||
self.module = None # None for disabled plugins.
|
self.module = None # None for disabled plugins.
|
||||||
@ -46,9 +46,13 @@ class Plugin(object):
|
|||||||
if loadfile:
|
if loadfile:
|
||||||
logger.info(f'loading plugin "{name.replace(".", "_")}" from "{loadfile}"')
|
logger.info(f'loading plugin "{name.replace(".", "_")}" from "{loadfile}"')
|
||||||
try:
|
try:
|
||||||
module = importlib.machinery.SourceFileLoader('plugin_{}'.format(
|
filename = 'plugin_'
|
||||||
name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_')),
|
filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_')
|
||||||
loadfile).load_module()
|
module = importlib.machinery.SourceFileLoader(
|
||||||
|
filename,
|
||||||
|
loadfile
|
||||||
|
).load_module()
|
||||||
|
|
||||||
if getattr(module, 'plugin_start3', None):
|
if getattr(module, 'plugin_start3', None):
|
||||||
newname = module.plugin_start3(os.path.dirname(loadfile))
|
newname = module.plugin_start3(os.path.dirname(loadfile))
|
||||||
self.name = newname and str(newname) or name
|
self.name = newname and str(newname) or name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user