Beispiel #1
0
 def MargeJsonFile(self, dParameters_: dict):
     _toJsonFilePath = dParameters_["toJsonFilePath"]
     _fromJsonFilePath = dParameters_["fromJsonFilePath"]
     _jsonDict = fileUtils.dictFromJsonFile(_toJsonFilePath)
     _margeJsonDict = fileUtils.dictFromJsonFile(_fromJsonFilePath)
     _jsonDict = jsonUtils.mergeAToB(_margeJsonDict, _jsonDict)  # 合并
     fileUtils.writeFileWithStr(  # 写回去
         _toJsonFilePath,
         str(json.dumps(_jsonDict, indent=4, sort_keys=False, ensure_ascii=False))
     )
Beispiel #2
0
    def DiffJsonFile(self, dParameters_: dict):
        _oldJsonFilePath = dParameters_["oldJsonFilePath"]
        _newJsonFilePath = dParameters_["newJsonFilePath"]
        _diffJsonFilePath = dParameters_["diffJsonFilePath"]
        _oldDict = fileUtils.dictFromJsonFile(_oldJsonFilePath)
        _newDict = fileUtils.dictFromJsonFile(_newJsonFilePath)

        _dataSetCache = {}
        _oldChangeList = dataSetUtils.setValueToDataPath("old", _oldDict, _dataSetCache)
        _newChangeList = dataSetUtils.setValueToDataPath("new", _newDict, _dataSetCache)

        # 去掉路径中的 old. 和 new.,使得后面保持一致
        for _i in range(len(_oldChangeList)):
            _oldChangeList[_i] = _oldChangeList[_i][4:]
        for _i in range(len(_newChangeList)):
            _newChangeList[_i] = _newChangeList[_i][4:]

        # 并集 - 交集 得到不同路径
        _justInNewSet = set(set(_newChangeList) - set(_oldChangeList))
        _justInNewList = list(_justInNewSet)
        for _i in range(len(_justInNewList)):
            _justInNewPath = _justInNewList[_i]
            dataSetUtils.setValueToDataPath(
                "diff." + _justInNewPath,  # 放置到不同路径中
                dataSetUtils.getValueByDataPath("new." + _justInNewPath, _dataSetCache),  # 新数据中的内容
                _dataSetCache
            )

        # 交集部分中不同的
        _intersectionList = list(set(set(_newChangeList) & set(_oldChangeList)))
        for _i in range(len(_intersectionList)):
            _intersectionElement = _intersectionList[_i]
            _oldValue = dataSetUtils.getValueByDataPath("old." + _intersectionElement, _dataSetCache)
            _newValue = dataSetUtils.getValueByDataPath("new." + _intersectionElement, _dataSetCache)
            # 比较值
            if not _oldValue == _newValue:
                dataSetUtils.setValueToDataPath(
                    "diff." + _intersectionElement,  # 放置到不同路径中
                    _newValue,
                    _dataSetCache
                )

        fileUtils.writeFileWithStr(  # 写回去
            _diffJsonFilePath,
            str(
                json.dumps(
                    dataSetUtils.dataSetToJsonDict("diff", _dataSetCache),
                    indent=4, sort_keys=False, ensure_ascii=False
                )
            )
        )
Beispiel #3
0
    def analysePrefabComponentRelationShip(self):
        _prefabPathDict = folderUtils.getFilePathKeyValue(self._prefabFolder, [".prefab"])
        for _, _prefabPath in _prefabPathDict.items():
            _prefabFileName = fileUtils.justName(_prefabPath)
            # prefab 文件 对应 Component 的 列表
            self.prefabComponentDict[_prefabFileName] = []
            # prefab 的 列表
            _prefabList = fileUtils.dictFromJsonFile(_prefabPath)
            # prefab 内容
            for _i in range(len(_prefabList)):
                # prefab 的 每一个 元素
                _elementDict = _prefabList[_i]
                # 每一个 元素 的 类型
                _elementType = _elementDict['__type__']
                # 组件 和 加密字符串 的 对应字典。
                if _elementType in self.componentEncryptClassDict.keys():
                    _componentJSName = self.componentEncryptClassDict[_elementType]  # 转换成 js 脚本名
                    self.prefabComponentDict[_prefabFileName].append(_componentJSName)  # 获取 Prefab 上的 js Component 脚本

        _keyList = []
        for _key, _list in self.prefabComponentDict.items():
            if len(_list) == 0:
                _keyList.append(_key)

        for _key in _keyList:
            del self.prefabComponentDict[_key]

        for _key, _list in self.prefabComponentDict.items():
            if _key != _list[0]:
                self.raiseError(pyUtils.getCurrentRunningFunctionName(),
                                " 界面名 和 component 名称 不一致 " + _key + " : " + _list[0])
