From d6db049b421407ae67ee3ed214f9e4094e7aa43d Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Thu, 19 Dec 2013 15:32:24 +0000 Subject: [PATCH] Generate project name based on current dir --- plum/cli/command.py | 15 ++++++++++++++- plum/service_collection.py | 8 ++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/plum/cli/command.py b/plum/cli/command.py index e59d1869f..78e28730d 100644 --- a/plum/cli/command.py +++ b/plum/cli/command.py @@ -1,6 +1,7 @@ from docker import Client import logging import os +import re import yaml from ..service_collection import ServiceCollection @@ -21,7 +22,19 @@ class Command(DocoptCommand): @cached_property def service_collection(self): config = yaml.load(open('plum.yml')) - return ServiceCollection.from_config(self.client, config) + return ServiceCollection.from_config( + config, + client=self.client, + project=self.project + ) + + @cached_property + def project(self): + project = os.path.basename(os.getcwd()) + project = re.sub(r'[^a-zA-Z0-9]', '', project) + if not project: + project = 'default' + return project @cached_property def formatter(self): diff --git a/plum/service_collection.py b/plum/service_collection.py index a72835b0f..feef3de57 100644 --- a/plum/service_collection.py +++ b/plum/service_collection.py @@ -14,7 +14,7 @@ def sort_service_dicts(services): class ServiceCollection(list): @classmethod - def from_dicts(cls, client, service_dicts): + def from_dicts(cls, service_dicts, client, project='default'): """ Construct a ServiceCollection from a list of dicts representing services. """ @@ -26,16 +26,16 @@ class ServiceCollection(list): for name in service_dict.get('links', []): links.append(collection.get(name)) del service_dict['links'] - collection.append(Service(client=client, links=links, **service_dict)) + collection.append(Service(client=client, project=project, links=links, **service_dict)) return collection @classmethod - def from_config(cls, client, config): + def from_config(cls, config, client, project='default'): dicts = [] for name, service in config.items(): service['name'] = name dicts.append(service) - return cls.from_dicts(client, dicts) + return cls.from_dicts(dicts, client, project) def get(self, name): for service in self: