def recreateJsFileAndBackUp(self, folderName_: str): # 目标文件 _targetJSPath = fileUtils.getPath(self._assetsFolderPath, folderName_) # 上层路径 _targetParentPath = fileUtils.getPath(self._assetsFolderPath, folderName_ + "/..") # 备份路径 _backUpPath = os.path.join(_targetParentPath, os.path.basename(_targetJSPath) + "_backUp") # 有备份 if os.path.exists(_backUpPath): # 没有源,有可能删了。【代码执行错误的时候,会删除源,因为,源会变】 if not os.path.exists(_targetJSPath): # 将备份 同步给 源 shutil.copytree(_backUpPath, _targetJSPath) print("备份文件,拷贝回源路径") # 源里没有 创建备份的标示。 if not os.path.isfile(_targetJSPath + '/backup_created'): # 删除 原有备份 folderUtils.removeTree(_backUpPath) # 新备份 shutil.copytree(_targetJSPath, _backUpPath) # 标记已经备份过了 fileUtils.writeFileWithStr(_targetJSPath + '/backup_created', 'backup end') else: print("已经创建过备份了") else: # 没备份文件 - 就备份一份 shutil.copytree(_targetJSPath, _backUpPath) # 标记已经备份过了 fileUtils.writeFileWithStr(_targetJSPath + '/backup_created', 'backup end')
def analyseFileInfo(self, srcFolderPath_: str, fileShortNameList_: list = []): _csCodeFolder = fileUtils.getPath(srcFolderPath_, "") _filePathList = folderUtils.getFileListInFolder(_csCodeFolder, [".cs"]) _finalfileDict = {} for _path in _filePathList: _fileShortName = _path.split(srcFolderPath_).pop() _isFilter = False for _filterFileShortName in fileShortNameList_: # 遍历过滤列表 if _fileShortName.find(_filterFileShortName) >= 0: # 存在过滤,就跳过 print("pass : "******"analyse : " + _fileShortName) _lines = fileUtils.linesFromFile(_path) # 类中的Class信息 _classDictList = self.getClassList(_lines, 0, len(_lines) - 1, True) _fileDict = {} _finalfileDict[_fileShortName] = _fileDict for _classDict in _classDictList: _fileDict[_classDict["className"]] = _classDict del _classDict["className"] return _finalfileDict
def deleteMata(self, folderName_: str): _jsCodeFolder = fileUtils.getPath(self._assetsFolderPath, folderName_) _filePathDict = folderUtils.getFilePathKeyValue( _jsCodeFolder, [".meta"]) # 移除掉无用的meta文件 for _keyName, _filePath in _filePathDict.items(): fileUtils.removeExistFile(_filePath)
def checkCulyBracesFolder(self, folderPath_: str): _csCodeFolder = fileUtils.getPath(folderPath_, "") _filePathList = folderUtils.getFileListInFolder(_csCodeFolder, [".cs"]) _shortFilePathList = [] for _path in _filePathList: if not self.checkCulyBracesFile(_path): _shortFilePathList.append(_path.split(folderPath_).pop()) return _shortFilePathList
def displayJsonStructure(self): _targetJsonPath = fileUtils.getPath( "/Volumes/18604037792/develop/ShunYuan/wxGame/assets/resources/Json/", "") _filePathDict = folderUtils.getFilePathKeyValue( _targetJsonPath, [".json"]) for _keyName, _filePath in _filePathDict.items(): print(_filePath)
def adjustClassFuncVariableLineFolder(self, srcFolderPath_: str, targetFolderPath_: str): _csCodeFolder = fileUtils.getPath(srcFolderPath_, "") _filePathList = folderUtils.getFileListInFolder(_csCodeFolder, [".cs"]) for _path in _filePathList: print(_path) _content = self.adjustClassFuncVariableLineFile(_path) _targetFilePath = targetFolderPath_ + _path.split(srcFolderPath_).pop() fileUtils.writeFileWithStr(_targetFilePath, _content)
def adjustIfElseFolder(self, srcFolderPath_: str, targetFolderPath_: str): _csCodeFolder = fileUtils.getPath(srcFolderPath_, "") _filePathList = folderUtils.getFileListInFolder(_csCodeFolder, [".cs"]) for _path in _filePathList: print(_path) _content = self.adjustIfElseFile(_path) # 拆分 单行 } else { _content = self.elseCombine(_content) # 合并多行 } else { _targetFilePath = targetFolderPath_ + _path.split(srcFolderPath_).pop() fileUtils.writeFileWithStr(_targetFilePath, _content)
def __init__(self, sm_): super().__init__(sm_) self.testJsonFilePath = fileUtils.getPath(self.resPath, "testJsonStr.json") self.conf: SparkConf = None self.sc: SparkContext = None self.spark: SparkSession = None self.sqlCtx: SQLContext = None # self.writeJsonToResPath() self.initSpark()
def getMetaByUUID(self, UUID: str): _targetAssetsFolder = fileUtils.getPath(self._assetsFolderPath, "") _filePathDict = folderUtils.getFilePathKeyValue( _targetAssetsFolder, [".meta"]) _find = False for _, _filePath in _filePathDict.items(): _fileMetaDict = fileUtils.dictFromJsonFile(_filePath) if _fileMetaDict["uuid"] == UUID: print(_filePath) _find = True if not _find: print("uuid {0} none.".format(UUID))
def create(self): super(CSharpUML, self).create() # 代码的位置 _csFolderPath = "/Volumes/18604037792/develop/TuYoo/GIT/MJ/majiang3d_super/Assets/AssetsFish/Plugins/MotionFramework/Scripts/" # 生成puml文件的位置 _pumlFolderPath = "/Volumes/18604037792/develop/TuYoo/GIT/Fish/PUML/" # 将 puml 转换成 UML 图的位置 _umlFolderPath = "/Volumes/18604037792/develop/TuYoo/GIT/Fish/UMLPIC/" # 工具路径,在自己对应的资源目录中 _plantUMLJar = fileUtils.getPath(self.resPath, "plantuml.jar") # CS -> 结构 -> UML analyseCSharpAndCreateUML(_csFolderPath, _pumlFolderPath, _umlFolderPath, _plantUMLJar)
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 analyseJsCode(self, folderName_: str): _jsCodeFolder = fileUtils.getPath(self._assetsFolderPath, folderName_) _filePathDict = folderUtils.getFilePathKeyValue(_jsCodeFolder, [".js"]) # 代码中使用function的次数 _funcLineCount = 0 # 正则表达式队列 for _, _filePath in _filePathDict.items(): # 做判断的,用来显示的路径 fileShowName = _filePath.split(folderName_)[1] if fileShowName in self._unAnalyseFileList: continue _funcLineCount += self.analyseSingle(_filePath, folderName_) print('共有 {0} 处function使用'.format(_funcLineCount))
def analyseNameSpaceInfo(self, srcFolderPath_: str): _csCodeFolder = fileUtils.getPath(srcFolderPath_, "") _filePathList = folderUtils.getFileListInFolder(_csCodeFolder, [".cs"]) _finalNameSpaceDict = {} for _path in _filePathList: print(_path) _nameSpaceDictList = self.getClassListWithNameSpace(_path) for _nameSpaceDict in _nameSpaceDictList: if _nameSpaceDict[ "namespace"] in _finalNameSpaceDict: # 当前命名空间存在 _targetNameSpaceDict = _finalNameSpaceDict[ _nameSpaceDict["namespace"]] else: # 当前命名空间不存在 _targetNameSpaceDict = {} _finalNameSpaceDict[ _nameSpaceDict["namespace"]] = _targetNameSpaceDict for _key in _nameSpaceDict.keys(): if not _key == "namespace": # 不是 namespace 的标示名 _targetNameSpaceDict[_key] = _nameSpaceDict[ _key] # 将类键值传递给命名空间总汇对象 return _finalNameSpaceDict
def test_jsonFileWrite(self): print(self.className + " - " + pyUtils.getCurrentRunningFunctionName() + "------------------") # 写入文件的路径 _writeToPath = fileUtils.getPath(self.app.resPath, "activityInfo.json") # 产生一个元组列表 (文件路径,文件内容) jsonRDD = self.sc.wholeTextFiles(self.testJsonFilePath) for _jsonKeyValue in jsonRDD.collect(): print("_jsonKeyValue = " + str(_jsonKeyValue)) # 元组列表的每一项,取其中的 文件内容,转换成 json字典对象,构成新的RDD # 字典对象RDD,过滤,将包含键的元素,构成新的RDD # 将元素中的字段取出,构成新的RDD jsonDataFilter = jsonRDD \ .map(lambda _jsonKeyValue: json.loads(_jsonKeyValue[1])) \ .filter(lambda _jsonDict: _jsonDict["activityInfo"]) \ .map(lambda _jsonDict: _jsonDict["activityInfo"]) # activityInfo 字段内容构成的RDD for _jsonDataFilter in jsonDataFilter.collect(): print("_jsonDataFilter = " + str(_jsonDataFilter)) # 如果,没有写过的话,就写一份 if not os.path.exists(_writeToPath): jsonDataFilter.saveAsTextFile(_writeToPath)
def displayJsStructure(self, folderName_: str): _jsCodeFolder = fileUtils.getPath(self._assetsFolderPath, folderName_) _filePathDict = folderUtils.getFilePathKeyValue(_jsCodeFolder, [".js"]) for _keyName, _filePath in _filePathDict.items(): print(_filePath)
def test_textFile(self): _testTextFilePath = fileUtils.getPath(self.app.resPath, "README.md") # Spark 的 RDD 包含两种操作 _testTextRDD = self.sc.textFile(_testTextFilePath) return _testTextRDD
def __init__(self, belongToService_): super().__init__(belongToService_) self.sqlFilePath = fileUtils.getPath(self.subResPath, self.className + ".sql")
def buildMiniClient_WeChat(self): # 工程路径 _projectFolderPath = sysUtils.folderPathFixEnd( "/Volumes/Files/develop/loho/mini-game/miniclient/") _assetsFolderPath = sysUtils.folderPathFixEnd(_projectFolderPath + "assets") _appConfigJsonPath = _projectFolderPath + "assets/resources/configs/AppConfig.json" # 打包配置路径 _miniClientJsonPath = fileUtils.getPath(self.resPath, "WeChatGameConfig.json") # 打包配置内容 _miniClientJsonDict = fileUtils.dictFromJsonFile(_miniClientJsonPath) # 获取构建之后的目录 _buildFolderPath = sysUtils.folderPathFixEnd( _miniClientJsonDict["buildPath"]) + "wechatgame" # 获取构建之后的res目录 _resFolderPath = sysUtils.folderPathFixEnd(_buildFolderPath) + "res/" print("请确保所有内容都已经 push 到远程,这样才能创建正确的 TAG") # 获取Git链接 _repo = gitUtils.getRepo(_projectFolderPath) # 获取当前满足版本格式的Tag中最大的tag号 _tagStrList = [ str(_tagName) for _tagName in _repo.tags if strUtils.isVersionStr(str(_tagName)) ] _tagStrList = sorted(_tagStrList, key=functools.cmp_to_key(strUtils.versionCompare), reverse=True) # 记录版本号 _biggestTar = _tagStrList[0] print("当前最大 TAG : " + _biggestTar) # 增加最后一位的版本号 _tagIntList = [int(_tarStr) for _tarStr in _biggestTar.split(".")] _tagIntList[-1] = _tagIntList[-1] + 1 _currentTar = ".".join([str(_tarInt) for _tarInt in _tagIntList]) # 填写到AppConfig.json中 print("修改本地的AppConfig版本号为 : " + _currentTar) print(" *请注意,只是修改本地。从本地提交到微信小程序测试工具中。不通过Git Remote 推送") self.changeAppConfigJson(_appConfigJsonPath, _currentTar) # 在 Git 上创建 tag print("创建新 TAG : " + _currentTar) _repo.create_tag(_currentTar) # 构建工程 _cmd = self.getBuildCmd(_projectFolderPath, _miniClientJsonPath) print("获取构建命令: \n" + _cmd) # 获取构建的LOG 并记录下来。 _cmdLogFile = "\n".join(os.popen(_cmd).readlines()) fileUtils.writeFileWithStr(_buildFolderPath + "buildLog.log", _cmdLogFile) # 修改game.json内的超时时间 self.changeGameJson(_buildFolderPath) print("正在获取FTP链接") # 获取要上传的ftp的host _ftpHost = "ftp网址" _ftpUserName = "******" _ftpPassWord = "******" _ftpSync = ftpUtils.getFTPSync(_ftpHost, _ftpUserName, _ftpPassWord, "路径/文件夹") print("ftp链接获取成功,正在上传请稍后") # 指定目录为 res ,那么res中的内容对应同步 ftpUtils.uploadFolder(_ftpSync, _resFolderPath) print("资源上传成功") return