def recordMove(self, oldPath, newPath):
     oldPath = re.sub(comFun.turnBias(comFun.OUTPUTTARGET), "Channel/",
                      oldPath)
     newPath = re.sub(comFun.turnBias(comFun.MOVETOCODEPATH), "CodePath/",
                      newPath)
     if "MoveRecord" in self.tidyInfo:
         self.tidyInfo["MoveRecord"][oldPath] = newPath
     else:
         MoveRecord = {}
         self.tidyInfo["MoveRecord"] = MoveRecord
         MoveRecord[oldPath] = newPath
 def replaceFile(self):
     jsonPaths = []
     comFun.initPathFiles(comFun.SEARCHJSONPATH , jsonPaths)
     # jsonPaths = ["D:\Svn_2d\UI_Shu\Json\obtain_prop_dialog.json","D:\Svn_2d\UI_Shu\Json\hall.json"]
     if not os.path.exists(comFun.OUTPUTPATH):
         os.mkdir(comFun.OUTPUTPATH , 0o777)        # 创建输出路径
     for jsonPath in jsonPaths:
         if not re.search(r".json" , jsonPath):
             continue
         jsonPath = comFun.turnBias(jsonPath)
         _ , filename = os.path.split(jsonPath)
         newFilePath = comFun.turnBias(comFun.OUTPUTPATH + filename)
         if cmp(newFilePath , jsonPath) != 0:
             shutil.copyfile(jsonPath , newFilePath)
         print("\n==========>>>>" + newFilePath)
         self.streamDispose(newFilePath)
     # 对数据进行记录处理
     comFun.RecordToJsonFile(comFun.CHANGERESULT, self.changeRecord)
 def copyFileToPath(self, oldPath, newPath):
     if not os.path.isabs(oldPath):
         oldPath = os.path.abspath(oldPath)
     oldPath = comFun.turnBias(oldPath)
     dir = os.path.dirname(newPath)  # 创建文件路径
     if not os.path.isdir(dir):
         os.makedirs(dir, 0o777)
     if os.path.isfile(oldPath):
         if os.path.isfile(newPath):
             # print "new path is exist"
             return
         else:
             newPath = comFun.turnBias(newPath)
             shutil.copyfile(oldPath, newPath)
             self.otherTypeDispose(oldPath, newPath)
             self.recordMove(oldPath, newPath)
     else:
         print "not find file : " + oldPath
         return
 def iniJsonFileList(self):
     folderFiles = []  # 存储所有的json文件
     comFun.initPathFiles(comFun.SEARCHJSONPATH, folderFiles)
     for jsonpath in folderFiles:
         _, fileType = os.path.splitext(jsonpath)
         if cmp(fileType, ".json") != 0:
             continue
         if not os.path.isabs(jsonpath):
             jsonpath = os.path.abspath(jsonpath)
         jsonpath = comFun.turnBias(jsonpath)
         if not os.path.isfile(jsonpath):
             assert (False)
         self.json_res[jsonpath] = []
         # print("Json has res : " + jsonpath)
         self.cmpJsonResType(jsonpath)
    def getNewResInfo(self , path):
        path = comFun.turnBias(comFun.REALPATH + path)
        md5code = self.FileData.getFileMd5(path)
        newFileName = self.FileData.getNewPathByMd5Code(md5code) # 需要做一个去处本地路径处理

        if md5code in self.plistMd5:
            newFileDict = collections.OrderedDict()
            newFileDict["newpath"] = os.path.basename(newFileName)
            newFileDict["plist"] = self.plistMd5.get(md5code)
            newFileDict["oldpath"] = path
            # print json.dumps(newFileDict, ensure_ascii=False, encoding="utf -8", indent=4)
            return newFileDict
        else:
            if self.FileData.getTPathByMd5Code(md5code):  # 包括大图,fnt,和手动设置为不进行打包的聂内容集合
                return self.FileData.getTPathByMd5Code(md5code)
            print "Not in Plist > " + path.ljust(60)  + " newPath:" + newFileName.ljust(45) + "md5:" + md5code
            return newFileName
 def initNewImageInfo(self):
     folderFiles = []  # 存储所有的json文件
     comFun.initPathFiles(comFun.PACKAGEOUTPUT, folderFiles)
     for plistPath in folderFiles:
         if not os.path.isabs(plistPath):
             plistPath = os.path.abspath(plistPath)
         plistPath = comFun.turnBias(plistPath)
         if not os.path.isfile(plistPath):
             print(" not found file " + plistPath)
             assert(False)
         _,filetype = os.path.splitext(plistPath)
         if cmp(filetype , r".plist") != 0:
             continue
         tree = ET.parse(plistPath)
         root = tree.getroot()
         elements = self.getListElement(root)
         self.initPlistInfo(elements , plistPath)
 def judgeResNum(self , modulePath):
     SourcePath = comFun.PACKAGESOURCE + "common"
     if not os.path.isdir(SourcePath):
         os.mkdir(SourcePath, 0o777)
     folderFiles = []  # 存储所有的json文件
     comFun.initPathFiles(modulePath, folderFiles)
     if not len(folderFiles):
         return False
     if len(folderFiles) < comFun.UNPACKAGENUM:   # 不要每次都移动图片,判断使用的图片是否满足条件后再做图片的移动处理
         for resPath in folderFiles:
             resPath = comFun.turnBias(resPath)
             md5code = self.moveRecord[resPath]["md5"]
             if md5code in self.unPackRepeat:   # 已经被移动过一次,则移动回原来的位置去,避免图片重复出现
                 print "repeat :" + resPath
                 self.moveResToPath(resPath, comFun.RESPATH, True)
             else:
                 self.moveResToPath(resPath, SourcePath, True)  # 达不到打包条件的图片会统一存放到这个位置,没有进行进一步的处理
                 self.unPackRepeat[self.moveRecord[resPath]["md5"]] = SourcePath + "/" + os.path.basename(resPath)
             # 要做进一步的处理,出现的一个情况是一个文件可能被多个(具体为2个,2个以上会另外打包)json使用 1000497.png 就是其中的情况之一
         return False
     return True
 def cmpJsonResType(self, jsonpath):
     file_stream = open(jsonpath, "rb")
     printLineNum = 0
     for line in file_stream.readlines():
         # if printLineNum == 2:
         #     print "------------------------------------------"
         # if printLineNum > 0:
         #     printLineNum -= 1
         #     line = re.sub(r"\s|\r|\n", "", line)
         #     if not re.search(r"plistFile|resourceType" , line):    # path、plistFile、resourceType
         #         print line + jsonpath
         # 结论 if not textures then texturesPng = []
         if re.search(r":\\", line):
             line = re.sub(r"\s|\r|\n", "", line)
             # print "Local Image Line : " + line + "by: " + jsonpath
             continue
         for resType in self.pResDict.iterkeys():  # 从json文件中,找到所有包含资源文件的行
             # print resType
             resType = str.replace(str(resType), ".", "\.")  # 把点号也匹配上,字符串替换
             if re.search(resType, line):
                 line = re.sub(r"\s|\r|\n", "", line)
                 # print line
                 printLineNum = 2
                 reType = re.compile(r"\"([^:]+" + resType +
                                     r")\"")  # :不是特殊字符跟字母一样 , ()不是特殊字符串
                 serchObj = reType.search(line)
                 # groupdict 返回以有别名的组的别名为键、以该组截获的子串为值的字典,没有别名的组不包含在内。default含义同上。
                 if serchObj:
                     realPath = comFun.REALPATH + serchObj.group(1)
                     if not os.path.isabs(realPath):
                         realPath = os.path.abspath(realPath)
                     realPath = comFun.turnBias(realPath)
                     self.json_res[jsonpath].append(
                         realPath)  # 记录每个文件中都包含了多少的资源
                 else:
                     print line + " regular failed "
                     assert (False)
                 break
 def changeResPath(self , pDictList):
     for tDict in pDictList:
         if not tDict["resourceType"] and tDict["path"]:
             record = collections.OrderedDict()
             self.recordDict[str(len(self.recordDict))] = record
             record["old"] = copy.deepcopy(tDict)
             newFileDict = self.getNewResInfo(tDict["path"])
             if type(newFileDict)is collections.OrderedDict:
                 tDict["path"] = newFileDict["newpath"]  # 直接改动生效
                 tDict["plistFile"] = re.sub(comFun.PACKAGEOUTPUT, "res_package/", comFun.turnBias(newFileDict["plist"]))
                 tDict["resourceType"] = 1
             else:
                 tDict["path"] = re.sub(comFun.OUTPUTTARGET , "" , newFileDict ) # 去除本地路径
                 tDict["resourceType"] = 0
                 tDict["plistFile"] = ""
             record["new"] = copy.deepcopy(tDict)
 def recordMovePath(self , path ,tPath):
     tPath = comFun.turnBias(tPath)
     self.moveRecord[tPath] = self.FileData.getResInfoByNewPath(path)