diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.py | 28 | ||||
-rw-r--r-- | src/plugin_manager.py | 12 |
2 files changed, 38 insertions, 2 deletions
diff --git a/src/plugin.py b/src/plugin.py index 728dfe21..d64679a1 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -1,3 +1,26 @@ +import os +from configparser import ConfigParser + +class PluginConfig(ConfigParser): + def __init__(self, filename): + ConfigParser.__init__(self) + self.__config_file__ = filename + self.read() + + def read(self): + """Read the config file""" + ConfigParser.read(self, self.__config_file__) + + def write(self): + """Write the config to the disk""" + try: + fp = open(self.__config_file__, 'w') + ConfigParser.write(self, fp) + fp.close() + return True + except IOError: + return False + class BasePlugin(object): """ Class that all plugins derive from. Any methods beginning with command_ @@ -5,9 +28,11 @@ class BasePlugin(object): event handlers """ - def __init__(self, plugin_manager, core): + def __init__(self, plugin_manager, core, plugins_conf_dir): self.core = core self.plugin_manager = plugin_manager + conf = os.path.join(plugins_conf_dir, self.__module__+'.cfg') + self.config = PluginConfig(conf) self.init() def init(self): @@ -17,6 +42,7 @@ class BasePlugin(object): pass def unload(self): + self.cleanup() def add_command(self, name, handler, help, completion=None): diff --git a/src/plugin_manager.py b/src/plugin_manager.py index 2a7a116f..0ffee7ee 100644 --- a/src/plugin_manager.py +++ b/src/plugin_manager.py @@ -9,11 +9,21 @@ plugins_dir = plugins_dir or\ os.path.join(os.environ.get('XDG_DATA_HOME') or\ os.path.join(os.environ.get('HOME'), '.local', 'share'), 'poezio', 'plugins') + +plugins_conf_dir = os.path.join(os.environ.get('XDG_CONFIG_HOME'), 'poezio',\ + 'plugins') + try: os.makedirs(plugins_dir) except OSError: pass +try: + os.makedirs(plugins_conf_dir) +except OSError: + pass + + sys.path.append(plugins_dir) class PluginManager(object): @@ -49,7 +59,7 @@ class PluginManager(object): self.modules[name] = module self.commands[name] = {} self.event_handlers[name] = [] - self.plugins[name] = module.Plugin(self, self.core) + self.plugins[name] = module.Plugin(self, self.core, plugins_conf_dir) def unload(self, name): if name in self.plugins: |