From 1a6d903e34d505005836f6b8aee3552073a2397e Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 25 Sep 2011 02:39:00 +0200 Subject: Add a config file to the plugins by default --- src/plugin.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/plugin.py') 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): -- cgit v1.2.3