def analysePrefabJS(self, jsPath_: str): _content = fileUtils.readFromFile(jsPath_) _propertiesReg = re.search(r'properties\s*:\s*{', _content) if _propertiesReg: _jsFileShortName = jsPath_.split(self._jsFolder)[1] if not (_jsFileShortName in self._jsComponentFileShortNameList): self._jsComponentFileShortNameList.append(_jsFileShortName)
def replaceUuidInPrefabs(self, sourceUuid_, targetUuid_): for _i in range(len(self.prefabFiles)): _prefabFilePath = self.prefabFiles[_i] print('_prefabFilePath = ' + str(_prefabFilePath)) if fileUtils.fileHasString(_prefabFilePath, sourceUuid_): _prefabContent = fileUtils.readFromFile( _prefabFilePath).replace(sourceUuid_, targetUuid_) fileUtils.writeFileWithStr(_prefabFilePath, _prefabContent)
def analyseFolder(self, folderName_: str): _swiftCodeFolder = fileUtils.getPath(self.resPath, folderName_) _filePathDict = folderUtils.getFilePathKeyValue( _swiftCodeFolder, [".swift"]) for _k, _v in _filePathDict.items(): _keyName = _k print(str(_keyName).ljust(40) + ":" + str(_v)) # 名称 -> 路径 关系输出 if _keyName == "2 - MyGameCoordinator.swift": _codeWithComment = fileUtils.readFromFile(_v) _codeWithOutComment = codeUtils.removeComment( "swift", _codeWithComment) for _idx, _line in list( enumerate(_codeWithOutComment.split("\n"))): print(str(_idx).ljust(3) + ":" + str(_line))
def adjustClassFuncVariableLineFile(self, path_: str): _content = fileUtils.readFromFile(path_) _content = self.adjustCurlyBracesBlank(_content) _content = self.adjustReturnInOneLine(_content) _content = self.adjustClassFuncInOneLine(_content) _content = self.adjustClassLineFile(_content) _content = self.adjustFuncLineFile(_content) _content = self.adjustAnonymous(_content) # 匿名函数 _content = self.adjustDelegateWrite(_content) # delegate的写法调整 _content = self.adjustCommaSymbol(_content) # 逗号写法调整 # return 两面的多空格全部变成一个 _content = re.sub(r' +return +', ' return ', _content) # self.checkContent(_content) return _content
def analyseMoudleExportsJS(self, jsPath_: str): _content = fileUtils.readFromFile(jsPath_) _moudleNameReg = re.search( r'module\.exports\s*=\s*([0-9a-z-A-Z_]+)\s*', _content) if _moudleNameReg: _jsFileShortName = jsPath_.split(self._jsFolder)[1] if not (_jsFileShortName in self._jsModuleExportsFileShortNameList): self._jsModuleExportsFileShortNameList.append(_jsFileShortName) _moudleNameReg = re.search(r'module\.exports\s*=\s*{', _content) if _moudleNameReg: _jsFileShortName = jsPath_.split(self._jsFolder)[1] if not (_jsFileShortName in self._jsModuleExportsFileShortNameList): self._jsModuleExportsFileShortNameList.append(_jsFileShortName)
def getAllRelationTableInfo(self): print(self.className + " - " + pyUtils.getCurrentRunningFunctionName() + "------------------") # 读取sql内容 _sqlStr = fileUtils.readFromFile(self.sqlFilePath) # print('_sqlStr = ' + str(_sqlStr)) # _sqlWithOutComment = codeUtils.removeComment("sql", _sqlStr) # print('_sqlWithOutComment = ' + str(_sqlWithOutComment)) # # 去掉注释切分Sql输出查看每一个SQL # _sqlList = _sqlWithOutComment.split(";") # for _i in range(len(_sqlList)): # print('_sqlList[_i] = \n' + str(_sqlList[_i])) # 获取表和表中索取字段 _whatFromWhereInfo = self.belongToService.getSelectWhatFromWhere( _sqlStr) # 获取要执行的Sql列表 _sqlList = self.belongToService.whatFromWhereToQuerySqlList( _whatFromWhereInfo) # 腾讯 链接信息 _txPrestoInfo = dict({ 'host': 'ip', 'port': 'port', 'catalog': 'hive', 'serverName': 'TengXun', 'schema': 'olap' }) # 执行的sql列表输出,链接 presto 来执行这些 Sql 语句 for _i in range(len(_sqlList)): _querySql = _sqlList[_i] _result, _errList = dataUtils_presto.executePrestoSQL( _txPrestoInfo, _querySql) if _errList: print(_querySql) self.raiseError(pyUtils.getCurrentRunningFunctionName(), str(_errList)) else: if len(_result) == 0: print(_querySql) self.raiseError(pyUtils.getCurrentRunningFunctionName(), 'WARNING : no data')
def getMatchList(filePath_: str, regStr_: str, printBoo_: bool = False): _contentStr = fileUtils.readFromFile(filePath_) _matches = re.finditer(regStr_, _contentStr, re.MULTILINE) _matchList = [] for _matchNum, _match in enumerate(_matches, start=1): if printBoo_: print( "Match {matchNum} was found at {start}-{end}: {match}".format( matchNum=_matchNum, start=_match.start(), end=_match.end(), match=_match.group())) for _groupNum in range(0, len(_match.groups())): _groupNum = _groupNum + 1 if printBoo_: print( "Group {groupNum} found at {start}-{end}: {group}".format( groupNum=_groupNum, start=_match.start(_groupNum), end=_match.end(_groupNum), group=_match.group(_groupNum))) _matchList.append(_match) return _matchList
def anaylseShortJsNameAndRequireRelation(self): _filePathDict = folderUtils.getFilePathKeyValue( self._jsFolder, [".js"]) for _, _filePath in _filePathDict.items(): _jsFileShortName = _filePath.split(self._jsFolder)[1] self._requireDict[_jsFileShortName] = [] if not (_jsFileShortName in self._jsAllShortNameList): self._jsAllShortNameList.append(_jsFileShortName) # 内容中识别 require _content = fileUtils.readFromFile(_filePath) regex = r"var\s*([0-9a-z-A-Z_\.]+)\s*=\s*require\(\s*\"([0-9a-z-A-Z_\.]+)\"\s*\)" matches = re.finditer(regex, _content, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): _localName = match.group(1) # 代码中的名称 _fileName = match.group(2) # 引用名称 _lines = _content.split("\n") _isFind = False for _line in _lines: # 注释的前半截 _line = _line.split("//")[0] # 在不是require的行中搜索 if not re.search( r'require\(\s*\"([0-9a-z-A-Z_\.]+)\"\s*\)', _line) and _line.find("module.exports") < 0: if (re.search( r'[\s\(\[=\!\+\-\*/\']' + _localName + '[\,\.\s=\)\]\+\-\*/\'\[]', _line)): _isFind = True break if _isFind: self._requireDict[_jsFileShortName].append(_fileName) else: print(_filePath) print(_fileName) self.raiseError(pyUtils.getCurrentRunningFunctionName(), "文件引用了类,但是没有使用过")
def adjustDelegateFile(self, filePath_: str): _content = fileUtils.readFromFile(filePath_) self.funcThreePartSeparate(_content) return _content
def adjuseAnonymousFile(self, filePath_: str): _content = fileUtils.readFromFile(filePath_) _content = self.adjuseAnonymousWrite(_content) return _content
def getProtobufStructInfo(self, keyName_: str, protoFilePath_: str): # 创建proto信息的字典对象 _currentProto = dict() _currentProto["tableList"] = [] _currentProto["fileName"] = keyName_ _currentTableDict = None _lastLine = None # _maxPropertyNameLen: int = 0 # 整理样式 _content = fileUtils.readFromFile(protoFilePath_) _content = self.formatProtoStr(_content) _content = self.removeUnuseStr(_content) _content = self.removePropertyCommentSpace(_content) # print(protoFilePath_) _content = self.reStructProtoStr(_content) # 读取每一行内容 _protoLines = _content.split("\n") # 循环proto的每一行 for _lineIdx in range(len(_protoLines)): # 两面空格都去掉 _line = str(_protoLines[_lineIdx]).strip() # 新table _tableReg = re.search(r'message\s*([1-9a-zA-Z_\.]+)\s*(//\s*(.*)|)', _line) if _tableReg: _currentTableDict = {} _currentTableDict["type"] = "table" _currentTableDict["propertyList"] = [] # 属性列表 _currentTableDict["fileName"] = keyName_ # 所属文件 _currentProto["tableList"].append(_currentTableDict) _currentTableDict["protoName"] = _tableReg.group(1) # print(" protoName = " + str(_currentTableDict["protoName"])) # _currentTableDict["tableName"] = _tableReg.group(1) # _currentTableDict["lowerTableName"] = _currentTableDict["tableName"].lower() if _tableReg.group(2): _currentTableDict["common"] = _tableReg.group(2).split("//")[1].strip() else: _currentTableDict["common"] = "" if _lastLine: _commonReg = re.search(r'\s*//\s*(.*)', _lastLine) if _commonReg: _currentTableDict["common"] = _commonReg.group(1) else: # table中属性 _propertyReg = re.search( r'\s*(required|optional|repeated)\s*([0-9a-z-A-Z_\.]+)\s*([0-9a-z-A-Z_]+)\s*=\s*(\d+)\s*;\s*(//\s*.*|)', _line) if _propertyReg: _currentProperty = {} _currentProperty["propertyName"] = _propertyReg.group(3) # if len(_currentProperty["propertyName"]) > _maxPropertyNameLen: # _maxPropertyNameLen = len(_currentProperty["propertyName"]) # print(" PropertyName = " + str(_currentProperty["propertyName"])) _currentProperty["needType"] = _propertyReg.group(1) _currentProperty["dataType"] = _propertyReg.group(2) # # 暂时忽略bytes类型 # if _currentProperty["dataType"] != "bytes": # if self.belongToService.isNormalProperty(_currentProperty["dataType"]): # _currentProperty["dataTypeExchange"] = _currentProperty["dataType"] # # int64/int32 的 result 统一变成String # if _currentProperty["propertyName"] == "result": # if _currentProperty["dataTypeExchange"] == "bigint": # _currentProperty["dataTypeExchange"] = "string" # else: # _currentProperty["dataType"] = _propertyReg.group(2) _currentProperty["index"] = _propertyReg.group(4) _currentProperty["common"] = "" if _propertyReg.group(5): _currentProperty["common"] = _propertyReg.group(5).split("//")[1].strip() _currentTableDict["propertyList"].append(_currentProperty) else: _enumReg = re.search(r'enum\s*([1-9a-zA-Z_\.]+)\s*(//\s*(.*)|)', _line) if _enumReg: _currentEnumDict = {} _currentEnumDict["type"] = "enum" _currentEnumDict["propertyList"] = [] # 属性列表 _currentEnumDict["fileName"] = keyName_ # 所属文件 _currentProto["tableList"].append(_currentEnumDict) _currentEnumDict["protoName"] = _enumReg.group(1) # print(" enumName = " + str(_currentEnumDict["protoName"])) # _currentEnumDict["tableName"] = _enumReg.group(1) # _currentEnumDict["lowerTableName"] = _currentEnumDict["tableName"].lower() else: _enumTypeReg = re.search(r'\t*([0-9a-z-A-Z_\.]+)\s*=\s*([0-9]+)\s*;\s*(//\s*(.*)|)', _line) if _enumTypeReg: _currentProperty = {} _currentProperty["propertyName"] = _enumTypeReg.group(1) _currentProperty["index"] = _enumTypeReg.group(2) _currentProperty["common"] = "" if _enumTypeReg.group(3): _currentProperty["common"] = _enumTypeReg.group(3).split("//")[1].strip() _currentEnumDict["propertyList"].append(_currentProperty) _lastLine = _line # print("_maxPropertyNameLen : " + str(_maxPropertyNameLen)) return _currentProto