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
|
@ -56,7 +56,7 @@ def main():
|
||||||
log.use_color(False)
|
log.use_color(False)
|
||||||
plugin_directories = list(options.plugin_dirs)
|
plugin_directories = list(options.plugin_dirs)
|
||||||
if not options.disable_built_in_plugins:
|
if not options.disable_built_in_plugins:
|
||||||
from .plugins import Clean, Link, Shell
|
from .plugins import Clean, Link, Shell, Plugins
|
||||||
plugin_paths = []
|
plugin_paths = []
|
||||||
for directory in plugin_directories:
|
for directory in plugin_directories:
|
||||||
for plugin_path in glob.glob(os.path.join(directory, '*.py')):
|
for plugin_path in glob.glob(os.path.join(directory, '*.py')):
|
||||||
|
|
|
@ -29,6 +29,10 @@ class Dispatcher(object):
|
||||||
if plugin.can_handle(action):
|
if plugin.can_handle(action):
|
||||||
try:
|
try:
|
||||||
success &= plugin.handle(action, task[action])
|
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
|
handled = True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self._log.error(
|
self._log.error(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
from .clean import Clean
|
from .clean import Clean
|
||||||
from .link import Link
|
from .link import Link
|
||||||
from .shell import Shell
|
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