mirror of
1
0
Fork 0

Add handling of groups

Signed-off-by: Andreas Schmidt <mail@schmidt-andreas.de>
This commit is contained in:
Andreas Schmidt 2020-07-09 16:04:33 +02:00
parent c5e709d433
commit 8b93d27441
No known key found for this signature in database
GPG Key ID: FEE0A611BEA6DEA0
2 changed files with 32 additions and 3 deletions

View File

@ -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)

View File

@ -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__()]