diff --git a/dotbot/cli.py b/dotbot/cli.py index b400dd6..caeb443 100644 --- a/dotbot/cli.py +++ b/dotbot/cli.py @@ -77,7 +77,10 @@ def main(): if tasks is None: log.warning('Configuration file is empty, no work to do') tasks = [] - if not isinstance(tasks, list): + if isinstance(tasks, dict): + if not 'groups' in tasks: + raise ReadingError('Configuration file must contains the "groups" structure') + elif not isinstance(tasks, list): raise ReadingError('Configuration file must be a list of tasks') if options.base_directory: base_directory = os.path.abspath(options.base_directory) diff --git a/dotbot/dispatcher.py b/dotbot/dispatcher.py index 10e4293..0285bec 100644 --- a/dotbot/dispatcher.py +++ b/dotbot/dispatcher.py @@ -20,10 +20,30 @@ class Dispatcher(object): def dispatch(self, tasks): success = True + if 'groups' in tasks: + success &= self._handle_groups(tasks['groups']) + else: + success &= self._handle_tasks(tasks) + return success + + def _handle_groups(self, groups): + success = True + + for group in groups: + if self._has_to_skip(group): + self._log.info('Skipping group %s' % group) + continue + self._log.info('Handle group %s' % group) + tasks = groups[group] + success &= self._handle_tasks(tasks) + return success + + def _handle_tasks(self, tasks): + success = True + for task in tasks: for action in task: - if self._only is not None and action not in self._only \ - or self._skip is not None and action in self._skip: + if self._has_to_skip(action): self._log.info('Skipping action %s' % action) continue handled = False @@ -46,6 +66,12 @@ class Dispatcher(object): self._log.error('Action %s not handled' % action) return success + def _has_to_skip(self, action): + if self._only is not None and action not in self._only \ + or self._skip is not None and action in self._skip: + return True + return False + def _load_plugins(self): self._plugins = [plugin(self._context) for plugin in Plugin.__subclasses__()]