Commit 7ec9c514 authored by unknown's avatar unknown

bug fix

parent 93639f28
Pipeline #3308 passed with stage
in 27 seconds
......@@ -2,15 +2,13 @@
@author Jakub Dolejsi
"""
import functools
from typing import Dict
from parse.ReportSet import ReportSet
from parse.Tool import Tool
class GenericParser:
"""
Base class for parsing reports. All implemented tools for parsing report must inherit from this class
"""
class GenericParser(object):
all_tools = list()
internal_structure = ReportSet()
tool = None
......@@ -18,32 +16,29 @@ class GenericParser:
def __init__(self, report: str):
self.report = report
def register_tool(self):
def register_tool(f):
"""
Register tool decorator
@return:wrapper method
Decorator for report tools registration
@return:
"""
def wrapper(this):
this.tool = Tool()
this(this)
this.tool.supported_extensions.append('txt')
this.tool.class_name = this.__name__
def wrapper(self):
self.tool = Tool()
f(self)
self.tool.supported_extensions.append('txt')
self.tool.class_name = self.__name__
# self.all_tools.append(self.tool)
GenericParser.all_tools.append(this.tool)
GenericParser.all_tools.append(self.tool)
return wrapper
def parse(self):
"""
Generic parse method, which all parses must implement
@return: None
"""
pass
@classmethod
def get_tools(cls):
"""
Retrieve all registered tools
@return: list of registered tools
@return: list of all registered tools
"""
return [x.get() for x in cls.all_tools]
......@@ -51,9 +46,9 @@ class GenericParser:
@classmethod
def get_tool_by_name(cls, name):
"""
Find parsing tool by registered name
@param name: nam of the parsing tools
@return: tool if found, else None
Retrieve parsing tool by it registered name
@param name: name of the tool
@return: found tool
"""
for tool in cls.all_tools:
if tool.name == name:
......@@ -61,41 +56,27 @@ class GenericParser:
return None
def set_object_property(self, obj, attr, val):
"""
Wrapper at set attribute dunder method
@param obj: input user object
@param attr: index
@param val: value
@return: None
"""
pre, _, post = attr.rpartition('.')
return setattr(self.__rgetattr(obj, pre) if pre else obj, post, val)
def __rgetattr(self, obj, attr, *args):
"""
Wrapper at get attribute dunder method
@param obj: input user object
@param attr: index
@param args: nested object
@return: Retrieved attribute
"""
def _getattr(obj, attr):
return getattr(obj, attr, *args)
return functools.reduce(_getattr, [obj] + attr.split('.'))
def init_backtrace(self, rep, number):
def init_backtrace(self, rep, n):
"""
Initialize Report object with nested backtrace
@param rep: Report object
@param number: number of nested objects
@param n: number of nested objects
@return: Initialized Report object and array of nested backtrace properties
"""
arr = ['Backtrace']
for i in range(1, number):
for i in range(1, n):
arr.append('Backtrace' + ('.Backtrace' * i))
for _, i in zip(range(number), arr):
for r, i in zip(range(n), arr):
self.set_object_property(rep, i, self.internal_structure.create_new_report())
# set first index to emtpy string because in regex loop we need something and this index
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment