[D] fix doit restart

This commit is contained in:
boyska 2018-09-21 12:35:33 +02:00
parent cf3163979a
commit 9c5a8f4379

29
dodo.py
View file

@ -1,5 +1,6 @@
import subprocess import subprocess
import os import os
import sys
from doit.tools import LongRunning from doit.tools import LongRunning
@ -104,18 +105,28 @@ def task_up():
} }
def restart(*containers): def _get_valid_services():
'''This actually restart the container(s).'''
srv = subprocess.check_output((COMPOSE + ' config --services').split()) srv = subprocess.check_output((COMPOSE + ' config --services').split())
services = srv.decode('utf-8').strip().split() return 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)) def restart(services):
subprocess.check_call((COMPOSE + 'restart %s' % container).split()) '''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 return True
def task_restart(*containers): def task_restart():
'''Restarts a container specified via commandline.''' '''Restarts a container specified via commandline.'''
return { return {
'params': [{'name': 'services', 'params': [{'name': 'services',
@ -124,7 +135,7 @@ def task_restart(*containers):
'type': list, 'type': list,
'default': [], 'default': [],
'help': "the list of services to be restarted"}], 'help': "the list of services to be restarted"}],
'actions': [(restart, containers)], 'actions': [(restart, )],
} }