mirror of https://github.com/docker/compose.git
Add flake8 and fix errors.
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
0dc55fda45
commit
50a24bc3bf
|
@ -1,4 +1,4 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from .service import Service
|
from .service import Service # noqa:flake8
|
||||||
|
|
||||||
__version__ = '0.5.1'
|
__version__ = '0.5.1'
|
||||||
|
|
|
@ -8,7 +8,6 @@ import os
|
||||||
import re
|
import re
|
||||||
import yaml
|
import yaml
|
||||||
from ..packages import six
|
from ..packages import six
|
||||||
import sys
|
|
||||||
|
|
||||||
from ..project import Project
|
from ..project import Project
|
||||||
from ..service import ConfigError
|
from ..service import ConfigError
|
||||||
|
@ -19,6 +18,7 @@ from . import errors
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Command(DocoptCommand):
|
class Command(DocoptCommand):
|
||||||
base_dir = '.'
|
base_dir = '.'
|
||||||
|
|
||||||
|
|
|
@ -281,13 +281,13 @@ class TopLevelCommand(Command):
|
||||||
try:
|
try:
|
||||||
num = int(num)
|
num = int(num)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise UserError('Number of containers for service "%s" is not a number' % service)
|
raise UserError('Number of containers for service "%s" is not a '
|
||||||
|
'number' % service_name)
|
||||||
try:
|
try:
|
||||||
self.project.get_service(service_name).scale(num)
|
self.project.get_service(service_name).scale(num)
|
||||||
except CannotBeScaledError:
|
except CannotBeScaledError:
|
||||||
raise UserError('Service "%s" cannot be scaled because it specifies a port on the host. If multiple containers for this service were created, the port would clash.\n\nRemove the ":" from the port definition in fig.yml so Docker can choose a random port for each container.' % service_name)
|
raise UserError('Service "%s" cannot be scaled because it specifies a port on the host. If multiple containers for this service were created, the port would clash.\n\nRemove the ":" from the port definition in fig.yml so Docker can choose a random port for each container.' % service_name)
|
||||||
|
|
||||||
|
|
||||||
def start(self, options):
|
def start(self, options):
|
||||||
"""
|
"""
|
||||||
Start existing containers.
|
Start existing containers.
|
||||||
|
@ -357,5 +357,6 @@ class TopLevelCommand(Command):
|
||||||
print("Gracefully stopping... (press Ctrl+C again to force)")
|
print("Gracefully stopping... (press Ctrl+C again to force)")
|
||||||
self.project.stop(service_names=service_names)
|
self.project.stop(service_names=service_names)
|
||||||
|
|
||||||
|
|
||||||
def list_containers(containers):
|
def list_containers(containers):
|
||||||
return ", ".join(c.name for c in containers)
|
return ", ".join(c.name for c in containers)
|
||||||
|
|
|
@ -65,11 +65,11 @@ def prettydate(d):
|
||||||
elif s < 120:
|
elif s < 120:
|
||||||
return '1 minute ago'
|
return '1 minute ago'
|
||||||
elif s < 3600:
|
elif s < 3600:
|
||||||
return '{0} minutes ago'.format(s/60)
|
return '{0} minutes ago'.format(s / 60)
|
||||||
elif s < 7200:
|
elif s < 7200:
|
||||||
return '1 hour ago'
|
return '1 hour ago'
|
||||||
else:
|
else:
|
||||||
return '{0} hours ago'.format(s/3600)
|
return '{0} hours ago'.format(s / 3600)
|
||||||
|
|
||||||
|
|
||||||
def mkdir(path, permissions=0o700):
|
def mkdir(path, permissions=0o700):
|
||||||
|
@ -103,8 +103,8 @@ def split_buffer(reader, separator):
|
||||||
index = buffered.find(separator)
|
index = buffered.find(separator)
|
||||||
if index == -1:
|
if index == -1:
|
||||||
break
|
break
|
||||||
yield buffered[:index+1]
|
yield buffered[:index + 1]
|
||||||
buffered = buffered[index+1:]
|
buffered = buffered[index + 1:]
|
||||||
|
|
||||||
if len(buffered) > 0:
|
if len(buffered) > 0:
|
||||||
yield buffered
|
yield buffered
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
|
||||||
class Container(object):
|
class Container(object):
|
||||||
"""
|
"""
|
||||||
Represents a Docker container, constructed from the output of
|
Represents a Docker container, constructed from the output of
|
||||||
|
|
|
@ -38,6 +38,7 @@ def sort_service_dicts(services):
|
||||||
|
|
||||||
return sorted_services
|
return sorted_services
|
||||||
|
|
||||||
|
|
||||||
class Project(object):
|
class Project(object):
|
||||||
"""
|
"""
|
||||||
A collection of services.
|
A collection of services.
|
||||||
|
@ -216,6 +217,6 @@ class ConfigurationError(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.msg
|
return self.msg
|
||||||
|
|
||||||
|
|
||||||
class DependencyError(ConfigurationError):
|
class DependencyError(ConfigurationError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,6 @@ class Service(object):
|
||||||
|
|
||||||
self.remove_stopped()
|
self.remove_stopped()
|
||||||
|
|
||||||
|
|
||||||
def remove_stopped(self, **options):
|
def remove_stopped(self, **options):
|
||||||
for c in self.containers(stopped=True):
|
for c in self.containers(stopped=True):
|
||||||
if not c.is_running:
|
if not c.is_running:
|
||||||
|
@ -212,7 +211,7 @@ class Service(object):
|
||||||
log.info("Starting %s..." % container.name)
|
log.info("Starting %s..." % container.name)
|
||||||
return self.start_container(container, **options)
|
return self.start_container(container, **options)
|
||||||
|
|
||||||
def start_container(self, container=None, intermediate_container=None,**override_options):
|
def start_container(self, container=None, intermediate_container=None, **override_options):
|
||||||
if container is None:
|
if container is None:
|
||||||
container = self.create_container(**override_options)
|
container = self.create_container(**override_options)
|
||||||
|
|
||||||
|
@ -342,7 +341,7 @@ class Service(object):
|
||||||
if 'environment' in container_options:
|
if 'environment' in container_options:
|
||||||
if isinstance(container_options['environment'], list):
|
if isinstance(container_options['environment'], list):
|
||||||
container_options['environment'] = dict(split_env(e) for e in container_options['environment'])
|
container_options['environment'] = dict(split_env(e) for e in container_options['environment'])
|
||||||
container_options['environment'] = dict(resolve_env(k,v) for k,v in container_options['environment'].iteritems())
|
container_options['environment'] = dict(resolve_env(k, v) for k, v in container_options['environment'].iteritems())
|
||||||
|
|
||||||
if self.can_be_built():
|
if self.can_be_built():
|
||||||
if len(self.client.images(name=self._build_tag_name())) == 0:
|
if len(self.client.images(name=self._build_tag_name())) == 0:
|
||||||
|
@ -459,13 +458,15 @@ def split_port(port):
|
||||||
external_port = (external_ip,)
|
external_port = (external_ip,)
|
||||||
return internal_port, external_port
|
return internal_port, external_port
|
||||||
|
|
||||||
|
|
||||||
def split_env(env):
|
def split_env(env):
|
||||||
if '=' in env:
|
if '=' in env:
|
||||||
return env.split('=', 1)
|
return env.split('=', 1)
|
||||||
else:
|
else:
|
||||||
return env, None
|
return env, None
|
||||||
|
|
||||||
def resolve_env(key,val):
|
|
||||||
|
def resolve_env(key, val):
|
||||||
if val is not None:
|
if val is not None:
|
||||||
return key, val
|
return key, val
|
||||||
elif key in os.environ:
|
elif key in os.environ:
|
||||||
|
|
|
@ -2,3 +2,4 @@ mock==1.0.1
|
||||||
nose==1.3.0
|
nose==1.3.0
|
||||||
pyinstaller==2.1
|
pyinstaller==2.1
|
||||||
unittest2
|
unittest2
|
||||||
|
flake8
|
||||||
|
|
Loading…
Reference in New Issue