Add handling of groups
Signed-off-by: Andreas Schmidt <mail@schmidt-andreas.de>
This commit is contained in:
parent
c5e709d433
commit
8b93d27441
2 changed files with 32 additions and 3 deletions
|
@ -77,7 +77,10 @@ def main():
|
||||||
if tasks is None:
|
if tasks is None:
|
||||||
log.warning('Configuration file is empty, no work to do')
|
log.warning('Configuration file is empty, no work to do')
|
||||||
tasks = []
|
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')
|
raise ReadingError('Configuration file must be a list of tasks')
|
||||||
if options.base_directory:
|
if options.base_directory:
|
||||||
base_directory = os.path.abspath(options.base_directory)
|
base_directory = os.path.abspath(options.base_directory)
|
||||||
|
|
|
@ -20,10 +20,30 @@ class Dispatcher(object):
|
||||||
|
|
||||||
def dispatch(self, tasks):
|
def dispatch(self, tasks):
|
||||||
success = True
|
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 task in tasks:
|
||||||
for action in task:
|
for action in task:
|
||||||
if self._only is not None and action not in self._only \
|
if self._has_to_skip(action):
|
||||||
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
|
||||||
|
@ -46,6 +66,12 @@ class Dispatcher(object):
|
||||||
self._log.error('Action %s not handled' % action)
|
self._log.error('Action %s not handled' % action)
|
||||||
return success
|
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):
|
def _load_plugins(self):
|
||||||
self._plugins = [plugin(self._context)
|
self._plugins = [plugin(self._context)
|
||||||
for plugin in Plugin.__subclasses__()]
|
for plugin in Plugin.__subclasses__()]
|
||||||
|
|
Loading…
Reference in a new issue