Beispiel #4
0
 def changeGameJson(self, buildFolderPath_: str):
     # game.json 的内容
     # {
     #     "deviceOrientation": "portrait",
     #     "networkTimeout": {
     #         "request": 5000,
     #         "connectSocket": 5000,
     #         "uploadFile": 5000,
     #         "downloadFile": 5000
     #     },
     #     "subpackages": []
     # }
     # 修改构建之后的 game.json 的内容
     # print('buildFolderPath_ = ' + str(buildFolderPath_))
     _gameJsonPath = sysUtils.folderPathFixEnd(
         buildFolderPath_) + "game.json"
     # print('_gameJsonPath = ' + str(_gameJsonPath))
     _gameJsonDict = fileUtils.dictFromJsonFile(_gameJsonPath)
     _gameJsonDict["networkTimeout"]["request"] = 60000
     _gameJsonDict["networkTimeout"]["connectSocket"] = 60000
     _gameJsonDict["networkTimeout"]["uploadFile"] = 60000
     _gameJsonDict["networkTimeout"]["downloadFile"] = 60000
     _jsonStr = str(
         json.dumps(_gameJsonDict,
                    indent=4,
                    sort_keys=False,
                    ensure_ascii=False))
     fileUtils.writeFileWithStr(_gameJsonPath, _jsonStr)
Beispiel #5
0
 def changeAppConfigJson(self, appConfigPath_: str, currentVer_: str):
     _appConfigDict = fileUtils.dictFromJsonFile(appConfigPath_)
     _appConfigDict["version"] = currentVer_
     _jsonStr = str(
         json.dumps(_appConfigDict,
                    indent=4,
                    sort_keys=False,
                    ensure_ascii=False))
     fileUtils.writeFileWithStr(appConfigPath_, _jsonStr)
Beispiel #6
0
 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))
Beispiel #7
0
    def analysePrefabBtn(self, prefabPath_: str):
        _prefabList = fileUtils.dictFromJsonFile(prefabPath_)
        print(prefabPath_.split(self._prefabFolder).pop() + " :")
        for _i in range(len(_prefabList)):
            # prefab 的 每一个 元素
            _elementDict = _prefabList[_i]
            _type = _elementDict["__type__"]
            # 节点是万物起源
            if _type == "cc.Node":
                _nodeName = _elementDict["_name"]
                _components = _elementDict["_components"]
                for _component in _components:
                    _componentId = _component["__id__"]
                    _componentDict = _prefabList[_componentId]
                    _componentType = _componentDict["__type__"]
                    # 包含按钮组件
                    if _componentType == "cc.Button":
                        _clickEvents = _componentDict["clickEvents"]
                        if len(_clickEvents) > 1 or len(_clickEvents) == 0:
                            print("    " + _nodeName + " 按钮组件 事件 触发 长度 为 " + str(len(_clickEvents)))
                        else:
                            if _clickEvents[0] is None:
                                print("    " + _nodeName + " 事件 是 空对象")
                            else:
                                print("    " + _nodeName + " 按钮组件 属性")
                                _clickEventId = _clickEvents[0]["__id__"]
                                _clickEvent = _prefabList[_clickEventId]
                                _clickEventComponentId = str(_clickEvent["_componentId"])
                                _componentName = ""
                                if _clickEventComponentId == "":
                                    _componentName = _clickEvent["component"]
                                else:
                                    if _clickEventComponentId in self.componentEncryptClassDict:
                                        _componentName = self.componentEncryptClassDict[
                                            _clickEventComponentId]
                                # if _componentName == "":
                                #     self.raiseError(pyUtils.getCurrentRunningFunctionName(), " 无组件名")
                                print("        " + '_componentName = ' + _componentName)

                                _customEventData = str(_clickEvent["customEventData"])
                                if not _customEventData == "":
                                    print("        " + 'customEventData = ' + _customEventData)

                                _hander = str(_clickEvent["handler"])
                                if not _hander == "":
                                    print("        " + '_hander = ' + _hander)

                                _clickEventTrargetId = str(_clickEvent["target"]["__id__"])
                                if not _clickEventTrargetId == "1":
                                    print("        " + 'target.__id__ = ' + _clickEventTrargetId)
