Add PYENTRYPOINT_RAW option

pull/3/head v0.3.2
Christophe Mehay 8 years ago
parent 9a18c3e139
commit 01cd8137cc

@ -13,4 +13,4 @@ WORKDIR /opt/tests
ENV SECRET nothing
CMD ["py.test", "-s", "."]
CMD ["py.test", "--verbose", "-s", "."]

@ -13,4 +13,4 @@ WORKDIR /opt/tests
ENV SECRET nothing
CMD ["py.test", "-s", "."]
CMD ["py.test", "--verbose", "-s", "."]

@ -3,6 +3,7 @@
Smart docker-entrypoint
"""
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import os
@ -51,6 +52,11 @@ class Entrypoint(object):
"""Check environment to tell if config should apply anyway"""
return 'ENTRYPOINT_FORCE' in os.environ
@property
def raw_output(self):
"""Check if command output should be displayed using logging or not"""
return 'ENTRYPOINT_RAW' in os.environ
def apply_conf(self):
"""Apply config to template files"""
env = Environment(loader=FileSystemLoader('/'))
@ -80,9 +86,11 @@ class Entrypoint(object):
cb(line)
if out:
dispout(out, self.log.info)
display_cb = self.log.info if not self.raw_output else print
dispout(out, display_cb)
if err:
dispout(err, self.log.warning)
display_cb = self.log.warning if not self.raw_output else print
dispout(err, display_cb)
if proc.returncode:
raise Exception('Command exit code: {}'.format(proc.returncode))

@ -72,10 +72,22 @@ class Logs(object):
def set_debug(cls):
"""Set log level to debug"""
cls.lvl = logging.DEBUG
cls.log.setLevel(logging.DEBUG)
cls.log.setLevel(cls.lvl)
@classmethod
def set_info(cls):
"""Set log level to info"""
cls.lvl = logging.INFO
cls.log.setLevel(logging.INFO)
cls.log.setLevel(cls.lvl)
@classmethod
def set_warning(cls):
"""Set log level to info"""
cls.lvl = logging.WARNING
cls.log.setLevel(cls.lvl)
@classmethod
def set_critical(cls):
"""Set log level to info"""
cls.lvl = logging.CRITICAL
cls.log.setLevel(cls.lvl)

@ -5,7 +5,7 @@ from setuptools import setup
# Thanks Sam and Max
__version__ = '0.3.1'
__version__ = '0.3.2'
if __name__ == '__main__':
setup(

@ -199,7 +199,7 @@ def test_command():
def test_config_file():
os.environ['ENTRYPOINT_CONFIG'] = 'configs/base.yml'
entry = Entrypoint()
entry = Entrypoint(conf='configs/base.yml')
assert entry.config.has_config
@ -208,8 +208,17 @@ def test_config_file():
def test_force_config():
os.environ['ENTRYPOINT_FORCE'] = 'True'
entry = Entrypoint()
entry = Entrypoint(conf='configs/base.yml')
assert entry.should_config
del os.environ['ENTRYPOINT_FORCE']
def test_display_raw():
os.environ['ENTRYPOINT_RAW'] = 'True'
entry = Entrypoint(conf='configs/base.yml')
assert entry.raw_output
del os.environ['ENTRYPOINT_RAW']

Loading…
Cancel
Save