Reimplemented explain feature
This commit is contained in:
@@ -83,6 +83,7 @@ class Sheerka(Concept):
|
||||
"test": self.test,
|
||||
"test_using_context": self.test_using_context
|
||||
}
|
||||
self.sheerka_pipeables = {}
|
||||
|
||||
@property
|
||||
def resolved_concepts_by_first_keyword(self):
|
||||
@@ -121,6 +122,15 @@ class Sheerka(Concept):
|
||||
|
||||
setattr(self, as_name, bound_method)
|
||||
|
||||
def add_pipeable(self, func_name, function):
|
||||
"""
|
||||
Adds a function that can bu used with pipe '|'
|
||||
:param func_name:
|
||||
:param function:
|
||||
:return:
|
||||
"""
|
||||
self.sheerka_pipeables[func_name] = function
|
||||
|
||||
def initialize(self, root_folder: str = None, save_execution_context=True):
|
||||
"""
|
||||
Starting Sheerka
|
||||
@@ -360,8 +370,11 @@ class Sheerka(Concept):
|
||||
if self.cache_manager.is_dirty:
|
||||
self.cache_manager.commit(execution_context)
|
||||
|
||||
if self.save_execution_context and self.load(self.name, "save_execution_context"):
|
||||
self.sdp.save_result(execution_context)
|
||||
try:
|
||||
if self.save_execution_context and self.load(self.name, "save_execution_context"):
|
||||
self.sdp.save_result(execution_context)
|
||||
except Exception as ex:
|
||||
self.log.error(f"Failed to save execution context. Reason: {ex}")
|
||||
|
||||
# # hack to save valid concept definition
|
||||
# if not self.during_restore:
|
||||
@@ -760,6 +773,9 @@ class Sheerka(Concept):
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
def get_last_execution(self):
|
||||
return self._last_execution
|
||||
|
||||
def test(self):
|
||||
return f"I have access to Sheerka !"
|
||||
|
||||
@@ -841,6 +857,28 @@ class Sheerka(Concept):
|
||||
|
||||
@staticmethod
|
||||
def init_logging(debug, loggers):
|
||||
def add_coloring_to_emit_ansi(fn):
|
||||
# add methods we need to the class
|
||||
def new(*args):
|
||||
levelno = args[1].levelno
|
||||
if levelno >= 50:
|
||||
color = '\x1b[31m' # red
|
||||
elif levelno >= 40:
|
||||
color = '\x1b[31m' # red
|
||||
elif levelno >= 30:
|
||||
color = '\x1b[33m' # yellow
|
||||
elif levelno >= 20:
|
||||
color = '\x1b[32m' # green
|
||||
elif levelno >= 10:
|
||||
color = '\x1b[35m' # pink
|
||||
else:
|
||||
color = '\x1b[0m' # normal
|
||||
args[1].msg = color + str(args[1].msg) + '\x1b[0m' # normal
|
||||
# print "after"
|
||||
return fn(*args)
|
||||
|
||||
return new
|
||||
|
||||
core.sheerka_logger.init_config(loggers)
|
||||
if debug:
|
||||
log_format = "%(asctime)s"
|
||||
@@ -853,3 +891,6 @@ class Sheerka(Concept):
|
||||
log_level = logging.INFO
|
||||
|
||||
logging.basicConfig(format=log_format, level=log_level, handlers=[console_handler])
|
||||
logging.addLevelName(logging.ERROR, "\033[1;41m%s\033[1;0m" % logging.getLevelName(logging.ERROR))
|
||||
# uncomment the following line to enable colors
|
||||
#logging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit)
|
||||
|
||||
Reference in New Issue
Block a user