summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authord11wtq <chris@w3style.co.uk>2014-06-08 08:51:09 +0000
committerChris Corbyn <chris@w3style.co.uk>2014-06-09 01:31:46 +0000
commit9dd53ecdaa6476d77c8877bfd907d22e0e5d8da1 (patch)
tree06f71190fdae1a8ae3dafceecd99dcea9fcccd08
parent6bfe5e049d4440054b460b92d254b5504b4890aa (diff)
Fix bug with duplicate service entries in `fig up`
Signed-off-by: Chris Corbyn <chris@w3style.co.uk>
-rw-r--r--fig/project.py36
1 files changed, 23 insertions, 13 deletions
diff --git a/fig/project.py b/fig/project.py
index 5152c5d7..15e25d54 100644
--- a/fig/project.py
+++ b/fig/project.py
@@ -89,22 +89,32 @@ class Project(object):
raise NoSuchService(name)
- def get_services(self, service_names=None):
+ def get_services(self, service_names=None, include_links=False):
"""
Returns a list of this project's services filtered
- by the provided list of names, or all services if
+ by the provided list of names, or all auto_start services if
service_names is None or [].
+ If include_links is specified, returns a list prepended with the needed
+ links for service_names, in order of dependency.
+
Preserves the original order of self.services.
Raises NoSuchService if any of the named services
do not exist.
"""
if service_names is None or len(service_names) == 0:
- return filter(lambda s: s.options['auto_start'], self.services)
+ return [s for s in self.services if s.options['auto_start']]
else:
unsorted = [self.get_service(name) for name in service_names]
- return [s for s in self.services if s in unsorted]
+ services = [s for s in self.services if s in unsorted]
+
+ if include_links:
+ services = reduce(self._prepend_with_links, services, [])
+
+ uniques = []
+ [uniques.append(s) for s in services if s not in uniques]
+ return uniques
def start(self, service_names=None, **options):
for service in self.get_services(service_names):
@@ -128,15 +138,7 @@ class Project(object):
def up(self, service_names=None, start_links=True):
new_containers = []
- for service in self.get_services(service_names):
- linked_services = service.get_linked_names()
-
- if start_links and len(linked_services) > 0:
- new_containers.extend(self.up(
- service_names=linked_services,
- start_links=True
- ))
-
+ for service in self.get_services(service_names, include_links=start_links):
for (_, new) in service.recreate_containers():
new_containers.append(new)
@@ -153,6 +155,14 @@ class Project(object):
l.append(container)
return l
+ def _prepend_with_links(self, acc, service):
+ linked_services = self.get_services(
+ service_names=service.get_linked_names(),
+ include_links=True
+ )
+ linked_services.append(service)
+ return acc + linked_services
+
class NoSuchService(Exception):
def __init__(self, name):