diff --git a/PLUGINS.md b/PLUGINS.md index 5338eac8..da2367e6 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -1,12 +1,18 @@ # EDMC Plugins -Market Connector Plugins allow you to customise and extend the behavior of EDMC. +Plugins allow you to customise and extend the behavior of EDMC. # Writing a Plugin Plugins are loaded when EDMC starts up. -Plugins are python files. Each plugin has it's own folder in the `plugins` directory. The plugin must have a file named `load.py` that must provide one module level function and optionally provide a few others. +Each plugin has it's own folder in the `plugins` directory: + +* Windows: `%LOCALAPPDATA%\EDMarketConnector\plugins` +* Mac: `~/Library/Application Support/EDMarketConnector/plugins` +* Linux: `$XDG_DATA_HOME/EDMarketConnector/plugins`, or `~/.local/share/EDMarketConnector/plugins` if `$XDG_DATA_HOME` is unset. + +Plugins are python files. The plugin folder must have a file named `load.py` that must provide one module level function and optionally provide a few others. EDMC will import the `load.py` file as a module and then call the `plugin_start()` function. diff --git a/config.py b/config.py index 5f5421af..e38486a6 100644 --- a/config.py +++ b/config.py @@ -89,6 +89,10 @@ class Config: if not isdir(self.app_dir): mkdir(self.app_dir) + self.plugin_dir = join(self.app_dir, 'plugins') + if not isdir(self.plugin_dir): + mkdir(self.plugin_dir) + self.home = expanduser('~') if not getattr(sys, 'frozen', False): @@ -131,6 +135,10 @@ class Config: if not isdir(self.app_dir): mkdir(self.app_dir) + self.plugin_dir = join(self.app_dir, 'plugins') + if not isdir(self.plugin_dir): + mkdir(self.plugin_dir) + # expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207 ctypes.windll.shell32.SHGetSpecialFolderPathW(0, buf, CSIDL_PROFILE, 0) self.home = buf.value @@ -206,6 +214,10 @@ class Config: if not isdir(self.app_dir): makedirs(self.app_dir) + self.plugin_dir = join(self.app_dir, 'plugins') + if not isdir(self.plugin_dir): + mkdir(self.plugin_dir) + self.home = expanduser('~') self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, '%s.ini' % appname) diff --git a/plug.py b/plug.py index 7715bd61..eeb71d19 100644 --- a/plug.py +++ b/plug.py @@ -3,6 +3,9 @@ Plugin hooks for EDMC - Ian Norton """ import os import imp +import sys + +from config import config """ Dictionary of loaded plugin modules. @@ -16,9 +19,9 @@ def find_plugins(): :return: """ found = dict() - plug_folders = os.listdir("plugins") + plug_folders = os.listdir(config.plugin_dir) for name in plug_folders: - loadfile = os.path.join("plugins", name, "load.py") + loadfile = os.path.join(config.plugin_dir, name, "load.py") if os.path.isfile(loadfile): found[name] = loadfile return found @@ -41,7 +44,7 @@ def load_plugins(): PLUGINS[plugname] = plugmod except Exception as plugerr: - print plugerr + sys.stderr.write('%s\n' % plugerr) # appears in %TMP%/EDMarketConnector.log in packaged Windows app imp.release_lock() diff --git a/plugins/About/load.py b/plugins/About/load.py index af232c6c..76bfc3b7 100644 --- a/plugins/About/load.py +++ b/plugins/About/load.py @@ -1,6 +1,7 @@ """ A Skeleton EDMC Plugin """ +import sys import Tkinter as tk @@ -9,7 +10,7 @@ def plugin_start(): Start this plugin :return: """ - print "example plugin started" + sys.stderr.write("example plugin started\n") # appears in %TMP%/EDMarketConnector.log in packaged Windows app def plugin_prefs(parent): @@ -46,7 +47,7 @@ def system_changed(timestamp, system): :param system: the name of the system :return: """ - print "Arrived at {}".format(system) + sys.stderr.write("Arrived at {}\n".format(system)) def cmdr_data(data): @@ -56,7 +57,7 @@ def cmdr_data(data): :return: """ cmdr_data.last = data - print "Got new data ({} chars)".format(len(str(data))) + sys.stderr.write("Got new data ({} chars)\n".format(len(str(data)))) cmdr_data.last = None