Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-146-Support-colorful-execution-logging [created] 3a7657431
wip Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/3a765743 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/3a765743 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/3a765743 Branch: refs/heads/ARIA-146-Support-colorful-execution-logging Commit: 3a765743100d4390b77e813f2873482ac1770751 Parents: 29bc84b Author: max-orlov <[email protected]> Authored: Thu Apr 20 18:51:46 2017 +0300 Committer: max-orlov <[email protected]> Committed: Thu Apr 20 18:51:46 2017 +0300 ---------------------------------------------------------------------- aria/cli/color.py | 50 ++++++++++++++++++++++++++++++++++++++ aria/cli/execution_logging.py | 19 +++++++++++---- aria/core.py | 4 +-- 3 files changed, 66 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a765743/aria/cli/color.py ---------------------------------------------------------------------- diff --git a/aria/cli/color.py b/aria/cli/color.py new file mode 100644 index 0000000..54ee4bf --- /dev/null +++ b/aria/cli/color.py @@ -0,0 +1,50 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from StringIO import StringIO + +import colorama + +colorama.init() + + +class StyledString(str): + + fore = colorama.Fore + back = colorama.Back + style = colorama.Style + + def __init__(self, str_, *args): + super(StyledString, self).__init__() + # TODO: raise proper exception + if not all(self._is_valid(arg) for arg in args): + raise Exception("bla bla bla") + self._str = str_ + self._args = args + self._stylized_str = None + + def __str__(self): + if self._stylized_str is None: + styling_str = StringIO() + for arg in self._args: + styling_str.write(arg) + styling_str.write(self._str) + styling_str.write(self.style.RESET_ALL) + self.stylized_str = styling_str.getvalue() + + return self.stylized_str + + def _is_valid(self, value): + return any(value in vars(instance).values() + for instance in (self.fore, self.back, self.style)) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a765743/aria/cli/execution_logging.py ---------------------------------------------------------------------- diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py index 8baf6d7..17e396d 100644 --- a/aria/cli/execution_logging.py +++ b/aria/cli/execution_logging.py @@ -15,21 +15,22 @@ from StringIO import StringIO +from .color import StyledString from . import logger from .env import env DEFAULT_FORMATTING = { logger.NO_VERBOSE: {'message': '{item.msg}'}, logger.LOW_VERBOSE: { - 'message': '{timestamp} | {item.level[0]} | {item.msg}', - 'timestamp': '%H:%M:%S' + 'message': '{timestamp} | {level} | {item.msg}', + 'timestamp': '%H:%M:%S', }, logger.MEDIUM_VERBOSE: { - 'message': '{timestamp} | {item.level[0]} | {implementation} | {item.msg} ', + 'message': '{timestamp} | {level} | {implementation} | {item.msg} ', 'timestamp': '%H:%M:%S' }, logger.HIGH_VERBOSE: { - 'message': '{timestamp} | {item.level[0]} | {implementation}({inputs}) | {item.msg} ', + 'message': '{timestamp} | {level} | {implementation}({inputs}) | {item.msg} ', 'timestamp': '%H:%M:%S' }, } @@ -41,9 +42,17 @@ def _str(item, formats=None): formatting = formats.get(env.logging.verbosity_level, DEFAULT_FORMATTING[env.logging.verbosity_level]) msg = StringIO() - formatting_kwargs = dict(item=item) + # region level styling + + levels_format = { + 'debug': (StyledString.back.LIGHTRED_EX,) + } + formatting_kwargs['level'] = StyledString(item.level[0], *levels_format.get(item.level.lower(), [])) + + # endregion level styling + if item.task: formatting_kwargs['implementation'] = item.task.implementation formatting_kwargs['inputs'] = dict(i.unwrap() for i in item.task.inputs.values()) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a765743/aria/core.py ---------------------------------------------------------------------- diff --git a/aria/core.py b/aria/core.py index af1984a..4e19506 100644 --- a/aria/core.py +++ b/aria/core.py @@ -77,8 +77,8 @@ class Core(object): consumption.ConsumerChain( context, ( - consumption.SatisfyRequirements, - consumption.ValidateCapabilities, + # consumption.SatisfyRequirements, + # consumption.ValidateCapabilities, consumption.FindHosts, consumption.ConfigureOperations )).consume()
