Browse Source

Cleanup some project logic.

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin 10 years ago
parent
commit
08ba857807
1 changed files with 28 additions and 26 deletions
  1. 28 26
      compose/project.py

+ 28 - 26
compose/project.py

@@ -87,8 +87,14 @@ class Project(object):
             volumes_from = project.get_volumes_from(service_dict)
             net = project.get_net(service_dict)
 
-            project.services.append(Service(client=client, project=name, links=links, net=net,
-                                            volumes_from=volumes_from, **service_dict))
+            project.services.append(
+                Service(
+                    client=client,
+                    project=name,
+                    links=links,
+                    net=net,
+                    volumes_from=volumes_from,
+                    **service_dict))
         return project
 
     @property
@@ -184,30 +190,26 @@ class Project(object):
         return volumes_from
 
     def get_net(self, service_dict):
-        if 'net' in service_dict:
-            net_name = get_service_name_from_net(service_dict.get('net'))
-
-            if net_name:
-                try:
-                    net = self.get_service(net_name)
-                except NoSuchService:
-                    try:
-                        net = Container.from_id(self.client, net_name)
-                    except APIError:
-                        raise ConfigurationError(
-                            'Service "%s" is trying to use the network of "%s", '
-                            'which is not the name of a service or container.' % (
-                                service_dict['name'],
-                                net_name))
-            else:
-                net = service_dict['net']
-
-            del service_dict['net']
-
-        else:
-            net = None
-
-        return net
+        net = service_dict.pop('net', None)
+        if not net:
+            return
+
+        net_name = get_service_name_from_net(net)
+        if not net_name:
+            return net
+
+        try:
+            return self.get_service(net_name)
+        except NoSuchService:
+            pass
+        try:
+            return Container.from_id(self.client, net_name)
+        except APIError:
+            raise ConfigurationError(
+                'Service "%s" is trying to use the network of "%s", '
+                'which is not the name of a service or container.' % (
+                    service_dict['name'],
+                    net_name))
 
     def start(self, service_names=None, **options):
         for service in self.get_services(service_names):