def Hotfix_Update(self): self.__hot_common() hdataList = getHotfixList() if hdataList is None: return bNeedHot = False for k, v in self.parentClass.items(): hdata = hdataList.get(k, None) if hdata is not None and hdata['var'] > v['var']: if hdata['local_import'] == False: try: v['module'] = importlib.reload(v['module']) hdata['local_import'] = True v['var'] = hdata['var'] bNeedHot = True except ImportError as e: KBEDebug.ERROR_MSG( "%s Hotfix.update parentClass ImportError:%s" % (self.__module__, e)) continue else: v['var'] = hdata['var'] bNeedHot = True # do something 可以优化 只 reload 一次 if bNeedHot == True: self.selfClass = importlib.reload(self.selfClass) hdata = hdataList.get(self.__module__, None) if hdata is not None and hdata['var'] > self.var: if hdata['local_import'] == False: try: self.selfClass = importlib.reload(self.selfClass) hdata['local_import'] = True self.var = hdata['var'] bNeedHot = True except ImportError as e: KBEDebug.ERROR_MSG( "%s Hotfix.update selfClass ImportError:%s" % (self.__module__, e)) else: self.var = hdata['var'] bNeedHot = True if bNeedHot: self.__hot()
def B_Hotfix_Hotfile(self, componentType, hotFilenameList): '''热更新文件 参数: 组件类型 1 = baseapp 2 = cellapp 3 = common 参数: 要热更的文件列表 Ps. 以下目录会自动映射成根目录 server_common common base base\interfaces cell cell\interfaces data 调用示例: .B_Hotfix_Hotfile(1, ['Account']) 更新 BaseApp Account.py 文件 .B_Hotfix_Hotfile(1, ['parent.C1']) 更新 BaseApp parent.C1.py 文件 .B_Hotfix_Hotfile(2, ['Account']) 更新 CellApp Account.py 文件 .B_Hotfix_Hotfile(3, ['CustomClass']) 更新 BaseApp与CellApp 的 CustomClass.py 文件 ''' component = None if componentType == 1: component = 'baseapp' elif componentType == 2: component = 'cellapp' elif componentType == 3: component = 'common' else: KBEDebug.ERROR_MSG( "Hotfix_Ent.B_Hotfix_Hotfile. component(%i) illegal" % (component)) return nowtime = int(time.time()) oldHData = Hotfix.getHotfixList(component) if oldHData is None: oldHData = {} for filename in hotFilenameList: classData = oldHData.get(filename, None) newClassData = None if classData is None: newClassData = { 'var': 1, 'local_import': False, 'hotime': nowtime } else: newClassData = { 'var': classData['var'] + 1, 'local_import': False, 'hotime': nowtime } oldHData[filename] = newClassData Hotfix.setHotfixList(component, oldHData) KBEDebug.INFO_MSG("Hotfix_Ent.B_Hotfix_Hotfile. broadcast done")
def __deco(*args, **kwargs): b = getCurrentTime() result = func(*args, **kwargs) KBEDebug.ERROR_MSG( str(func) + " run time is " + str(getCurrentTime() - b)) return result
def getUpdateSql(tableName, setValueMap, filterValueMap, hasIndex=True): if setValueMap is None: KBEDebug.ERROR_MSG("you setValueMap is None!") return indexStr = "" if hasIndex: indexStr = "sm_" setStr = "" whereStr = "" for k, v in setValueMap.items(): setStr += "sm_" + k + "='" + str(v) + "'," for k, v in filterValueMap.items(): whereStr += "sm_" + k + "='" + str(v) + "' and " setStr = setStr[:-1] if whereStr != "": whereStr = whereStr[:-4] sql = "update " + tableName + " set " + setStr + ' where ' + whereStr print("now run update sql " + sql) return sql
def __deco(result, rowNum, error): if error is not None: KBEDebug.ERROR_MSG(str(func) + " error is " + error) # 调用原方法,不打断流程 func(result, rowNum, error)