Beispiel #8
0
 def getPicSubMetaInfos(self, fileMetas_: list):
     _metaInfos = []
     for _fileMeta in fileMetas_:
         _metaInfo = {}
         _fileMetaDict = fileUtils.dictFromJsonFile(_fileMeta)
         _metaInfo["filePath"] = _fileMeta.split(".meta")[0]
         _metaInfo["subUuids"] = []
         # 获取 文件中 subMetas ,这个就是当前图片中包含的单图信息[因为有些图是pack之后的大图]
         _subMeta = _fileMetaDict["subMetas"]
         for _key in _subMeta:
             # 循环 subMetas 得到其中包含的所有小图的uuid
             _metaInfo["subUuids"].append(_subMeta[_key]["uuid"])
         _metaInfos.append(_metaInfo)
     return _metaInfos
Beispiel #9
0
 def analysePrefab(self, prefabPath_: str):
     _prefabList = fileUtils.dictFromJsonFile(prefabPath_)
     if isinstance(_prefabList, list):
         for _i in range(len(_prefabList)):
             _elementDict = _prefabList[_i]
             _elementType = _elementDict['__type__']
             if not (_elementType in self.typeList):
                 self.typeList.append(_elementType)
                 # 是有类名的Component
                 if "className" in _elementDict:
                     _className = _elementDict["className"]
                     if not (_className in self.componentClassEncryptDict):
                         self.componentClassEncryptDict[_className] = _elementType
                         self.componentEncryptClassDict[_elementType] = _className
     else:
         self.raiseError(pyUtils.getCurrentRunningFunctionName(), " 不是数组 : " + prefabPath_)
Beispiel #10
0
 def analysePrefabStructure(self, prefabPath_: str, pathList_: list):
     _prefabList = fileUtils.dictFromJsonFile(prefabPath_)
     for _i in range(len(_prefabList)):
         # prefab 的 每一个 元素
         _elementDict = _prefabList[_i]
         _type = _elementDict["__type__"]
         if _type.find("cc.") == 0:
             _type = "cc_" + _type.split(".").pop()
         else:
             if _type in self.componentEncryptClassDict:
                 _type = self.componentEncryptClassDict[_type]
         _changeList = self.sm.dc.sv(_type, _elementDict)
         # 过滤掉相同的变更路径
         for _changeIdx in range(len(_changeList)):
             _changePath = str(_changeList[_changeIdx])
             if not _changePath in pathList_:
                 pathList_.append(_changePath)
