summaryrefslogtreecommitdiff
path: root/src/plugin.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2011-09-25 02:39:00 +0200
committermathieui <mathieui@mathieui.net>2011-09-25 02:39:00 +0200
commit1a6d903e34d505005836f6b8aee3552073a2397e (patch)
tree63b64fd3ff4f9818512aba47c71afa833b2b9980 /src/plugin.py
parentcac130e7543b30be7fbec6484b29191a9f8b1665 (diff)
downloadpoezio-1a6d903e34d505005836f6b8aee3552073a2397e.tar.gz
poezio-1a6d903e34d505005836f6b8aee3552073a2397e.tar.bz2
poezio-1a6d903e34d505005836f6b8aee3552073a2397e.tar.xz
poezio-1a6d903e34d505005836f6b8aee3552073a2397e.zip
Add a config file to the plugins by default
Diffstat (limited to 'src/plugin.py')
-rw-r--r--src/plugin.py28
1 files changed, 27 insertions, 1 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):