add plugins module to handle plugins in configuration file
Signed-off-by: Andreas Schmidt <mail@schmidt-andreas.de>
This commit is contained in:
parent
5d74f29001
commit
e07ed9374a
4 changed files with 43 additions and 1 deletions
|
@ -56,7 +56,7 @@ def main():
|
|||
log.use_color(False)
|
||||
plugin_directories = list(options.plugin_dirs)
|
||||
if not options.disable_built_in_plugins:
|
||||
from .plugins import Clean, Link, Shell
|
||||
from .plugins import Clean, Link, Shell, Plugins
|
||||
plugin_paths = []
|
||||
for directory in plugin_directories:
|
||||
for plugin_path in glob.glob(os.path.join(directory, '*.py')):
|
||||
|
|
|
@ -29,6 +29,10 @@ class Dispatcher(object):
|
|||
if plugin.can_handle(action):
|
||||
try:
|
||||
success &= plugin.handle(action, task[action])
|
||||
if action == 'plugins':
|
||||
self._load_plugins()
|
||||
self._log.lowinfo('Plugin list have been update')
|
||||
self._log.info('New plugin list: %s' % [type(plugin).__name__ for plugin in self._plugins])
|
||||
handled = True
|
||||
except Exception as err:
|
||||
self._log.error(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from .clean import Clean
|
||||
from .link import Link
|
||||
from .shell import Shell
|
||||
from .plugins import Plugins
|
||||
|
|
37
dotbot/plugins/plugins.py
Normal file
37
dotbot/plugins/plugins.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import os
|
||||
import glob
|
||||
import dotbot
|
||||
from ..util import module
|
||||
|
||||
class Plugins(dotbot.Plugin):
|
||||
'''
|
||||
Plugins configuration
|
||||
'''
|
||||
|
||||
_directive = 'plugins'
|
||||
|
||||
def can_handle(self, directive):
|
||||
return directive == self._directive
|
||||
|
||||
def handle(self, directive, data):
|
||||
if directive != self._directive:
|
||||
raise ValueError('Plugins cannot handle directive %s' % directive)
|
||||
return self._process_plugins(data)
|
||||
|
||||
def _process_plugins(self, plugins):
|
||||
plugin_dirs = []
|
||||
plugin_paths = []
|
||||
for plugin in plugins:
|
||||
if isinstance(plugin, dict):
|
||||
plugin_dirs.append(plugin.get('dir', ''))
|
||||
else:
|
||||
plugin_paths.append(plugin)
|
||||
for directory in plugin_dirs:
|
||||
for plugin_path in glob.glob(os.path.join(directory, '*.py')):
|
||||
plugin_paths.append(plugin_path)
|
||||
for plugin in plugin_paths:
|
||||
abspath = os.path.abspath(plugin)
|
||||
module.load(abspath)
|
||||
return True
|
||||
|
||||
# vim: ts=4 sw=4 et
|
Loading…
Reference in a new issue