Ver Fonte

日志基类;
配置管理类

scbc.sat2 há 5 anos atrás
pai
commit
a053e2772b
2 ficheiros alterados com 244 adições e 0 exclusões
  1. 60 0
      ssat_sdk/MenuTree3/BaseLog.py
  2. 184 0
      ssat_sdk/MenuTree3/ConfigManager.py

+ 60 - 0
ssat_sdk/MenuTree3/BaseLog.py

@@ -0,0 +1,60 @@
+# -*- coding:utf-8 -*-
+
+"""
+注:私有变量和函数,前面加双下划线(不要在后面也加双下划线);
+"""
+
+import os
+import sys
+import time
+# 使用inspect模块动态获取当前运行的函数名
+import inspect
+# 日期头文件;
+from datetime import datetime
+
+
+
+'''
+CBaseLog:日志基类
+inspect.stack()[0][3]:获取当前函数的名称;
+inspect.stack()[1][3]:获取当前函数的上一层函数的名称;
+inspect.stack()[2][3]:获取当前函数的上上一层函数的名称;
+'''
+
+
+class CBaseLog:
+    def __init__(self):
+        pass
+
+    def __printlog(self, msg):
+        # 时间/内容;
+        print("%s %s") % (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msg)
+
+    def debug(self, msg):
+        # 类型/类名:函数/内容
+        log_str = "【DEBUG】<%s::%s> %s" % (self.__class__.__name__, inspect.stack()[1][3], msg)
+        self.__printlog(log_str)
+
+    def info(self, msg):
+        # 类型/类名:函数/内容
+        log_str = "【INFO】<%s::%s> %s" % (self.__class__.__name__, inspect.stack()[1][3], msg)
+        self.__printlog(log_str)
+
+    def warn(self, msg):
+        # 类型/类名:函数/内容
+        log_str = "【WARN】<%s::%s> %s" % (self.__class__.__name__, inspect.stack()[1][3], msg)
+        self.__printlog(log_str)
+
+    def error(self, msg):
+        # 类型/类名:函数/内容
+        log_str = "【ERROR】<%s::%s> %s" % (self.__class__.__name__, inspect.stack()[1][3], msg)
+        self.__printlog(log_str)
+
+    def log(self, msg):
+        # 类型/类名/内容
+        log_str = "【LOG】<%s::%s> %s" % (self.__class__.__name__, inspect.stack()[1][3], msg)
+        self.__printlog(log_str)
+        
+        
+if __name__ == "__main__":
+    pass

+ 184 - 0
ssat_sdk/MenuTree3/ConfigManager.py

