Merge 0098c52610
into 5294594f5a
This commit is contained in:
commit
75e5122ab8
|
@ -2,6 +2,7 @@ import os
|
||||||
from .plugin import Plugin
|
from .plugin import Plugin
|
||||||
from .messenger import Messenger
|
from .messenger import Messenger
|
||||||
from .context import Context
|
from .context import Context
|
||||||
|
from .util import test_success
|
||||||
|
|
||||||
class Dispatcher(object):
|
class Dispatcher(object):
|
||||||
def __init__(self, base_directory, only=None, skip=None):
|
def __init__(self, base_directory, only=None, skip=None):
|
||||||
|
@ -21,29 +22,43 @@ class Dispatcher(object):
|
||||||
def dispatch(self, tasks):
|
def dispatch(self, tasks):
|
||||||
success = True
|
success = True
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
for action in task:
|
actions = task
|
||||||
|
name = task.get('task', None)
|
||||||
|
if name is not None:
|
||||||
|
test = task.get('if', None)
|
||||||
|
if test is not None and not test_success(test, cwd=self._context.base_directory(), log=self._log):
|
||||||
|
self._log.info('Skipping task %s' % name)
|
||||||
|
actions = []
|
||||||
|
else:
|
||||||
|
actions = task.get('actions', [])
|
||||||
|
if not actions:
|
||||||
|
self._log.info('Task %s has no actions' % name)
|
||||||
|
else:
|
||||||
|
self._log.info('Starting task %s' % name)
|
||||||
|
for action in actions:
|
||||||
if self._only is not None and action not in self._only \
|
if self._only is not None and action not in self._only \
|
||||||
or self._skip is not None and action in self._skip:
|
or self._skip is not None and action in self._skip:
|
||||||
self._log.info('Skipping action %s' % action)
|
self._log.info('Skipping action %s' % action)
|
||||||
continue
|
continue
|
||||||
handled = False
|
handled = False
|
||||||
if action == 'defaults':
|
if action == 'defaults':
|
||||||
self._context.set_defaults(task[action]) # replace, not update
|
self._context.set_defaults(actions[action]) # replace, not update
|
||||||
handled = True
|
handled = True
|
||||||
# keep going, let other plugins handle this if they want
|
# keep going, let other plugins handle this if they want
|
||||||
for plugin in self._plugins:
|
for plugin in self._plugins:
|
||||||
if plugin.can_handle(action):
|
if plugin.can_handle(action):
|
||||||
try:
|
try:
|
||||||
success &= plugin.handle(action, task[action])
|
success &= plugin.handle(action, actions[action])
|
||||||
handled = True
|
handled = True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self._log.error(
|
self._log.error(
|
||||||
'An error was encountered while executing action %s' %
|
'An error was encountered while executing action %s' %
|
||||||
action)
|
action)
|
||||||
self._log.debug(err)
|
|
||||||
if not handled:
|
if not handled:
|
||||||
success = False
|
success = False
|
||||||
self._log.error('Action %s not handled' % action)
|
self._log.error('Action %s not handled' % action)
|
||||||
|
if name and actions:
|
||||||
|
self._log.info('Task %s completed' % name)
|
||||||
return success
|
return success
|
||||||
|
|
||||||
def _load_plugins(self):
|
def _load_plugins(self):
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Link(dotbot.Plugin):
|
||||||
path = self._default_source(destination, source.get('path'))
|
path = self._default_source(destination, source.get('path'))
|
||||||
else:
|
else:
|
||||||
path = self._default_source(destination, source)
|
path = self._default_source(destination, source)
|
||||||
if test is not None and not self._test_success(test):
|
if test is not None and not dotbot.util.test_success(test, cwd=self._context.base_directory(), log=self._log):
|
||||||
self._log.lowinfo('Skipping %s' % destination)
|
self._log.lowinfo('Skipping %s' % destination)
|
||||||
continue
|
continue
|
||||||
path = os.path.expandvars(os.path.expanduser(path))
|
path = os.path.expandvars(os.path.expanduser(path))
|
||||||
|
@ -105,12 +105,6 @@ class Link(dotbot.Plugin):
|
||||||
self._log.error('Some links were not successfully set up')
|
self._log.error('Some links were not successfully set up')
|
||||||
return success
|
return success
|
||||||
|
|
||||||
def _test_success(self, command):
|
|
||||||
ret = dotbot.util.shell_command(command, cwd=self._context.base_directory())
|
|
||||||
if ret != 0:
|
|
||||||
self._log.debug('Test \'%s\' returned false' % command)
|
|
||||||
return ret == 0
|
|
||||||
|
|
||||||
def _default_source(self, destination, source):
|
def _default_source(self, destination, source):
|
||||||
if source is None:
|
if source is None:
|
||||||
basename = os.path.basename(destination)
|
basename = os.path.basename(destination)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
from .common import shell_command
|
from .common import shell_command, test_success
|
||||||
|
|
|
@ -32,3 +32,9 @@ def shell_command(command, cwd=None, enable_stdin=False, enable_stdout=False, en
|
||||||
stderr=stderr,
|
stderr=stderr,
|
||||||
cwd=cwd
|
cwd=cwd
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_success(command, cwd=None, log=None):
|
||||||
|
ret = shell_command(command, cwd=cwd)
|
||||||
|
if ret != 0 and log != None:
|
||||||
|
log.debug('Test \'%s\' returned false' % command)
|
||||||
|
return ret == 0
|
||||||
|
|
Loading…
Reference in a new issue