def __checkDefine(self): """ 第一行的个元素是否符合定义格式"name[signs][func]"以及key是否符合规定 """ print( "检测文件头(第一行)是否正确" ) for index in self.__exportSheetIndex: self.sheetKeys = [] headList = self.xbook.getRowValues(self.xbook.getSheetByIndex(index), EXPORT_DEFINE_ROW -1 ) enName = [] #检查命名重复临时变量 reTuples = [] self.headerDict[index] = {} for c, head in enumerate(headList): if head is None or head.strip() == '': #导出表的第一行None, 则这一列将被忽略 self.__onCheckSheetHeader(self.headerDict[index], c, None) continue reTuple = self.__reCheck(head) if len(reTuple) == 3: #定义被分拆为三部分:name, signs, func,signs可以是空 name, signs, funcName = reTuple[0], reTuple[1][1:-1], reTuple[2][1:-1] funcName = funcName +"Func" #修正函数名称 name = self.__convertKeyName(name) for s in signs: #符号定义是否在规则之内 if s not in EXPORT_ALL_SIGNS: self.xlsxClear(EXPORT_ERROR_NOSIGN, (EXPORT_DEFINE_ROW, c+1)) if EXPORT_SIGN_GTH in signs: #是否为key self.sheetKeys.append(c) if len(self.sheetKeys) > EXPORT_KEY_NUMS: #key是否超过规定的个数 self.xlsxClear(EXPORT_ERROR_NUMKEY, (EXPORT_DEFINE_ROW, c+1)) if name not in enName: #name不能重复 enName.append(name) else: self.xlsxClear(EXPORT_ERROR_REPEAT, \ (self.xbook.getSheetNameByIndex(index).encode(FILE_CODE), EXPORT_DEFINE_ROW, c+1)) if not hasFunc(funcName): #funcName是否存在 self.xlsxClear(EXPORT_ERROR_NOFUNC, (xlsxtool.toGBK(funcName), c+1)) else: self.xlsxClear(EXPORT_ERROR_HEADER, (self.xbook.getSheetNameByIndex(index).encode(FILE_CODE), EXPORT_DEFINE_ROW, c+1)) bExportClient = EXPORT_SIGN_CLIENT in signs bExportServer = EXPORT_SIGN_SERVER in signs if EXPORT_PLARFORM == EXPORT_PLARFORM_CLIENT and bExportClient : #定义了'c' self.__onCheckSheetHeader(self.headerDict[index], c, (name, signs, funcName)) elif EXPORT_PLARFORM == EXPORT_PLARFORM_SERVER and bExportServer : #定义了's' self.__onCheckSheetHeader(self.headerDict[index], c, (name, signs, funcName)) elif not bExportClient and not bExportServer : #未定义'cs' self.__onCheckSheetHeader(self.headerDict[index], c, (name, signs, funcName)) else : #忽略此列 self.__onCheckSheetHeader(self.headerDict[index], c, None) self.__onCheckDefine() return
def __checkDefine(self): """ 第一行的个元素是否符合定义格式"name[signs][func]"以及key是否符合规定 """ for sheetName in self.__exportSheetName: print("检测表[%s]文件头(第一行)是否正确" % sheetName) self.sheetKeys = [] headList = self.xbook.getRowValues( self.xbook.getSheetBySheetName(sheetName), config.EXPORT_DEFINE_ROW - 1) enName = [] # 检查命名重复临时变量 self.headerDict[sheetName] = {} for c, head in enumerate(headList): if head is None or head.strip() == '': # 导出表的第一行None, 则这一列将被忽略 self.headerDict[sheetName][c] = None continue reTuple = self.__reCheck(head) if len(reTuple) == 3: # 定义被分拆为三部分:name, signs, func, signs可以是空 name, signs, funcName = reTuple[0], reTuple[1][ 1:-1], reTuple[2][1:-1] for s in signs: # 符号定义是否在规则之内 if s not in config.EXPORT_ALL_SIGNS: self.xlsxClear(config.EXPORT_ERROR_NOSIGN, (config.EXPORT_DEFINE_ROW, c + 1)) if config.EXPORT_SIGN_GTH in signs: # 是否为key self.sheetKeys.append(c) if len(self.sheetKeys ) > config.EXPORT_KEY_NUMS: # key是否超过规定的个数 self.xlsxClear(config.EXPORT_ERROR_NUMKEY, (config.EXPORT_DEFINE_ROW, c + 1)) if name not in enName: # name不能重复 enName.append(name) else: self.xlsxClear(config.EXPORT_ERROR_REPEAT, (sheetName.encode(config.FILE_CODE), config.EXPORT_DEFINE_ROW, c + 1)) if not hasFunc(funcName): # funcName是否存在 self.xlsxClear(config.EXPORT_ERROR_NOFUNC, (xlsxtool.toGBK(funcName), c + 1)) else: self.xlsxClear(config.EXPORT_ERROR_HEADER, (sheetName.encode(config.FILE_CODE), config.EXPORT_DEFINE_ROW, c + 1)) self.headerDict[sheetName][c] = (name, signs, funcName) self.__onCheckDefine()
def __checkDefine(self): """ 第一行的个元素是否符合定义格式"name[signs][func]"以及key是否符合规定 """ print( "检测文件头(第一行)是否正确" ) for index in self.__exportSheetIndex: self.sheetKeys = [] headList = self.xbook.getRowValues(self.xbook.getSheetByIndex(index), EXPORT_DEFINE_ROW -1 ) enName = [] #检查命名重复临时变量 reTuples = [] self.headerDict[index] = {} for c, head in enumerate(headList): if head is None or head.strip() == '': #导出表的第一行None, 则这一列将被忽略 self.__onCheckSheetHeader(self.headerDict[index], c, None) continue reTuple = self.__reCheck(head) if len(reTuple) == 3: #定义被分拆为三部分:name, signs, func,signs可以是空 name, signs, funcName = reTuple[0], reTuple[1][1:-1], reTuple[2][1:-1] name = self.__convertKeyName(name) for s in signs: #符号定义是否在规则之内 if s not in EXPORT_ALL_SIGNS: self.xlsxClear(EXPORT_ERROR_NOSIGN, (EXPORT_DEFINE_ROW, c+1)) if EXPORT_SIGN_GTH in signs: #是否为key self.sheetKeys.append(c) if len(self.sheetKeys) > EXPORT_KEY_NUMS: #key是否超过规定的个数 self.xlsxClear(EXPORT_ERROR_NUMKEY, (EXPORT_DEFINE_ROW, c+1)) if name not in enName: #name不能重复 enName.append(name) else: self.xlsxClear(EXPORT_ERROR_REPEAT, \ (self.xbook.getSheetNameByIndex(index).encode(FILE_CODE), EXPORT_DEFINE_ROW, c+1)) if not hasFunc(funcName): #funcName是否存在 self.xlsxClear(EXPORT_ERROR_NOFUNC, (xlsxtool.toGBK(funcName), c+1)) else: self.xlsxClear(EXPORT_ERROR_HEADER, (self.xbook.getSheetNameByIndex(index).encode(FILE_CODE), EXPORT_DEFINE_ROW, c+1)) self.__onCheckSheetHeader(self.headerDict[index], c, (name, signs, funcName)) #定义一行经常使用存起来了 self.__onCheckDefine() return