plugins: remove unneeded function.
[nephilim.git] / nephilim / plugins / __init__.py
bloba3463a25280e9fa7711667cac6626688441b0289
2 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
4 # Nephilim is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # Nephilim is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
19 import sys
20 import logging
22 __all__ = ['AlbumCover', 'Filebrowser', 'Library', 'Lyrics', 'Notify', 'PlayControl',
23 'Playlist', 'Songinfo', 'Systray']
25 class Plugins:
26 _plugins = None
27 parent = None
28 mpclient = None
30 def __init__(self, parent, mpclient):
31 """load all modules in the plugins directory."""
32 self._plugins = {}
33 self.parent = parent
34 self.mpclient = mpclient
36 for name in __all__:
37 self.init_plugin(name)
39 def plugin(self, name):
40 return self._plugins[name] if name in self._plugins else None
42 def init_plugin(self, name):
43 try:
44 if name in sys.modules:
45 reload(sys.modules[name])
46 module = sys.modules[name]
47 else:
48 module = __import__(name, globals(), locals(), [], 1)
49 except SyntaxError, e:
50 logging.error('Failed to initialize plugin %s: %s.'%(name, e))
51 return False
53 self._plugins[name] = eval('module.%s(self.parent, self.mpclient, \'%s\')'%(name, name))
54 return True
56 def load(self, name):
57 if not name in self._plugins:
58 if not self.init_plugin(name):
59 return False
61 self._plugins[name].load()
62 return True
64 def unload(self, name):
65 if name in self._plugins:
66 if self._plugins[name].is_loaded():
67 self._plugins[name].unload()
69 def plugins(self):
70 return self._plugins.values()
72 def loaded_plugins(self):
73 list = []
74 for plugin in self._plugins.values():
75 if plugin.is_loaded():
76 list.append(plugin)
77 return list