Beispiel #11
0
    def Filter(self, dParameters_: dict):
        _jsonFilePath = dParameters_["jsonFilePath"]
        _toJsonFilePath = dParameters_["toJsonFilePath"]
        _withOutList = dParameters_["withOutList"]
        _jsonList = fileUtils.dictFromJsonFile(_jsonFilePath)
        if not _jsonList or not isinstance(_jsonList, list):
            print("ERROR : " + _jsonFilePath + " 不是一个list或者为空")
            sys.exit(1)

        _type = None
        if isinstance(_jsonList[0], list):  # list模式的二维数组
            _type = "List"
        elif isinstance(_jsonList[0], dict):  # list的模式是对象数组
            _type = "DictList"
        else:
            print("ERROR : " + _jsonFilePath + " 列表元素为意外类型。")

        _backList = []
        if _type == "List":  # 是列表,那么就第一行是字段名,将字段名转换成序号,然后过滤掉
            _parameterList = _jsonList[0]
            _newParameterList = []
            _withOutIdxList = []
            for _i in range(len(_parameterList)):
                if _parameterList[_i] in _withOutList:
                    _withOutIdxList.append(_i)  # 记录要过滤的序号
                else:
                    _newParameterList.append(_parameterList[_i])  # 保留非过滤项
            _backList.append(_newParameterList)
            for _i in range(1, len(_jsonList)):
                _elementList = _jsonList[_i]
                _newElementList = []
                for _j in range(len(_elementList)):
                    if not _j in _withOutIdxList:
                        _newElementList.append(_elementList[_j])
                _backList.append(_newElementList)
        elif _type == "DictList":
            for _i in range(len(_jsonList)):
                _elementDict = _jsonList[_i]
                for _delParameterName in _withOutList:  # 直接删除对应的键值
                    del _elementDict[_delParameterName]
                    _backList = _jsonList

        fileUtils.writeFileWithStr(  # 写回去
            _toJsonFilePath,
            str(json.dumps(_backList, indent=4, sort_keys=False, ensure_ascii=False))
        )
Beispiel #12
0
def linkLogUtilsAsmdef(csFolder, logUtilsMetaGuid_):
    _asmdefList = folderUtils.getFilePathWithSuffixInFolder(csFolder, ".asmdef")
    for _i in range(len(_asmdefList)):
        _asmdefPath = _asmdefList[_i]
        print('_asmdefPath = ' + str(_asmdefPath))
        _asmdefDict = fileUtils.dictFromJsonFile(_asmdefPath)
        # logUtils 的 guid
        _logUtilsAsmdefGuid = ("GUID:" + logUtilsMetaGuid_)
        # 在 asmdef 的依赖上查找,如果不在依赖上那么就添加这个
        if "references" in _asmdefDict and _logUtilsAsmdefGuid not in _asmdefDict["references"]:
            # 这个字段是 source compare 比对手动指定 LogUtils.asmdef 得到的
            if "rootNamespace" not in _asmdefDict:
                _asmdefDict["rootNamespace"] = ""
            # 添加依赖 guid
            _asmdefDict["references"].append(_logUtilsAsmdefGuid)
            _newContent = str(json.dumps(_asmdefDict, indent=4, sort_keys=False, ensure_ascii=False))
            print('_newContent = ' + str(_newContent))
            fileUtils.writeFileWithStr(_asmdefPath, _newContent)
Beispiel #13
0
    def create(self):
        super(SpineAnalyse, self).create()

        _spineMainFolderPath = "/Volumes/18604037792/develop/ShunYuan/farmNew/SpineAssets/建筑Spine/"
        _outputFolderPath = _spineMainFolderPath + "output/"
        _spineList = folderUtils.getFolderListJustOneDepth(
            _spineMainFolderPath)
        for _i in range(len(_spineList)):
            _spineName = str(_spineList[_i])  # 文件夹名为Spine名
            _spineFolderPath = os.path.join(_spineMainFolderPath, _spineName)
            _imageFolderPath = os.path.join(_spineFolderPath,
                                            "images")  # 其中包含images文件夹
            _outFolderPath = os.path.join(_spineFolderPath,
                                          "out")  # 且包含一个输出文件夹
            if os.path.exists(_imageFolderPath) and os.path.exists(
                    _outFolderPath):
                print("o - " + _spineName)
                # altas中的图片
                _pngList = self.pngListFromAltas(
                    folderUtils.getFilterFilesInPath(_outFolderPath,
                                                     [".txt"])[0])
                # 动画信息
                _jsonFilePath = folderUtils.getFilterFilesInPath(
                    _outFolderPath, [".json"])[0]
                _jsonName = fileUtils.justName(_jsonFilePath)  # json名称
                _jsonDict = fileUtils.dictFromJsonFile(_jsonFilePath)

                # attachments 变更
                _slotAndPngRelationDict = _jsonDict["skins"][0]["attachments"]
                _tempDict = {}
                # 变更键名
                for _key in _slotAndPngRelationDict:
                    _tempDict[_key] = {}
                    for _pngKey in _slotAndPngRelationDict[_key]:
                        _pngInfoDict = _slotAndPngRelationDict[_key][_pngKey]
                        if not "type" in _pngInfoDict:
                            _tempDict[_key][_jsonName + "_" +
                                            _pngKey] = _pngInfoDict
                        else:
                            if _pngInfoDict["type"] == "mesh":
                                _tempDict[_key][_jsonName + "_" +
                                                _pngKey] = _pngInfoDict
                            else:
                                _tempDict[_key][_pngKey] = _pngInfoDict
                _jsonDict["skins"][0]["attachments"] = _tempDict

                # 更改后的json放置位置
                _jsonOutputPath = _outputFolderPath + _jsonName + ".json"
                fileUtils.dictToJsonFile(_jsonOutputPath, _jsonDict)

                # 图片字典
                _pngFolderPath = os.path.join(_outputFolderPath,
                                              _jsonName) + "/"
                fileCopyUtils.copyFilesInFolderTo([".png"], _imageFolderPath,
                                                  _pngFolderPath, "include",
                                                  True)
                _pngPathList = folderUtils.getFilterFilesInPath(
                    _pngFolderPath, [".png"])
                for _j in range(len(_pngPathList)):
                    _pngName = fileUtils.justName(_pngPathList[_j])  # png名称
                    os.rename(
                        _pngPathList[_j],
                        _pngFolderPath + _jsonName + "_" + _pngName + ".png")
            else:
                print("x - " + _spineName)