@@ -0,0 +1,184 @@
+# -*- coding:utf-8 -*-
+import os
+from UIT_PathManage import UITPathManage
+from ssat_sdk.MenuTree3.BaseLog import CBaseLog
+from ssat_sdk.MenuTree3.TConfig import TConfig
+
+# 测试加头文件;
+from TData import CTData
+
+
+g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
+           'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth']
+
+
+class CConfigManager(TConfig, CBaseLog):
+    def __init__(self, menuTreeDir, pathManager):
+        self.pathManager = pathManager
+        if self.pathManager is None:
+            self.error("路径参数错误:None")
+        # 状态:False表示路径值失败;
+        self.status = False
+        # menuTree目录;
+        self.uiTreeDir = menuTreeDir
+        # 判断是否为目录;
+        if not os.path.isdir(self.uiTreeDir):
+            self.error("%s 不是menuTree目录" % self.uiTreeDir)
+        # 判断目录是否存在;
+        if not os.path.exists(self.uiTreeDir):
+            self.error("menuTree(%s)目录不存在" % self.uiTreeDir)
+        # 判断配置文件是否存在;
+        self.configPath = os.path.join(self.uiTreeDir, "menutree.ini")
+        if not os.path.exists(self.configPath):
+            self.error("menutree配置文件不存在:%s" % self.configPath)
+            self.status = True
+        # 初始化父类;
+        TConfig.__init__(self, self.configPath)
+
+    # 获取超级密码;
+    def getSuperPassword(self):
+        return self.get_value("Password", "super")
+
+    # 获取普通密码;
+    def getOrdinaryPassword(self):
+        return self.get_value("Password", "ordinary")
+
+    # 获取父节点等待进入子节点时间;
+    def getParentWaitTime(self, parent):
+        optionName = parent + "WaitTime"
+        try:
+            waitTime = float(self.get_value("waitTime", optionName))
+        except Exception, e:
+            waitTime = 1.0
+            self.error("获取%s界面的等待界面时间失败,使用默认值1.0s" % str(parent))
+        return waitTime
+
+    # 获取阀值字典;
+    def getThresholdDict(self, option):
+        section = "Threshold"
+        thresholdDict = {}
+        value = self.get_value(section, option)
+        self.info("value:%s,%s" % (value, type(value)))
+        if not value:
+            return thresholdDict
+        value_str = str(value)
+        self.info("value_str:%s,%s" % (value_str, type(value_str)))
+        value_dict = eval(value_str)
+        self.info("value_dict:%s,%s" % (value_dict, type(value_dict)))
+        return value_dict
+
+    # 获取Option的图片配置;
+    def __getICONConfig(self, optionName, is_value_sheet=False):
+        paths = self.pathManager.get_option_paths(optionName)
+        # 判断路径节点是否空;
+        if paths.__len__() == 0:
+            self.error("当前【%s】的路径节点空" % optionName)
+            return False, {"icon_path": "", "dcfg": {}, "dir_path": ""}
+
+        # 获取first parent;
+        first_parent = paths[g_level[0]]['parent']
+        # 获取当前option的level;
+        cur_level = g_level[paths.__len__() - 1]
+        # 当前option的父节点名称;
+        cur_parent = paths[cur_level]['parent']
+        if is_value_sheet is True:
+            cur_level = "value"
+
+        # option聚焦的首配图片路径;
+        icon_path = os.path.join(self.uiTreeDir, "icon\\", cur_parent + "." + cur_level + "_" + optionName + ".png")
+        # option聚焦的dir首配图片路径;
+        icon_dir_path = os.path.join(self.uiTreeDir, "icon\\" + cur_parent + "." + cur_level + "_" + optionName + ".dir.png")
+        # 图片聚焦时的定位参数;
+        opc_cfg = self.get_value_dict(cur_level, cur_parent + '.' + optionName)
+
+        last_path = icon_path
+        # 首配图片判断是否存在,不存在取用次配图片路径;
+        if not os.path.exists(icon_path):
+            # 使用次配图片,父级配图;
+            icon_path = os.path.join(self.uiTreeDir, "icon\\" + cur_parent + "." + cur_level + ".png")
+            icon_dir_path = os.path.join(self.uiTreeDir, "icon\\" + cur_parent + "." + cur_level + ".dir.png")
+            opc_cfg = self.get_value_dict(cur_level, cur_parent)
+            self.warn("Option(%s)首配图片不存在:%s,使用次配图:%s" % (optionName, icon_path))
+            # 如果次配都不存在,使用顶层配图;
+            if not os.path.exists(icon_path):
+                self.warn("Option(%s)次配图片不存在:%s" % (optionName, icon_path))
+                # 使用顶层配图(first parent)
+                icon_path = os.path.join(self.uiTreeDir, "icon\\" + first_parent + "." + cur_level + "_" + optionName +
+                                         ".png")
+                icon_dir_path = os.path.join(self.uiTreeDir, "icon\\" + first_parent + "." + cur_level + "_" + optionName +
+                                             ".dir.png")
+                opc_cfg = self.get_value_dict(cur_level, first_parent)
+
+                # 如果顶层配图不存在,退出;
+                if not os.path.exists(icon_path):
+                    self.error("%s对应的顶层菜单配图不存在%s" % (optionName, icon_path))
+                    return False, {"icon_path": "", "dcfg": {}, "dir_path": ""}
+                # endif
+            # endif
+        # endif
+
+        if opc_cfg.__len__() == 0:
+            opc_cfg = {"offset": 20, "minPeri": 0, "maxPeri": 0, "minArea": 0, "maxArea": 0, "morphology": []}
+
+        return True, {"icon_path": icon_path, "dcfg": opc_cfg, "dir_path": icon_dir_path}
+
+    # 获取Option的图片配置;
+    def getOptionICONConfig(self, optionName):
+        return self.__getICONConfig(optionName, False)
+
+    # 获取Value的图片配置;
+    def getValueICONConfig(self, valueName):
+        return self.__getICONConfig(valueName, True)
+
+    # 获取Option的OCR配置;
+    def getOptionOCRConfig(self, optionName):
+        ocr_dict = []
+        paths = self.pathManager.get_option_paths(optionName)
+        # 判断路径节点是否空;
+        if paths.__len__() == 0:
+            self.error("当前【%s】的路径节点空" % optionName)
+            ocr_dict = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
+                        {"lan": "ChinesePRC+English", "type": 10001}]
+        else:
+            # 如果状态False,退出;
+            if self.status is False:
+                self.warn("配置文件(%s)不存在,%s使用默认的ocr配置", self.configPath, optionName)
+                ocr_dict = [{"lan": "ChinesePRC+English", "type": 4}, {"lan": "ChinesePRC+English", "type": 253},
+                            {"lan": "ChinesePRC+English", "type": 10001}]
+            else:
+                # 读取指定的ocr配置信息;
+                for i in range(g_level.index(paths.__len__() - 1), -1, -1):
+                    cur_parent = paths['parent']
+                    first_parent = paths['first_parent']
+                    cur_level = g_level[i]
+                    # 是否有当前option的ocr配置;
+                    if self.has_option(cur_level, optionName + '.ocr'):
+                        self.warn("%s使用自身的ocr配置", optionName)
+                        ocr_dict = self.get_dict(self.get_value(cur_level, optionName + '.ocr'))
+                        break
+                    # 如果option本身没有配置,获取其父节点的配置;
+                    if self.has_option(cur_level, cur_parent + '.ocr'):
+                        self.warn("%s使用父节点%s的ocr配置", optionName, cur_parent)
+                        ocr_dict = self.get_dict(self.get_value(cur_level, cur_parent + '.ocr'))
+                        break
+                    # 如果option父级没有配置,则获取顶层配置(first parent);
+                    if self.has_option(cur_level, first_parent + '.ocr'):
+                        self.warn("%s使用顶层节点%s的ocr配置", optionName, first_parent)
+                        ocr_dict = self.get_dict(self.get_value(cur_level, first_parent + '.ocr'))
+                        break
+                # end-for
+            # end-if
+        # end-if
+        self.info("%s使用的ocr配置=%" % (optionName, ocr_dict))
+
+    # 获取Value的OCR配置;
+    def getValueOCRConfig(self, valueName, paths):
+        pass
+
+
+if __name__ == "__main__":
+    tData = CTData()
+    upath = UITPathManage(tData)
+    opc = CConfigManager(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
+    # print opc.getThresholdDict("factory")
+    print opc.getOptionICONConfig("picture")