From b8a7d143d47556cbbee29ccc25b1d982f751d93b Mon Sep 17 00:00:00 2001 From: Jonathan Harris <jonathan@marginal.org.uk> Date: Thu, 9 Aug 2018 00:47:28 +0100 Subject: [PATCH] Pass plugin's folder to plugin_start() --- PLUGINS.md | 4 ++-- plug.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index b72149b5..6d60539c 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -22,11 +22,11 @@ Plugins are python files. The plugin folder must have a file named `load.py` tha EDMC will import the `load.py` file as a module and then call the `plugin_start()` function. ```python -def plugin_start(): +def plugin_start(plugin_dir): """ Load this plugin into EDMC """ - print "I am loaded!" + print "I am loaded! My plugin folder is {}".format(plugin_dir.encode("utf-8")) return "Test" ``` diff --git a/plug.py b/plug.py index e4e96b6a..01075644 100644 --- a/plug.py +++ b/plug.py @@ -83,7 +83,10 @@ class Plugin(object): with open(loadfile, 'rb') as plugfile: module = imp.load_module('plugin_%s' % name.encode('ascii', 'replace').replace('.', '_'), plugfile, loadfile.encode(sys.getfilesystemencoding()), ('.py', 'r', imp.PY_SOURCE)) - newname = module.plugin_start() + if module.plugin_start.func_code.co_argcount == 0: + newname = module.plugin_start() + else: + newname = module.plugin_start(os.path.dirname(loadfile)) self.name = newname and unicode(newname) or name self.module = module else: