# Path: XulDebugTool/logcatapi/Logcat.py
# class STCLogger():
#     DEBUG = "debug"
#     INFO = "info"
#     WARNING = "warning"
#     ERROR = "error"
#     CRITICAL = "critical"
#     def __init__(self):
# 
#         self.loggername = "STCLogger"
#         #当前日志模式
#         self.setLogLevel(self.INFO)
# 
#         #logging.basicConfig(level=logging.DEBUG)
#         self.logger = logging.getLogger(self.loggername)
# 
#         self.logger.setLevel(logging.DEBUG)
# 
#         # create a file handler
#         self.handler = logging.FileHandler(ConfigHelper.LOGCATPATH, "a", encoding="UTF-8")
#         self.handler.setLevel(logging.DEBUG)
# 
#         # create a logging format
#         self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#         self.handler.setFormatter(self.formatter)
# 
#         # add the handlers to the logger
#         self.logger.addHandler(self.handler)
# 
#     def removeHandler(self):
#         self.logger.removeHandler(self.handler)
#         return
# 
#     def e(self, *args):
#         self.logger.error(args)
#         self.filterLog(self.ERROR,args)
#         self.removeHandler()
#         return
# 
# 
#     def w(self, *args):
#         self.logger.warning(args)
#         self.filterLog(self.WARNING, args)
#         self.removeHandler()
#         return
# 
#     def i(self, *args):
#         self.logger.info(args)
#         self.filterLog(self.INFO, args)
#         self.removeHandler()
#         return
# 
#     def d(self, *args):
#         self.logger.debug(args)
#         self.filterLog(self.DEBUG, args)
#         self.removeHandler()
#         return
# 
#     def c(self, *args):
#         self.logger.critical(args)
#         self.filterLog(self.CRITICAL, args)
#         self.removeHandler()
#         return
# 
# 
# 
#     def filterLog(self,mode, args):
#         preLevel = self.getCurLogLevel(mode)
#         if preLevel >= self.level:
#             ConsoleController.windowPrintInfo(self.loggername, mode, args)
#         else:
#             return
# 
#     def setLogLevel(self,level):
#         if level is self.DEBUG:
#             self.level = 0
#         elif level is self.INFO:
#             self.level = 1
#         elif level is self.WARNING:
#             self.level = 2
#         elif level is self.ERROR:
#             self.level = 3
#         elif level is self.CRITICAL:
#             self.level = 4
# 
#     def getCurLogLevel(self,level):
#         if level is self.DEBUG:
#             return 0
#         elif level is self.INFO:
#             return 1
#         elif level is self.WARNING:
#             return 2
#         elif level is self.ERROR:
#             return 3
#         elif level is self.CRITICAL:
#             return 4


import json
import sqlite3
import xmltodict
from PyQt5.QtWebEngineWidgets import QWebEngineScript
from lxml import etree
from XulDebugTool.logcatapi.Logcat import STCLogger
    windowHeight = 1080
    itemHeight = 30

    @staticmethod
    def xml2json(xml, tag):
        # 将xml的某个tag转化成json
        doc = xmltodict.parse(xml)[tag]
        if doc != None:
            str = json.dumps(dict(doc))
            return json.loads(str)
        else:
            return ''

    @staticmethod
    def scriptCreator(path, name, page):
        script = QWebEngineScript()
        f = open(path, 'r')
        script.setSourceCode(f.read())
        script.setInjectionPoint(QWebEngineScript.DocumentReady)
        script.setName(name)
        script.setWorldId(QWebEngineScript.MainWorld)
        page.scripts().insert(script)

    @staticmethod
    def findNodeById(id, xml):
        root = etree.fromstring(xml)
        # print(etree.tostring(root, pretty_print=True).decode('utf-8'))
        try:
            list = root.xpath("//*[@id=%s]" % id)
        except Exception as e:

