mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Reduce up() cyclomatic complexity
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
9587556e8f
commit
42aa1c3447
@ -969,33 +969,10 @@ class TopLevelCommand(object):
|
|||||||
|
|
||||||
if cascade_stop:
|
if cascade_stop:
|
||||||
print("Aborting on container exit...")
|
print("Aborting on container exit...")
|
||||||
|
all_containers = self.project.containers(service_names=options['SERVICE'], stopped=True)
|
||||||
exit_code = 0
|
exit_code = compute_exit_code(
|
||||||
if exit_value_from:
|
exit_value_from, attached_containers, cascade_starter, all_containers
|
||||||
candidates = list(filter(
|
)
|
||||||
lambda c: c.service == exit_value_from,
|
|
||||||
attached_containers))
|
|
||||||
if not candidates:
|
|
||||||
log.error(
|
|
||||||
'No containers matching the spec "{0}" '
|
|
||||||
'were run.'.format(exit_value_from)
|
|
||||||
)
|
|
||||||
exit_code = 2
|
|
||||||
elif len(candidates) > 1:
|
|
||||||
exit_values = filter(
|
|
||||||
lambda e: e != 0,
|
|
||||||
[c.inspect()['State']['ExitCode'] for c in candidates]
|
|
||||||
)
|
|
||||||
|
|
||||||
exit_code = exit_values[0]
|
|
||||||
else:
|
|
||||||
exit_code = candidates[0].inspect()['State']['ExitCode']
|
|
||||||
else:
|
|
||||||
for e in self.project.containers(service_names=options['SERVICE'], stopped=True):
|
|
||||||
if (not e.is_running and cascade_starter == e.name):
|
|
||||||
if not e.exit_code == 0:
|
|
||||||
exit_code = e.exit_code
|
|
||||||
break
|
|
||||||
|
|
||||||
self.project.stop(service_names=service_names, timeout=timeout)
|
self.project.stop(service_names=service_names, timeout=timeout)
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
@ -1016,6 +993,37 @@ class TopLevelCommand(object):
|
|||||||
print(get_version_info('full'))
|
print(get_version_info('full'))
|
||||||
|
|
||||||
|
|
||||||
|
def compute_exit_code(exit_value_from, attached_containers, cascade_starter, all_containers):
|
||||||
|
exit_code = 0
|
||||||
|
if exit_value_from:
|
||||||
|
candidates = list(filter(
|
||||||
|
lambda c: c.service == exit_value_from,
|
||||||
|
attached_containers))
|
||||||
|
if not candidates:
|
||||||
|
log.error(
|
||||||
|
'No containers matching the spec "{0}" '
|
||||||
|
'were run.'.format(exit_value_from)
|
||||||
|
)
|
||||||
|
exit_code = 2
|
||||||
|
elif len(candidates) > 1:
|
||||||
|
exit_values = filter(
|
||||||
|
lambda e: e != 0,
|
||||||
|
[c.inspect()['State']['ExitCode'] for c in candidates]
|
||||||
|
)
|
||||||
|
|
||||||
|
exit_code = exit_values[0]
|
||||||
|
else:
|
||||||
|
exit_code = candidates[0].inspect()['State']['ExitCode']
|
||||||
|
else:
|
||||||
|
for e in all_containers:
|
||||||
|
if (not e.is_running and cascade_starter == e.name):
|
||||||
|
if not e.exit_code == 0:
|
||||||
|
exit_code = e.exit_code
|
||||||
|
break
|
||||||
|
|
||||||
|
return exit_code
|
||||||
|
|
||||||
|
|
||||||
def convergence_strategy_from_opts(options):
|
def convergence_strategy_from_opts(options):
|
||||||
no_recreate = options['--no-recreate']
|
no_recreate = options['--no-recreate']
|
||||||
force_recreate = options['--force-recreate']
|
force_recreate = options['--force-recreate']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user