|
|
|
@@ -28,19 +28,22 @@ class BaseDebugLogger:
|
|
|
|
|
BaseDebugLogger.ids[hint] = 0
|
|
|
|
|
return BaseDebugLogger.ids[hint]
|
|
|
|
|
|
|
|
|
|
def __init__(self, debug_manager, who, method_name, context_id, debug_id):
|
|
|
|
|
def __init__(self, debug_manager, context, who, method_name, debug_id):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def debug_entering(self, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def debug_log(self, text, is_error=False):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def debug_var(self, name, value, is_error=False, hint=None):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def debug_rule(self, rule, results):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def debug_log(self, text, is_error=False):
|
|
|
|
|
def debug_concept(self, concept, text=None, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def is_enabled(self):
|
|
|
|
@@ -57,12 +60,12 @@ class NullDebugLogger(BaseDebugLogger):
|
|
|
|
|
|
|
|
|
|
class ConsoleDebugLogger(BaseDebugLogger):
|
|
|
|
|
|
|
|
|
|
def __init__(self, debug_manager, service_name, method_name, context_id, debug_id):
|
|
|
|
|
BaseDebugLogger.__init__(self, debug_manager, service_name, method_name, context_id, debug_id)
|
|
|
|
|
def __init__(self, debug_manager, context, service_name, method_name, debug_id):
|
|
|
|
|
BaseDebugLogger.__init__(self, debug_manager, context, service_name, method_name, debug_id)
|
|
|
|
|
self.debug_manager = debug_manager
|
|
|
|
|
self.service_name = service_name
|
|
|
|
|
self.method_name = method_name
|
|
|
|
|
self.context_id = context_id
|
|
|
|
|
self.context = context
|
|
|
|
|
self.debug_id = debug_id
|
|
|
|
|
self.is_highlighted = ""
|
|
|
|
|
|
|
|
|
@@ -80,12 +83,16 @@ class ConsoleDebugLogger(BaseDebugLogger):
|
|
|
|
|
self.debug_manager.debug(self.prefix() + str_text)
|
|
|
|
|
self.debug_manager.debug(self.prefix() + str_vars)
|
|
|
|
|
|
|
|
|
|
def debug_log(self, text, is_error=False):
|
|
|
|
|
color = 'red' if is_error else 'blue'
|
|
|
|
|
self.debug_manager.debug(self.prefix() + f"{CCM[color]}..{text}{CCM['reset']}")
|
|
|
|
|
|
|
|
|
|
def debug_var(self, name, value, is_error=False, hint=None):
|
|
|
|
|
enabled = is_error or self.debug_manager.compute_var_debug(self.service_name,
|
|
|
|
|
enabled = is_error or self.debug_manager.compute_debug_var(self.context,
|
|
|
|
|
self.service_name,
|
|
|
|
|
self.method_name,
|
|
|
|
|
self.context_id,
|
|
|
|
|
name,
|
|
|
|
|
self.context_id)
|
|
|
|
|
self.debug_id)
|
|
|
|
|
if enabled == False:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
@@ -93,37 +100,51 @@ class ConsoleDebugLogger(BaseDebugLogger):
|
|
|
|
|
hint_str = f"({hint})" if hint is not None else ""
|
|
|
|
|
str_text = f"{CCM[color]}..{name}{hint_str}={CCM['reset']}"
|
|
|
|
|
str_vars = "" if isinstance(enabled, str) else pp.pformat(value)
|
|
|
|
|
if "\n" not in str(str_vars):
|
|
|
|
|
self.debug_manager.debug(self.prefix() + str_text + str_vars)
|
|
|
|
|
else:
|
|
|
|
|
self.debug_manager.debug(self.prefix() + str_text)
|
|
|
|
|
self.debug_manager.debug(self.prefix() + str_vars)
|
|
|
|
|
self.debug(str_text, str_vars)
|
|
|
|
|
|
|
|
|
|
def debug_rule(self, rule, results):
|
|
|
|
|
if not self.debug_manager.compute_debug_rule(rule.id, self.context_id, self.debug_id):
|
|
|
|
|
if not self.debug_manager.compute_debug_rule(self.context,
|
|
|
|
|
self.service_name,
|
|
|
|
|
self.method_name,
|
|
|
|
|
rule.id,
|
|
|
|
|
self.debug_id):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
str_text = f"{CCM['green']}..results({rule.id})={CCM['reset']}"
|
|
|
|
|
str_vars = pp.pformat(results)
|
|
|
|
|
self.debug(str_text, str_vars)
|
|
|
|
|
|
|
|
|
|
def debug_concept(self, concept, text=None, **kwargs):
|
|
|
|
|
raw = kwargs.pop('raw', None)
|
|
|
|
|
if not self.debug_manager.compute_debug_concept(self.context,
|
|
|
|
|
self.service_name,
|
|
|
|
|
self.method_name,
|
|
|
|
|
concept.id,
|
|
|
|
|
self.debug_id):
|
|
|
|
|
return
|
|
|
|
|
str_vars = raw if raw else pp.pformat(kwargs) if kwargs else ""
|
|
|
|
|
text = " - " + text if text is not None else ""
|
|
|
|
|
colon = ": " if str_vars else ""
|
|
|
|
|
str_text = f"{CCM['cyan']}..concept#{concept.id}{text}{colon} {CCM['reset']}"
|
|
|
|
|
|
|
|
|
|
self.debug(str_text, str_vars)
|
|
|
|
|
|
|
|
|
|
def debug(self, str_text, str_vars):
|
|
|
|
|
if "\n" not in str(str_vars):
|
|
|
|
|
self.debug_manager.debug(self.prefix() + str_text + str_vars)
|
|
|
|
|
else:
|
|
|
|
|
self.debug_manager.debug(self.prefix() + str_text)
|
|
|
|
|
self.debug_manager.debug(self.prefix() + str_vars)
|
|
|
|
|
|
|
|
|
|
def debug_log(self, text, is_error=False):
|
|
|
|
|
color = 'red' if is_error else 'blue'
|
|
|
|
|
self.debug_manager.debug(self.prefix() + f"{CCM[color]}..{text}{CCM['reset']}")
|
|
|
|
|
|
|
|
|
|
def prefix(self):
|
|
|
|
|
return f"[{self.context_id:2}][{self.debug_id:2}] {self.is_highlighted}"
|
|
|
|
|
return f"[{self.context.id:2}][{self.debug_id:2}] {self.is_highlighted}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class DebugVarSetting:
|
|
|
|
|
class DebugItem:
|
|
|
|
|
item: str
|
|
|
|
|
service_name: str
|
|
|
|
|
method_name: str
|
|
|
|
|
variable_name: str
|
|
|
|
|
context_id: int
|
|
|
|
|
context_children: bool
|
|
|
|
|
debug_id: int
|
|
|
|
@@ -132,15 +153,6 @@ class DebugVarSetting:
|
|
|
|
|
enabled: bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class DebugRuleSetting:
|
|
|
|
|
rule_id: str
|
|
|
|
|
context_id: int
|
|
|
|
|
debug_id: int
|
|
|
|
|
|
|
|
|
|
enabled: bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SheerkaDebugManager(BaseService):
|
|
|
|
|
NAME = "Debug"
|
|
|
|
|
PREFIX = "debug."
|
|
|
|
@@ -155,23 +167,28 @@ class SheerkaDebugManager(BaseService):
|
|
|
|
|
self.variable_cache = set() # debug for specific variable
|
|
|
|
|
self.debug_vars_settings = []
|
|
|
|
|
self.debug_rules_settings = []
|
|
|
|
|
self.debug_concepts_settings = []
|
|
|
|
|
|
|
|
|
|
def initialize(self):
|
|
|
|
|
self.sheerka.bind_service_method(self.set_debug, True)
|
|
|
|
|
# TO REMOVE ???
|
|
|
|
|
self.sheerka.bind_service_method(self.set_explicit, True)
|
|
|
|
|
self.sheerka.bind_service_method(self.activate_debug_for, True)
|
|
|
|
|
self.sheerka.bind_service_method(self.deactivate_debug_for, True)
|
|
|
|
|
self.sheerka.bind_service_method(self.debug_activated, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.debug_activated_for, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.get_context_debug_mode, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.debug_rule, True)
|
|
|
|
|
self.sheerka.bind_service_method(self.debug_rule_activated, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.inspect, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.debug, False, visible=False)
|
|
|
|
|
|
|
|
|
|
self.sheerka.bind_service_method(self.set_debug, True)
|
|
|
|
|
self.sheerka.bind_service_method(self.inspect, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.get_debugger, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.debug_var, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.reset_debug, False)
|
|
|
|
|
self.sheerka.bind_service_method(self.get_debug_settings, False, as_name="debug_settings")
|
|
|
|
|
self.sheerka.bind_service_method(self.debug_var, True)
|
|
|
|
|
self.sheerka.bind_service_method(self.debug_rule, True)
|
|
|
|
|
self.sheerka.bind_service_method(self.debug_concept, True)
|
|
|
|
|
|
|
|
|
|
# self.sheerka.bind_service_method(self.get_debug_settings, False, as_name="debug_settings")
|
|
|
|
|
|
|
|
|
|
def initialize_deferred(self, context, is_first_time):
|
|
|
|
|
self.restore_values("activated",
|
|
|
|
@@ -179,7 +196,8 @@ class SheerkaDebugManager(BaseService):
|
|
|
|
|
"context_cache",
|
|
|
|
|
"variable_cache",
|
|
|
|
|
"debug_vars_settings",
|
|
|
|
|
"debug_rules_settings")
|
|
|
|
|
"debug_rules_settings",
|
|
|
|
|
"debug_concepts_settings")
|
|
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
|
"""
|
|
|
|
@@ -191,6 +209,7 @@ class SheerkaDebugManager(BaseService):
|
|
|
|
|
self.variable_cache.clear()
|
|
|
|
|
self.debug_vars_settings.clear()
|
|
|
|
|
self.debug_rules_settings.clear()
|
|
|
|
|
self.debug_concepts_settings.clear()
|
|
|
|
|
|
|
|
|
|
def set_debug(self, context, value=True):
|
|
|
|
|
self.activated = value
|
|
|
|
@@ -289,26 +308,30 @@ class SheerkaDebugManager(BaseService):
|
|
|
|
|
print(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
def get_debugger(self, context, who, method_name):
|
|
|
|
|
if self.compute_debug(who, method_name, context):
|
|
|
|
|
if self.compute_debug(context, who, method_name):
|
|
|
|
|
debug_id = ConsoleDebugLogger.next_id(context.event.get_digest() + str(context.id))
|
|
|
|
|
return ConsoleDebugLogger(self, who, method_name, context.id, debug_id)
|
|
|
|
|
return ConsoleDebugLogger(self, context, who, method_name, debug_id)
|
|
|
|
|
|
|
|
|
|
return NullDebugLogger()
|
|
|
|
|
|
|
|
|
|
def debug_var(self, context,
|
|
|
|
|
service=None,
|
|
|
|
|
method=None,
|
|
|
|
|
variable=None,
|
|
|
|
|
context_id=None,
|
|
|
|
|
context_children=False,
|
|
|
|
|
debug_id=None,
|
|
|
|
|
debug_children=False,
|
|
|
|
|
enabled=True):
|
|
|
|
|
def add_or_update_debug_item(self, context,
|
|
|
|
|
item_type,
|
|
|
|
|
item=None,
|
|
|
|
|
service=None,
|
|
|
|
|
method=None,
|
|
|
|
|
context_id=None,
|
|
|
|
|
context_children=False,
|
|
|
|
|
debug_id=None,
|
|
|
|
|
debug_children=False,
|
|
|
|
|
enabled=True):
|
|
|
|
|
|
|
|
|
|
for setting in self.debug_vars_settings:
|
|
|
|
|
if setting.service_name == service and \
|
|
|
|
|
# if the setting already exist, update it
|
|
|
|
|
item_type_full_name = self.container_name(item_type)
|
|
|
|
|
items_container = getattr(self, item_type_full_name)
|
|
|
|
|
for setting in items_container:
|
|
|
|
|
if setting.item == item and \
|
|
|
|
|
setting.service_name == service and \
|
|
|
|
|
setting.method_name == method and \
|
|
|
|
|
setting.variable_name == variable and \
|
|
|
|
|
setting.context_id == context_id and \
|
|
|
|
|
setting.context_children == context_children and \
|
|
|
|
|
setting.debug_id == debug_id and \
|
|
|
|
@@ -316,64 +339,77 @@ class SheerkaDebugManager(BaseService):
|
|
|
|
|
setting.enabled = enabled
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
self.debug_vars_settings.append(DebugVarSetting(service,
|
|
|
|
|
method,
|
|
|
|
|
variable,
|
|
|
|
|
context_id,
|
|
|
|
|
context_children,
|
|
|
|
|
debug_id,
|
|
|
|
|
debug_children,
|
|
|
|
|
enabled))
|
|
|
|
|
items_container.append(DebugItem(item,
|
|
|
|
|
service,
|
|
|
|
|
method,
|
|
|
|
|
context_id,
|
|
|
|
|
context_children,
|
|
|
|
|
debug_id,
|
|
|
|
|
debug_children,
|
|
|
|
|
enabled))
|
|
|
|
|
|
|
|
|
|
self.sheerka.record_var(context, self.NAME, "debug_vars_settings", self.debug_vars_settings)
|
|
|
|
|
self.sheerka.record_var(context, self.NAME, item_type_full_name, items_container)
|
|
|
|
|
return self.sheerka.ret(SheerkaDebugManager.NAME, True, self.sheerka.new(BuiltinConcepts.SUCCESS))
|
|
|
|
|
|
|
|
|
|
def reset_debug(self, context):
|
|
|
|
|
self.debug_vars_settings.clear()
|
|
|
|
|
self.debug_rules_settings.clear()
|
|
|
|
|
self.sheerka.record_var(context, self.NAME, "debug_vars_settings", self.debug_vars_settings)
|
|
|
|
|
self.sheerka.record_var(context, self.NAME, "debug_rules_settings", self.debug_vars_settings)
|
|
|
|
|
return self.sheerka.ret(SheerkaDebugManager.NAME, True, self.sheerka.new(BuiltinConcepts.SUCCESS))
|
|
|
|
|
|
|
|
|
|
def compute_debug(self, service_name, method_name, context):
|
|
|
|
|
def compute_debug(self, context, service_name, method_name):
|
|
|
|
|
"""
|
|
|
|
|
Using the debug info, tells if the debug is active for a given service, method, context (and debug_id)
|
|
|
|
|
:param context:
|
|
|
|
|
:param service_name:
|
|
|
|
|
:param method_name:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
if not self.activated:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
selected = []
|
|
|
|
|
for setting in self.debug_vars_settings:
|
|
|
|
|
if setting.service_name is None and setting.method_name is None and setting.context_id is None:
|
|
|
|
|
continue
|
|
|
|
|
for item_type in ["vars", "rules", "concepts"]:
|
|
|
|
|
for setting in getattr(self, self.container_name(item_type)):
|
|
|
|
|
if setting.service_name is None and setting.method_name is None and setting.context_id is None:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if (setting.service_name is None or setting.service_name == service_name) and \
|
|
|
|
|
(setting.method_name is None or setting.method_name == method_name) and \
|
|
|
|
|
(setting.context_id is None or setting.context_id == context.id or (
|
|
|
|
|
setting.context_children and context.has_parent(setting.context_id))):
|
|
|
|
|
selected.append(setting.enabled)
|
|
|
|
|
if (setting.service_name is None or setting.service_name == service_name) and \
|
|
|
|
|
(setting.method_name is None or setting.method_name == method_name) and \
|
|
|
|
|
(setting.context_id is None or setting.context_id == context.id or (
|
|
|
|
|
setting.context_children and context.has_parent(setting.context_id))):
|
|
|
|
|
selected.append(setting.enabled)
|
|
|
|
|
|
|
|
|
|
if len(selected) == 0:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
res = selected[0]
|
|
|
|
|
for enabled in selected[1:]:
|
|
|
|
|
res &= enabled
|
|
|
|
|
res |= enabled
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
def compute_var_debug(self, service_name, method_name, context_id, variable_name, debug_id):
|
|
|
|
|
def compute_debug_item(self, item_type, context, service_name, method_name, item, debug_id):
|
|
|
|
|
"""
|
|
|
|
|
Using the debug info, tells if debug is activated for a given item
|
|
|
|
|
:param context:
|
|
|
|
|
:param item_type:
|
|
|
|
|
:param service_name:
|
|
|
|
|
:param method_name:
|
|
|
|
|
:param item:
|
|
|
|
|
:param debug_id:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
if not self.activated:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
selected = []
|
|
|
|
|
for setting in self.debug_vars_settings:
|
|
|
|
|
if setting.variable_name is None and setting.debug_id is None:
|
|
|
|
|
|
|
|
|
|
for setting in getattr(self, self.container_name(item_type)):
|
|
|
|
|
if setting.item is None and setting.debug_id is None:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if (setting.service_name is None or setting.service_name == service_name) and \
|
|
|
|
|
(setting.method_name is None or setting.method_name == method_name) and \
|
|
|
|
|
(setting.context_id is None or setting.context_id == context_id) and \
|
|
|
|
|
(setting.variable_name is None or
|
|
|
|
|
setting.variable_name == "*" or
|
|
|
|
|
setting.variable_name == variable_name) and \
|
|
|
|
|
(setting.context_id is None or setting.context_id == context.id or (
|
|
|
|
|
setting.context_children and context.has_parent(setting.context_id))) and \
|
|
|
|
|
(setting.item is None or
|
|
|
|
|
setting.item == "*" or
|
|
|
|
|
setting.item == item) and \
|
|
|
|
|
(setting.debug_id is None or setting.debug_id == debug_id):
|
|
|
|
|
selected.append(setting.enabled)
|
|
|
|
|
|
|
|
|
@@ -392,56 +428,246 @@ class SheerkaDebugManager(BaseService):
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
def debug_rule(self, context, rule=None, context_id=None, debug_id=None, enabled=True):
|
|
|
|
|
def reset_debug(self, context):
|
|
|
|
|
for item_type in ["vars", "rules", "concepts"]:
|
|
|
|
|
setting_name = self.container_name(item_type)
|
|
|
|
|
settings = getattr(self, setting_name)
|
|
|
|
|
settings.clear()
|
|
|
|
|
self.sheerka.record_var(context, self.NAME, setting_name, settings)
|
|
|
|
|
|
|
|
|
|
return self.sheerka.ret(SheerkaDebugManager.NAME, True, self.sheerka.new(BuiltinConcepts.SUCCESS))
|
|
|
|
|
|
|
|
|
|
def debug_var(self, context, *args, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Add a debug rule request
|
|
|
|
|
Adds debug item for variables
|
|
|
|
|
debug_var(<service>.<method>.<var>, <context_id>[+], <debug_id>)
|
|
|
|
|
with service, method and vat that can be '*'
|
|
|
|
|
:param context:
|
|
|
|
|
:param rule:
|
|
|
|
|
:param context_id:
|
|
|
|
|
:param debug_id:
|
|
|
|
|
:param enabled:
|
|
|
|
|
:param args:
|
|
|
|
|
:param kwargs:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
rule = str(rule) if rule is not None else None
|
|
|
|
|
for setting in self.debug_rules_settings:
|
|
|
|
|
if setting.rule_id == rule and \
|
|
|
|
|
setting.context_id == context_id and \
|
|
|
|
|
setting.debug_id == debug_id:
|
|
|
|
|
setting.enabled = enabled
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
self.debug_rules_settings.append(DebugRuleSetting(rule,
|
|
|
|
|
context_id,
|
|
|
|
|
debug_id,
|
|
|
|
|
enabled))
|
|
|
|
|
i, s, m, c_id, c_children, d, e = self.parse_debug_args("variable", *args, **kwargs)
|
|
|
|
|
return self.add_or_update_debug_item(context, "vars", i, s, m, c_id, c_children, d, False, e)
|
|
|
|
|
|
|
|
|
|
self.sheerka.record_var(context, self.NAME, "debug_rules_settings", self.debug_rules_settings)
|
|
|
|
|
return self.sheerka.ret(SheerkaDebugManager.NAME, True, self.sheerka.new(BuiltinConcepts.SUCCESS))
|
|
|
|
|
def debug_rule(self, context, *args, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Adds debug item for rules
|
|
|
|
|
debug_var(<service>.<method>.<rule>, <context_id>[+], <debug_id>)
|
|
|
|
|
with service, method and rule that can be '*'
|
|
|
|
|
debug_var(rule_id, <context_id>[+], <debug_id>)
|
|
|
|
|
:param context:
|
|
|
|
|
:param args:
|
|
|
|
|
:param kwargs:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
i, s, m, c_id, c_children, d, e = self.parse_debug_args("rule", *args, **kwargs)
|
|
|
|
|
return self.add_or_update_debug_item(context, "rules", i, s, m, c_id, c_children, d, False, e)
|
|
|
|
|
|
|
|
|
|
def compute_debug_rule(self, rule_id, context_id, debug_id):
|
|
|
|
|
if not self.activated:
|
|
|
|
|
return False
|
|
|
|
|
def debug_concept(self, context, *args, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Adds debug item for concepts
|
|
|
|
|
debug_var(<service>.<method>.<concept>, <context_id>[+], <debug_id>)
|
|
|
|
|
with service, method and vat that can be '*'
|
|
|
|
|
debug_var(concept_id, <context_id>[+], <debug_id>)
|
|
|
|
|
:param context:
|
|
|
|
|
:param args:
|
|
|
|
|
:param kwargs:
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
i, s, m, c_id, c_children, d, e = self.parse_debug_args("concept", *args, **kwargs)
|
|
|
|
|
return self.add_or_update_debug_item(context, "concepts", i, s, m, c_id, c_children, d, False, e)
|
|
|
|
|
|
|
|
|
|
selected = []
|
|
|
|
|
for setting in self.debug_rules_settings:
|
|
|
|
|
if (setting.rule_id is None or setting.rule_id == rule_id) and \
|
|
|
|
|
(setting.context_id is None or setting.context_id == context_id) and \
|
|
|
|
|
(setting.debug_id is None or setting.debug_id == debug_id):
|
|
|
|
|
selected.append(setting.enabled)
|
|
|
|
|
def compute_debug_var(self, context, service_name, method_name, item, debug_id):
|
|
|
|
|
return self.compute_debug_item("vars", context, service_name, method_name, item, debug_id)
|
|
|
|
|
|
|
|
|
|
if len(selected) == 0:
|
|
|
|
|
return False
|
|
|
|
|
def compute_debug_concept(self, context, service_name, method_name, item, debug_id):
|
|
|
|
|
return self.compute_debug_item("concepts", context, service_name, method_name, item, debug_id)
|
|
|
|
|
|
|
|
|
|
res = selected[0]
|
|
|
|
|
for enabled in selected[1:]:
|
|
|
|
|
res &= enabled
|
|
|
|
|
def compute_debug_rule(self, context, service_name, method_name, item, debug_id):
|
|
|
|
|
return self.compute_debug_item("rules", context, service_name, method_name, item, debug_id)
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
@staticmethod
|
|
|
|
|
def container_name(item_type):
|
|
|
|
|
return f"debug_{item_type}_settings"
|
|
|
|
|
|
|
|
|
|
def reset_debug_rules(self, context):
|
|
|
|
|
self.debug_rules_settings.clear()
|
|
|
|
|
self.sheerka.record_var(context, self.NAME, "debug_rules_settings", self.debug_rules_settings)
|
|
|
|
|
return self.sheerka.ret(SheerkaDebugManager.NAME, True, self.sheerka.new(BuiltinConcepts.SUCCESS))
|
|
|
|
|
@staticmethod
|
|
|
|
|
def parse_debug_args(item_name, *args, **kwargs):
|
|
|
|
|
service, method_name, context_id, context_children, item, debug_id, enabled = None, None, None, False, None, None, True
|
|
|
|
|
if len(args) > 0:
|
|
|
|
|
if args[0] is None or args[0] == "":
|
|
|
|
|
pass
|
|
|
|
|
elif isinstance(args[0], int):
|
|
|
|
|
item = str(args[0])
|
|
|
|
|
else:
|
|
|
|
|
parts = args[0].split(".")
|
|
|
|
|
service = None if parts[0] == "*" else parts[0]
|
|
|
|
|
if len(parts) > 1:
|
|
|
|
|
method_name = None if parts[1] == "*" else parts[1]
|
|
|
|
|
if len(parts) > 2:
|
|
|
|
|
item = parts[2]
|
|
|
|
|
|
|
|
|
|
def get_debug_settings(self):
|
|
|
|
|
return self.sheerka.new(BuiltinConcepts.TO_LIST, body=self.debug_vars_settings)
|
|
|
|
|
if len(args) > 1:
|
|
|
|
|
context_part = args[1]
|
|
|
|
|
if isinstance(context_part, int):
|
|
|
|
|
context_id = context_part
|
|
|
|
|
if isinstance(context_part, str):
|
|
|
|
|
m = SheerkaDebugManager.children_activation_regex.match(context_part)
|
|
|
|
|
if m:
|
|
|
|
|
context_id = int(m.group(1))
|
|
|
|
|
context_children = True
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
context_id = int(context_part)
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if len(args) > 2:
|
|
|
|
|
debug_id = args[2]
|
|
|
|
|
|
|
|
|
|
service = kwargs.get("service", service)
|
|
|
|
|
method_name = kwargs.get("method", method_name)
|
|
|
|
|
context_id = kwargs.get("context_id", context_id)
|
|
|
|
|
context_children = kwargs.get("context_children", context_children)
|
|
|
|
|
item = kwargs.get(item_name, item)
|
|
|
|
|
debug_id = kwargs.get("debug_id", debug_id)
|
|
|
|
|
enabled = kwargs.get("enabled", enabled)
|
|
|
|
|
|
|
|
|
|
return item, service, method_name, context_id, context_children, debug_id, enabled
|
|
|
|
|
|
|
|
|
|
# def debug_rule(self, context, rule=None, context_id=None, debug_id=None, enabled=True):
|
|
|
|
|
# """
|
|
|
|
|
# Add a debug rule request
|
|
|
|
|
# :param context:
|
|
|
|
|
# :param rule:
|
|
|
|
|
# :param context_id:
|
|
|
|
|
# :param debug_id:
|
|
|
|
|
# :param enabled:
|
|
|
|
|
# :return:
|
|
|
|
|
# """
|
|
|
|
|
# rule = str(rule) if rule is not None else None
|
|
|
|
|
# for setting in self.debug_rules_settings:
|
|
|
|
|
# if setting.rule_id == rule and \
|
|
|
|
|
# setting.context_id == context_id and \
|
|
|
|
|
# setting.debug_id == debug_id:
|
|
|
|
|
# setting.enabled = enabled
|
|
|
|
|
# break
|
|
|
|
|
# else:
|
|
|
|
|
# self.debug_rules_settings.append(DebugRuleSetting(rule,
|
|
|
|
|
# context_id,
|
|
|
|
|
# debug_id,
|
|
|
|
|
# enabled))
|
|
|
|
|
#
|
|
|
|
|
# self.sheerka.record_var(context, self.NAME, "debug_rules_settings", self.debug_rules_settings)
|
|
|
|
|
# return self.sheerka.ret(SheerkaDebugManager.NAME, True, self.sheerka.new(BuiltinConcepts.SUCCESS))
|
|
|
|
|
#
|
|
|
|
|
# def debug_concept(self, context, concept=None, context_id=None, debug_id=None, enabled=True):
|
|
|
|
|
# """
|
|
|
|
|
# Add a debug rule request
|
|
|
|
|
# :param context:
|
|
|
|
|
# :param concept:
|
|
|
|
|
# :param context_id:
|
|
|
|
|
# :param debug_id:
|
|
|
|
|
# :param enabled:
|
|
|
|
|
# :return:
|
|
|
|
|
# """
|
|
|
|
|
# concept_id = concept.id if isinstance(concept, Concept) else str(concept) if concept is not None else None
|
|
|
|
|
# for setting in self.debug_concepts_settings:
|
|
|
|
|
# if setting.concept_id == concept_id and \
|
|
|
|
|
# setting.context_id == context_id and \
|
|
|
|
|
# setting.debug_id == debug_id:
|
|
|
|
|
# setting.enabled = enabled
|
|
|
|
|
# break
|
|
|
|
|
# else:
|
|
|
|
|
# self.debug_concepts_settings.append(DebugConceptSetting(concept_id,
|
|
|
|
|
# context_id,
|
|
|
|
|
# debug_id,
|
|
|
|
|
# enabled))
|
|
|
|
|
#
|
|
|
|
|
# self.sheerka.record_var(context, self.NAME, "debug_concepts_settings", self.debug_concepts_settings)
|
|
|
|
|
# return self.sheerka.ret(SheerkaDebugManager.NAME, True, self.sheerka.new(BuiltinConcepts.SUCCESS))
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# def compute_debug_var(self, service_name, method_name, context_id, variable_name, debug_id):
|
|
|
|
|
# if not self.activated:
|
|
|
|
|
# return False
|
|
|
|
|
#
|
|
|
|
|
# selected = []
|
|
|
|
|
# for setting in self.debug_vars_settings:
|
|
|
|
|
# if setting.variable_name is None and setting.debug_id is None:
|
|
|
|
|
# continue
|
|
|
|
|
#
|
|
|
|
|
# if (setting.service_name is None or setting.service_name == service_name) and \
|
|
|
|
|
# (setting.method_name is None or setting.method_name == method_name) and \
|
|
|
|
|
# (setting.context_id is None or setting.context_id == context_id) and \
|
|
|
|
|
# (setting.variable_name is None or
|
|
|
|
|
# setting.variable_name == "*" or
|
|
|
|
|
# setting.variable_name == variable_name) and \
|
|
|
|
|
# (setting.debug_id is None or setting.debug_id == debug_id):
|
|
|
|
|
# selected.append(setting.enabled)
|
|
|
|
|
#
|
|
|
|
|
# if len(selected) == 0:
|
|
|
|
|
# return False
|
|
|
|
|
#
|
|
|
|
|
# res = selected[0]
|
|
|
|
|
# for enabled in selected[1:]:
|
|
|
|
|
# if res == False or enabled == False:
|
|
|
|
|
# return False
|
|
|
|
|
#
|
|
|
|
|
# if isinstance(res, str):
|
|
|
|
|
# continue
|
|
|
|
|
#
|
|
|
|
|
# res = enabled
|
|
|
|
|
#
|
|
|
|
|
# return res
|
|
|
|
|
#
|
|
|
|
|
# def compute_debug_rule(self, rule_id, context_id, debug_id):
|
|
|
|
|
# if not self.activated:
|
|
|
|
|
# return False
|
|
|
|
|
#
|
|
|
|
|
# selected = []
|
|
|
|
|
# for setting in self.debug_rules_settings:
|
|
|
|
|
# if (setting.rule_id is None or setting.rule_id == rule_id) and \
|
|
|
|
|
# (setting.context_id is None or setting.context_id == context_id) and \
|
|
|
|
|
# (setting.debug_id is None or setting.debug_id == debug_id):
|
|
|
|
|
# selected.append(setting.enabled)
|
|
|
|
|
#
|
|
|
|
|
# if len(selected) == 0:
|
|
|
|
|
# return False
|
|
|
|
|
#
|
|
|
|
|
# res = selected[0]
|
|
|
|
|
# for enabled in selected[1:]:
|
|
|
|
|
# res &= enabled
|
|
|
|
|
#
|
|
|
|
|
# return res
|
|
|
|
|
#
|
|
|
|
|
# def compute_debug_concept(self, concept_id, context_id, debug_id):
|
|
|
|
|
# if not self.activated:
|
|
|
|
|
# return False
|
|
|
|
|
#
|
|
|
|
|
# selected = []
|
|
|
|
|
# for setting in self.debug_concepts_settings:
|
|
|
|
|
# if (setting.concept_id is None or setting.concept_id == concept_id) and \
|
|
|
|
|
# (setting.context_id is None or setting.context_id == context_id) and \
|
|
|
|
|
# (setting.debug_id is None or setting.debug_id == debug_id):
|
|
|
|
|
# selected.append(setting.enabled)
|
|
|
|
|
#
|
|
|
|
|
# if len(selected) == 0:
|
|
|
|
|
# return False
|
|
|
|
|
#
|
|
|
|
|
# res = selected[0]
|
|
|
|
|
# for enabled in selected[1:]:
|
|
|
|
|
# res &= enabled
|
|
|
|
|
#
|
|
|
|
|
# return res
|
|
|
|
|
#
|
|
|
|
|
# def reset_debug_rules(self, context):
|
|
|
|
|
# self.debug_rules_settings.clear()
|
|
|
|
|
# self.sheerka.record_var(context, self.NAME, "debug_rules_settings", self.debug_rules_settings)
|
|
|
|
|
# return self.sheerka.ret(SheerkaDebugManager.NAME, True, self.sheerka.new(BuiltinConcepts.SUCCESS))
|
|
|
|
|
#
|
|
|
|
|
# def get_debug_settings(self):
|
|
|
|
|
# lst = self.debug_vars_settings + self.debug_concepts_settings + self.debug_rules_settings
|
|
|
|
|
# return self.sheerka.new(BuiltinConcepts.TO_LIST, body=lst)
|
|
|
|
|