You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/04/24 10:55:25 UTC
[4/9] incubator-ariatosca git commit: wip
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/1e0f030e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1e0f030e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1e0f030e
Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 1e0f030e2ba2c20c47b4711e707ecabe21b3b7e5
Parents: 7a4a1dd
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Apr 20 18:51:46 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 11:47:11 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/1e0f030e/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/1e0f030e/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/1e0f030e/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()