# Path: XulDebugTool/logcatapi/Logcat.py
# class STCLogger():
#     DEBUG = "debug"
#     INFO = "info"
#     WARNING = "warning"
#     ERROR = "error"
#     CRITICAL = "critical"
#     def __init__(self):
# 
#         self.loggername = "STCLogger"
#         #当前日志模式
#         self.setLogLevel(self.INFO)
# 
#         #logging.basicConfig(level=logging.DEBUG)
#         self.logger = logging.getLogger(self.loggername)
# 
#         self.logger.setLevel(logging.DEBUG)
# 
#         # create a file handler
#         self.handler = logging.FileHandler(ConfigHelper.LOGCATPATH, "a", encoding="UTF-8")
#         self.handler.setLevel(logging.DEBUG)
# 
#         # create a logging format
#         self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#         self.handler.setFormatter(self.formatter)
# 
#         # add the handlers to the logger
#         self.logger.addHandler(self.handler)
# 
#     def removeHandler(self):
#         self.logger.removeHandler(self.handler)
#         return
# 
#     def e(self, *args):
#         self.logger.error(args)
#         self.filterLog(self.ERROR,args)
#         self.removeHandler()
#         return
# 
# 
#     def w(self, *args):
#         self.logger.warning(args)
#         self.filterLog(self.WARNING, args)
#         self.removeHandler()
#         return
# 
#     def i(self, *args):
#         self.logger.info(args)
#         self.filterLog(self.INFO, args)
#         self.removeHandler()
#         return
# 
#     def d(self, *args):
#         self.logger.debug(args)
#         self.filterLog(self.DEBUG, args)
#         self.removeHandler()
#         return
# 
#     def c(self, *args):
#         self.logger.critical(args)
#         self.filterLog(self.CRITICAL, args)
#         self.removeHandler()
#         return
# 
# 
# 
#     def filterLog(self,mode, args):
#         preLevel = self.getCurLogLevel(mode)
#         if preLevel >= self.level:
#             ConsoleController.windowPrintInfo(self.loggername, mode, args)
#         else:
#             return
# 
#     def setLogLevel(self,level):
#         if level is self.DEBUG:
#             self.level = 0
#         elif level is self.INFO:
#             self.level = 1
#         elif level is self.WARNING:
#             self.level = 2
#         elif level is self.ERROR:
#             self.level = 3
#         elif level is self.CRITICAL:
#             self.level = 4
# 
#     def getCurLogLevel(self,level):
#         if level is self.DEBUG:
#             return 0
#         elif level is self.INFO:
#             return 1
#         elif level is self.WARNING:
#             return 2
#         elif level is self.ERROR:
#             return 3
#         elif level is self.CRITICAL:
#             return 4


# Path: XulDebugTool/utils/Utils.py
import json
import sqlite3
import xmltodict
from PyQt5.QtWebEngineWidgets import QWebEngineScript
from lxml import etree
from XulDebugTool.logcatapi.Logcat import STCLogger

    windowHeight = 1080
    itemHeight = 30

    @staticmethod
    def xml2json(xml, tag):
        # 将xml的某个tag转化成json
        doc = xmltodict.parse(xml)[tag]
        if doc != None:
            str = json.dumps(dict(doc))
            return json.loads(str)
        else:
            return ''

    @staticmethod
    def scriptCreator(path, name, page):
        script = QWebEngineScript()
        f = open(path, 'r')
        script.setSourceCode(f.read())
        script.setInjectionPoint(QWebEngineScript.DocumentReady)
        script.setName(name)
        script.setWorldId(QWebEngineScript.MainWorld)
        page.scripts().insert(script)

    @staticmethod
    def findNodeById(id, xml):
        root = etree.fromstring(xml)
        # print(etree.tostring(root, pretty_print=True).decode('utf-8'))
        try:
            list = root.xpath("//*[@id=%s]" % id)
        except Exception as e:

            STCLogger().e(e)