compose/fig/cli/command.py

46 lines
1.1 KiB
Python
Raw Normal View History

2013-12-11 15:25:32 +01:00
from docker import Client
import errno
2013-12-11 15:25:32 +01:00
import logging
import os
import re
2013-12-11 15:25:32 +01:00
import yaml
from ..project import Project
2013-12-11 15:25:32 +01:00
from .docopt_command import DocoptCommand
from .formatter import Formatter
from .utils import cached_property, docker_url
2013-12-11 15:25:32 +01:00
log = logging.getLogger(__name__)
class Command(DocoptCommand):
@cached_property
def client(self):
return Client(docker_url())
2013-12-11 15:25:32 +01:00
@cached_property
def project(self):
try:
config = yaml.load(open('fig.yml'))
except IOError, e:
if e.errno == errno.ENOENT:
log.error("Can't find %s. Are you in the right directory?", e.filename)
else:
log.error(e)
exit(1)
return Project.from_config(self.project_name, config, self.client)
@cached_property
def project_name(self):
project = os.path.basename(os.getcwd())
project = re.sub(r'[^a-zA-Z0-9]', '', project)
if not project:
project = 'default'
return project
2013-12-11 15:25:32 +01:00
@cached_property
def formatter(self):
return Formatter()