Beispiel #14
0
    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
Beispiel #15
0
                showDictStructure(_value, depth_ + 1)
            elif isinstance(_value, list) or isinstance(object_, tuple):
                if len(_value) > 0:
                    print("|      " * depth_ + "+--" + str(_key) + " [0]")
                    showDictStructure(_value[0], depth_ + 1)
                else:
                    print("|      " * depth_ + "+--" + str(_key) + " []")
            else:
                print("|      " * depth_ + "+--" + str(_key))
    elif isinstance(object_, str):
        print("|      " * depth_ + "- <str>")
    elif isinstance(object_, bool):
        print("|      " * depth_ + "- <bool>")
    elif isinstance(object_, int):
        print("|      " * depth_ + "- <int>")
    elif isinstance(object_, float):
        print("|      " * depth_ + "- <float>")
    elif isinstance(object_, complex):
        print("|      " * depth_ + "- <complex>")
    else:
        print("Unkown type")


if __name__ == "__main__":
    # _dict = json.loads("{\"cmd\": \"game\"}")
    # showDictStructure(_dict)
    showDictStructure(
        fileUtils.dictFromJsonFile(
            "/Volumes/18604037792/develop/TuYoo/GIT/MJ/majiang3d_super/Assets/AssetsMJ/ABRes/Configs/queshen/queshen.json"
        ))
def printIssueByArea(issueDict_: dict, area_: str):
    _printStr = ""
    _printStr += "AREA : " + area_ + "\n"
    for _key in issueDict_:
        _codeIssuesInfo = issueDict_[_key]
        if _codeIssuesInfo.area == area_:
            _tempPrintStr = _codeIssuesInfo.printSelf()
            if _tempPrintStr:
                _printStr += _tempPrintStr
    return _printStr


if __name__ == '__main__':
    _reportJsonFilePath = "/Users/jiasy/Downloads/project-auditor-report.json"
    _reportAnalyseFilePath = "/Users/jiasy/Downloads/project-auditor-report_analyse"
    _reportDict = fileUtils.dictFromJsonFile(_reportJsonFilePath)
    _m_Issues = _reportDict["m_Issues"]
    _codeIssuesDict = CodeIssuesDict()
    _areaList = []
    for _i in range(len(_m_Issues)):
        _descriptor = _m_Issues[_i]["descriptor"]
        _location = _m_Issues[_i]["location"]
        # 类目不止一个的时候提示一下
        if len(_descriptor["areas"]) > 1:
            print("areas > 1 : " + str(
                json.dumps(
                    _descriptor, indent=4, sort_keys=False,
                    ensure_ascii=False)))
        # 记录出现的 area 类型
        _area = _descriptor["areas"][0]
        if _area not in _areaList: