From 9c5a8f4379e91ed91ddb3fe7ae32479526a6fcbd Mon Sep 17 00:00:00 2001 From: boyska Date: Fri, 21 Sep 2018 12:35:33 +0200 Subject: [PATCH] [D] fix doit restart --- dodo.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/dodo.py b/dodo.py index 4962b9e..52fc71e 100644 --- a/dodo.py +++ b/dodo.py @@ -1,5 +1,6 @@ import subprocess import os +import sys from doit.tools import LongRunning @@ -104,18 +105,28 @@ def task_up(): } -def restart(*containers): - '''This actually restart the container(s).''' +def _get_valid_services(): srv = subprocess.check_output((COMPOSE + ' config --services').split()) - services = srv.decode('utf-8').strip().split() - for container in containers: - if container not in services: - raise ValueError("%s is not among the services %r" % (container, services)) - subprocess.check_call((COMPOSE + 'restart %s' % container).split()) + return srv.decode('utf-8').strip().split() + + +def restart(services): + '''This actually restart the container(s).''' + valid = _get_valid_services() + err = False + for service in services: + if service not in valid: + print('ERROR: invalid service %s' % service, file=sys.stderr) + err = True + if err or not services: + print('Valid services are: ' + ', '.join(valid), file=sys.stderr) + return False + for service in services: + subprocess.check_call((COMPOSE + 'restart %s' % service).split()) return True -def task_restart(*containers): +def task_restart(): '''Restarts a container specified via commandline.''' return { 'params': [{'name': 'services', @@ -124,7 +135,7 @@ def task_restart(*containers): 'type': list, 'default': [], 'help': "the list of services to be restarted"}], - 'actions': [(restart, containers)], + 'actions': [(restart, )], }