Mercurial > fife-parpg
comparison tools/editor/scripts/plugin.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2009 by the FIFE team | |
5 # http://www.fifengine.de | |
6 # This file is part of FIFE. | |
7 # | |
8 # FIFE is free software; you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public | |
10 # License as published by the Free Software Foundation; either | |
11 # version 2.1 of the License, or (at your option) any later version. | |
12 # | |
13 # This library is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this library; if not, write to the | |
20 # Free Software Foundation, Inc., | |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 # #################################################################### | |
23 | |
24 import os | |
25 | |
26 class PluginManager: | |
27 """ Currently, pluginmanager iterates through the plugin directory | |
28 adding the plugins if they are set to True in settings.xml. If a plugin | |
29 isn't set in settings.xml it assumes it is not to be loaded, and saves it | |
30 as False in settings.xml. | |
31 | |
32 If a plugin fails to load due to exceptions, they are caught and a line | |
33 of the error is printed to console. | |
34 """ | |
35 def __init__(self, settings, *args, **kwargs): | |
36 self._settings = settings | |
37 | |
38 self._pluginDir = "plugins" | |
39 self._plugins = [] | |
40 | |
41 files = [] | |
42 for f in os.listdir(self._pluginDir): | |
43 path = os.path.join(self._pluginDir, f) | |
44 if os.path.isfile(path) and os.path.splitext(f)[1] == ".py" and f != "__init__.py": | |
45 files.append(os.path.splitext(f)[0]) | |
46 | |
47 for f in files: | |
48 importPlugin = self._settings.get("Plugins", f, False) | |
49 if importPlugin: | |
50 try: | |
51 print "Importing plugin:", f | |
52 exec "import plugins."+f | |
53 plugin = eval("plugins."+f+"."+f+"()") | |
54 if isinstance(plugin, Plugin) is False: | |
55 print f+" is not an instance of Plugin!" | |
56 else: | |
57 plugin.enable() | |
58 self._plugins.append(plugin) | |
59 except BaseException, error: | |
60 print "Error: ", error | |
61 print "Invalid plugin:", f | |
62 else: | |
63 print "Not importing plugin:", f | |
64 | |
65 self._settings.set("Plugins", f, importPlugin) | |
66 | |
67 self._settings.saveSettings() | |
68 | |
69 | |
70 class Plugin: | |
71 """ The base class for all plugins. All plugins should override these functions. """ | |
72 | |
73 def enable(self): | |
74 raise NotImplementedError, "Plugin has not implemented the enable() function!" | |
75 | |
76 def disable(self): | |
77 raise NotImplementedError, "Plugin has not implemented the disable() function!" | |
78 | |
79 def isEnabled(self): | |
80 raise NotImplementedError, "Plugin has not implemented the isEnabled() function!" | |
81 | |
82 def getName(self): | |
83 raise NotImplementedError, "Plugin has not implemented the getName() function!" | |
84 | |
85 #--- These are not so important ---# | |
86 def getAuthor(self): | |
87 return "Unknown" | |
88 | |
89 def getDescription(self): | |
90 return "" | |
91 | |
92 def getLicense(self): | |
93 return "" | |
94 | |
95 def getVersion(self): | |
96 return "0.1" |