comparison clients/editor/scripts/plugin.py @ 255:51cc05d862f2

Merged editor_rewrite branch to trunk. This contains changes that may break compatibility against existing clients. For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Jun 2009 16:00:02 +0000
parents
children 8b125ec749d7
comparison
equal deleted inserted replaced
254:10b5f7f36dd4 255:51cc05d862f2
1 import os
2 import editor
3
4 class PluginManager:
5 """ Currently, pluginmanager iterates through the plugin directory
6 adding the plugins if they are set to True in settings.xml. If a plugin
7 isn't set in settings.xml it assumes it is not to be loaded, and saves it
8 as False in settings.xml.
9
10 If a plugin fails to load due to exceptions, they are caught and a line
11 of the error is printed to console.
12 """
13 def __init__(self, *args, **kwargs):
14 self._settings = editor.getEditor().getSettings()
15
16 self._pluginDir = "plugins"
17 self._plugins = []
18
19 files = []
20 for f in os.listdir(self._pluginDir):
21 path = os.path.join(self._pluginDir, f)
22 if os.path.isfile(path) and os.path.splitext(f)[1] == ".py" and f != "__init__.py":
23 files.append(os.path.splitext(f)[0])
24
25 for f in files:
26 importPlugin = self._settings.get("Plugins", f, False)
27 if importPlugin:
28 try:
29 print "Importing plugin:", f
30 exec "import plugins."+f
31 plugin = eval("plugins."+f+"."+f+"()")
32 if isinstance(plugin, Plugin) is False:
33 print f+" is not an instance of Plugin!"
34 else:
35 plugin.enable()
36 self._plugins.append(plugin)
37 except BaseException, error:
38 print "Error: ", error
39 print "Invalid plugin:", f
40 else:
41 print "Not importing plugin:", f
42
43 self._settings.set("Plugins", f, importPlugin)
44
45 self._settings.saveSettings()
46
47
48 class Plugin:
49 """ The base class for all plugins. All plugins should override these functions. """
50
51 def enable(self):
52 raise NotImplementedError, "Plugin has not implemented the enable() function!"
53
54 def disable(self):
55 raise NotImplementedError, "Plugin has not implemented the disable() function!"
56
57 def isEnabled(self):
58 raise NotImplementedError, "Plugin has not implemented the isEnabled() function!"
59
60 def getName(self):
61 raise NotImplementedError, "Plugin has not implemented the getName() function!"
62
63 #--- These are not so important ---#
64 def getAuthor(self):
65 return "Unknown"
66
67 def getDescription(self):
68 return ""
69
70 def getLicense(self):
71 return ""
72
73 def getVersion(self):
74 return "0.1"