mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Don't allow boolean values for one_off in Project methods
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
5826a2147b
commit
1bc9469674
@ -46,8 +46,12 @@ class OneOffFilter(enum.Enum):
|
|||||||
def update_labels(cls, value, labels):
|
def update_labels(cls, value, labels):
|
||||||
if value == cls.only:
|
if value == cls.only:
|
||||||
labels.append('{0}={1}'.format(LABEL_ONE_OFF, "True"))
|
labels.append('{0}={1}'.format(LABEL_ONE_OFF, "True"))
|
||||||
elif value == cls.exclude or value is False:
|
elif value == cls.exclude:
|
||||||
labels.append('{0}={1}'.format(LABEL_ONE_OFF, "False"))
|
labels.append('{0}={1}'.format(LABEL_ONE_OFF, "False"))
|
||||||
|
elif value == cls.include:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid value for one_off: {}".format(repr(value)))
|
||||||
|
|
||||||
|
|
||||||
class Project(object):
|
class Project(object):
|
||||||
@ -61,7 +65,7 @@ class Project(object):
|
|||||||
self.volumes = volumes or ProjectVolumes({})
|
self.volumes = volumes or ProjectVolumes({})
|
||||||
self.networks = networks or ProjectNetworks({}, False)
|
self.networks = networks or ProjectNetworks({}, False)
|
||||||
|
|
||||||
def labels(self, one_off=False):
|
def labels(self, one_off=OneOffFilter.exclude):
|
||||||
labels = ['{0}={1}'.format(LABEL_PROJECT, self.name)]
|
labels = ['{0}={1}'.format(LABEL_PROJECT, self.name)]
|
||||||
|
|
||||||
OneOffFilter.update_labels(one_off, labels)
|
OneOffFilter.update_labels(one_off, labels)
|
||||||
@ -264,7 +268,7 @@ class Project(object):
|
|||||||
def kill(self, service_names=None, **options):
|
def kill(self, service_names=None, **options):
|
||||||
parallel.parallel_kill(self.containers(service_names), options)
|
parallel.parallel_kill(self.containers(service_names), options)
|
||||||
|
|
||||||
def remove_stopped(self, service_names=None, one_off=False, **options):
|
def remove_stopped(self, service_names=None, one_off=OneOffFilter.exclude, **options):
|
||||||
parallel.parallel_remove(self.containers(
|
parallel.parallel_remove(self.containers(
|
||||||
service_names, stopped=True, one_off=one_off
|
service_names, stopped=True, one_off=one_off
|
||||||
), options)
|
), options)
|
||||||
@ -429,7 +433,7 @@ class Project(object):
|
|||||||
for service in self.get_services(service_names, include_deps=False):
|
for service in self.get_services(service_names, include_deps=False):
|
||||||
service.pull(ignore_pull_failures)
|
service.pull(ignore_pull_failures)
|
||||||
|
|
||||||
def _labeled_containers(self, stopped=False, one_off=False):
|
def _labeled_containers(self, stopped=False, one_off=OneOffFilter.exclude):
|
||||||
return list(filter(None, [
|
return list(filter(None, [
|
||||||
Container.from_ps(self.client, container)
|
Container.from_ps(self.client, container)
|
||||||
for container in self.client.containers(
|
for container in self.client.containers(
|
||||||
@ -437,7 +441,7 @@ class Project(object):
|
|||||||
filters={'label': self.labels(one_off=one_off)})])
|
filters={'label': self.labels(one_off=one_off)})])
|
||||||
)
|
)
|
||||||
|
|
||||||
def containers(self, service_names=None, stopped=False, one_off=False):
|
def containers(self, service_names=None, stopped=False, one_off=OneOffFilter.exclude):
|
||||||
if service_names:
|
if service_names:
|
||||||
self.validate_service_names(service_names)
|
self.validate_service_names(service_names)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user