summaryrefslogtreecommitdiff
path: root/src/plugin.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-09-25 20:12:43 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-09-25 20:12:43 +0200
commitc80022e816e96580d48286011337528a929f4ec8 (patch)
tree6ede4e9d16e4fc2916a99dff6e0fbf3c065fae39 /src/plugin.py
parentfa5044f423e30db386d6d24d39f60d0735a44355 (diff)
parent00ed9b4842169111238b86d0bfc1465176b7d2d8 (diff)
downloadpoezio-c80022e816e96580d48286011337528a929f4ec8.tar.gz
poezio-c80022e816e96580d48286011337528a929f4ec8.tar.bz2
poezio-c80022e816e96580d48286011337528a929f4ec8.tar.xz
poezio-c80022e816e96580d48286011337528a929f4ec8.zip
merge default into plugins branch. So that branch is still up to date too
Diffstat (limited to 'src/plugin.py')
-rw-r--r--src/plugin.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/plugin.py b/src/plugin.py
new file mode 100644
index 00000000..d64679a1
--- /dev/null
+++ b/src/plugin.py
@@ -0,0 +1,55 @@
+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_
+ are interpreted as a command and beginning with on_ are interpreted as
+ event handlers
+ """
+
+ 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):
+ pass
+
+ def cleanup(self):
+ pass
+
+ def unload(self):
+
+ self.cleanup()
+
+ def add_command(self, name, handler, help, completion=None):
+ return self.plugin_manager.add_command(self.__module__, name, handler, help, completion)
+
+ def add_event_handler(self, event_name, handler):
+ return self.plugin_manager.add_event_handler(self.__module__, event_name, handler)
+
+ def del_event_handler(self, event_name, handler):
+ return self.plugin_manager.del_event_handler(self.__module__, event_name, handler)