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 11:35:41 UTC

incubator-ariatosca git commit: tidying up

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-146-Support-colorful-execution-logging 1c074676b -> 592a1068b


tidying up


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/592a1068
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/592a1068
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/592a1068

Branch: refs/heads/ARIA-146-Support-colorful-execution-logging
Commit: 592a1068bc289e95598e7ecc2c89cd4aa3e48b97
Parents: 1c07467
Author: max-orlov <ma...@gigaspaces.com>
Authored: Mon Apr 24 14:28:00 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Apr 24 14:35:35 2017 +0300

----------------------------------------------------------------------
 aria/cli/color.py               | 93 ------------------------------------
 aria/cli/commands/executions.py |  1 -
 aria/cli/commands/logs.py       |  1 +
 aria/cli/execution_logging.py   |  8 ++--
 aria/cli/logger.py              | 16 +++++++
 5 files changed, 20 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/592a1068/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
deleted file mode 100644
index 006af4d..0000000
--- a/aria/cli/color.py
+++ /dev/null
@@ -1,93 +0,0 @@
-# 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
-from jinja2.environment import Template
-
-class StyledString1(object):
-
-    FORE = colorama.Fore
-    BACK = colorama.Back
-    STYLE = colorama.Style
-
-    def __init__(self, str_to_stylize, *style_args):
-        """
-
-        :param str_to_stylize:
-        :param style_args:
-        :param kwargs:
-            to_close: specifies if end the format on the current line. default to True
-        """
-        colorama.init()
-        self._original_str = str_to_stylize
-        self._args = style_args
-        self._apply_style()
-
-    def __str__(self):
-        return self._stylized_str
-
-    def _style_str(self, styling_str=None):
-        str_ = styling_str or StringIO
-        for arg in self._args:
-            str_.write(arg)
-        if styling_str is not None:
-            return str_
-        else:
-            return str_.getvalue()
-
-    def _apply_style(self):
-        assert all(self._is_valid(arg) for arg in self._args)
-        styling_str = StringIO()
-        self._style_str(styling_str)
-        styling_str.write(self._original_str)
-        styling_str.write(self.STYLE.RESET_ALL)
-        self._stylized_str = styling_str.getvalue()
-
-    def _is_valid(self, value):
-        return any(value in vars(type).values() for type in (self.FORE, self.BACK, self.STYLE))
-
-
-# print StyledString1('aaa', StyledString1.FORE.WHITE, StyledString1.FORE.BLACK)
-
-
-class StyledString2(object):
-    FORE = colorama.Fore
-    BACK = colorama.Back
-    STYLE = colorama.Style
-
-    def __init__(self, str_to_stylize):
-        """
-
-        :param str_to_stylize: 
-        :param style_args: 
-        :param kwargs:
-            to_close: specifies if end the format on the current line. default to True
-        """
-        colorama.init()
-        self._original_str = str_to_stylize
-        str_template = Template(self._original_str)
-        self._stylized_str = str_template.render(FORE=self.FORE, BACK=self.BACK, STYLE=self.STYLE)
-
-    def __str__(self):
-        return self._stylized_str
-
-    def __add__(self, other):
-        return str(self) + other
-
-    def __radd__(self, other):
-        return other + str(self)
-
-# print str(StyledString2('{BACK.RED}123{BACK.BLUE}aaa{STYLE.RESET_ALL}')) + 'bbb'
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/592a1068/aria/cli/commands/executions.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/executions.py b/aria/cli/commands/executions.py
index 6269d28..3eb53ab 100644
--- a/aria/cli/commands/executions.py
+++ b/aria/cli/commands/executions.py
@@ -20,7 +20,6 @@ from .. import table
 from .. import utils
 from .. import logger as cli_logger
 from .. import execution_logging
-from .. import color
 from ..core import aria
 from ...modeling.models import Execution
 from ...orchestrator.workflow_runner import WorkflowRunner

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/592a1068/aria/cli/commands/logs.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/logs.py b/aria/cli/commands/logs.py
index 8de4662..350a035 100644
--- a/aria/cli/commands/logs.py
+++ b/aria/cli/commands/logs.py
@@ -18,6 +18,7 @@ from ..core import aria
 
 
 @aria.group(name='logs')
+@aria.options.verbose()
 def logs():
     """Show logs from workflow executions
     """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/592a1068/aria/cli/execution_logging.py
----------------------------------------------------------------------
diff --git a/aria/cli/execution_logging.py b/aria/cli/execution_logging.py
index 304da6f..b909dda 100644
--- a/aria/cli/execution_logging.py
+++ b/aria/cli/execution_logging.py
@@ -18,7 +18,6 @@ from StringIO import StringIO
 from contextlib import contextmanager
 from functools import partial
 
-from .color import StyledString2
 from . import logger
 from .env import env
 
@@ -127,7 +126,7 @@ class _StylizedLogs(object):
     def _stylize(self, msg, log_item, msg_type):
         string_marker = (self._final_string_marker(log_item.msg) or
                          self._styles[msg_type].get(log_item.level.lower(), ''))
-        return StyledString2( string_marker + str(msg) + '{{ STYLE.RESET_ALL }}')
+        return logger.Color.render_str(string_marker + str(msg) + '{{ STYLE.RESET_ALL }}')
 
     def _markup(self, str_, original_message):
         if self._mark_pattern is None:
@@ -137,9 +136,9 @@ class _StylizedLogs(object):
             if not re.match(regex_pattern, original_message):
                 return str_
         marker = self._styles[MARKER]
-        return StyledString2(
+        return logger.Color.render_str(
             marker +
-            str_.replace(StyledString2.STYLE.RESET_ALL, '{{ STYLE.RESET_ALL }}' + marker) +
+            str_.replace(logger.Color.STYLE.RESET_ALL, '{{ STYLE.RESET_ALL }}' + marker) +
             '{{ STYLE.RESET_ALL }}'
         )
 
@@ -167,7 +166,6 @@ class _StylizedLogs(object):
             # execution task
             implementation = item.execution.workflow_name
             inputs = dict(i.unwrap() for i in item.execution.inputs.values())
-        import pydevd; pydevd.settrace('localhost', suspend=False)
 
         formatting_kwargs['implementation'] = self._implementation(implementation, item)
         formatting_kwargs['inputs'] = self._inputs(inputs, item)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/592a1068/aria/cli/logger.py
----------------------------------------------------------------------
diff --git a/aria/cli/logger.py b/aria/cli/logger.py
index c240f02..cac5d2e 100644
--- a/aria/cli/logger.py
+++ b/aria/cli/logger.py
@@ -19,6 +19,9 @@ import copy
 import logging
 from logutils import dictconfig
 
+import colorama
+from jinja2.environment import Template
+
 
 HIGH_VERBOSE = 3
 MEDIUM_VERBOSE = 2
@@ -130,3 +133,16 @@ class ModelLogIterator(object):
         for log in self._model_storage.log.iter(filters=filters, sort=self._sort):
             self._last_visited_id = log.id
             yield log
+
+colorama.init()
+
+
+class Color(object):
+    FORE = colorama.Fore
+    BACK = colorama.Back
+    STYLE = colorama.Style
+
+    @classmethod
+    def render_str(cls, str_to_stylize):
+        str_template = Template(str_to_stylize)
+        return str_template.render(FORE=cls.FORE, BACK=cls.BACK, STYLE=cls.STYLE)