mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-14 16:27:13 +03:00
Load plugins from outside the source tree.
So that plugins work with the packaged app on Windows and Mac.
This commit is contained in:
parent
4f16215720
commit
b3d585693e
10
PLUGINS.md
10
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.
|
||||
|
||||
|
12
config.py
12
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)
|
||||
|
9
plug.py
9
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()
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user