def modifyFolderName(file_dir): if _projectNameTup == None: return fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) tmp_pathList = '/.git/' not in tmp_path and tmp_path.split('/') FolderName = tmp_pathList[-1] if _projectNameTup[0] in FolderName: FolderName = FolderName.replace(_projectNameTup[0], _projectNameTup[1]) tmp_pathList[-1] = FolderName new_path = '/'.join(tmp_pathList) try: os.rename(tmp_path, new_path) conLog.info('[MissProName OK] ' + new_path) tmp_path = new_path except Exception as e: try: conLog.error('[MissProName Fail] ' + str(e)) finally: e = None del e if not os.path.isdir(tmp_path): pass else: modifyFolderName(tmp_path)
def cycTra_for_methodListMap(file_dir, funNamePrefix): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('.h'): pass if not igFil.isIgnoreFiles(tmp_path): if '+' not in tmp_path: confusionAt_H_Obj(tmp_path, funNamePrefix) conLog.info('[ConFunH OK] ' + tmp_path) if tmp_path.endswith('.swift'): if not igFil.isIgnoreFiles(tmp_path): if '+' not in tmp_path: if 'Tests.swift' not in tmp_path: confusionAt_Swift_Obj(tmp_path, funNamePrefix) conLog.info('[ConFunH OK] ' + tmp_path) except Exception as e: try: conLog.error('[ConFunH Fail] ' + str(e)) finally: e = None del e else: cycTra_for_methodListMap(tmp_path, funNamePrefix)
def startAddRubbishCode(file_dir, amount, rubPrefix): if amount <= 0: conLog.error('[AddCode Fail] <=0') return initData() realizeRubbishFunCode(file_dir, amount, rubPrefix) propertyListAtMFile(file_dir)
def cycTraPropertyListMap(file_dir, propertyPrefix): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('.h'): if not igFil.isIgnoreFiles(tmp_path): pass if '+' not in tmp_path: if 'AppDelegate.' not in tmp_path: getPropertyNameAtHFile(tmp_path, propertyPrefix) conLog.info('[ReadProH OK] ' + tmp_path) if tmp_path.endswith('.swift'): if not igFil.isIgnoreFiles(tmp_path): if '+' not in tmp_path: if 'AppDelegate.' not in tmp_path: getPropertyNameAtSwiftAndMiss( tmp_path, propertyPrefix) conLog.info('[ReadProH OK] ' + tmp_path) except Exception as e: try: conLog.error('[ReadProH Fail] ' + str(e)) finally: e = None del e else: cycTraPropertyListMap(tmp_path, propertyPrefix)
def cycTraMissPropertyAtMFile(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('.m') or tmp_path.endswith( '.mm') or tmp_path.endswith( '.xib') or tmp_path.endswith('.storyboard'): if '/Pods/' not in tmp_path: missPropertyAtMFile(tmp_path) conLog.info('[ConFunM OK] ' + tmp_path) if tmp_path.endswith('.swift'): if '/Pods/' not in tmp_path: missPublicProAtSwiftFile(tmp_path) conLog.info('[ConFunM OK] ' + tmp_path) except Exception as e: try: conLog.error('[ConFunM Fail] ' + str(e)) finally: e = None del e else: cycTraMissPropertyAtMFile(tmp_path)
def reviseFilesName(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if not igFil.isIgnoreFiles(tmp_path): if tmp_path.endswith('.h') or tmp_path.endswith( '.m') or tmp_path.endswith( '.xib') or tmp_path.endswith('.swift'): for object_name in objectNamesMap.keys(): replace_name = objectNamesMap[object_name] new_path = tmp_path.replace( object_name + '.', replace_name + '.') if tmp_path != new_path: os.rename(tmp_path, new_path) conLog.info('[ReFilNa Scu] ' + tmp_path) except Exception as e: try: conLog.error('[ReFilNa Fail] ' + str(e)) finally: e = None del e else: reviseFilesName(tmp_path)
def findProjectPbxproj(file_dir): if _projectNameTup == None: return fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('project.pbxproj'): if not igFil.isIgnoreFiles(tmp_path): modifyProjectPbxproj(tmp_path) if '/Pods/' in tmp_path or tmp_path.endswith('contents.xcworkspacedata'): modifyProjectPbxproj(tmp_path) else: if '/Pods/' not in tmp_path: if tmp_path.endswith('Podfile'): modifyProjectPbxproj(tmp_path) conLog.info('[MissProName OK] ' + tmp_path) except Exception as e: try: conLog.error('[MissProName Fail] ' + str(e)) finally: e = None del e else: findProjectPbxproj(tmp_path)
def propertyListAtMFile(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('.m') or tmp_path.endswith('.mm'): if not notUpdateFile(tmp_path): getPropertyList(tmp_path) conLog.info('[CallFun OK] ' + tmp_path) except Exception as e: try: conLog.error('[CallFun Fail] ' + str(e)) finally: e = None del e else: propertyListAtMFile(tmp_path)
def startReplaceSouName(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if not igFil.isIgnoreFiles(tmp_path): if '/Contents.json' not in tmp_path: replaceAtFile(tmp_path) conLog.info('[RepSouNa OK] ' + tmp_path) except Exception as e: try: conLog.error('[RepSouNa Fail] ' + str(e)) finally: e = None del e else: startReplaceSouName(tmp_path)
def getNewProjectPbxprojPath(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('project.pbxproj'): if '/Pods/' not in tmp_path: missProjectPbxproj(tmp_path) conLog.info('[MissFolder OK] ' + tmp_path) except Exception as e: try: conLog.error('[MissFolder Fail] ' + str(e)) finally: e = None del e else: getNewProjectPbxprojPath(tmp_path)
def encryptString(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if not igFil.isIgnoreFiles(tmp_path): pass if not tmp_path.endswith('.pch'): obfuscate(tmp_path) conLog.info('[EncrStr OK] ' + tmp_path) except Exception as e: try: conLog.error('[EncrStr Fail] ' + str(e)) finally: e = None del e else: encryptString(tmp_path)
def searchPchFile(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('.pch'): pass if '/Pods/' not in tmp_path: addCodeAtPch(tmp_path) conLog.info('[SearPCH OK] ' + tmp_path) except Exception as e: try: conLog.error('[SearPCH Fail] ' + str(e)) finally: e = None del e else: searchPchFile(tmp_path)
def searchMissCode(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if not igFil.isIgnoreFiles(tmp_path): pass if tmp_path.endswith('.m'): missCodeAtFile(tmp_path) conLog.info('[SearchStr OK] ' + tmp_path) except Exception as e: try: conLog.error('[SearchStr Fail] ' + str(e)) finally: e = None del e else: searchMissCode(tmp_path)
def replaceFilesObjNames(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if '/Pods/' not in tmp_path: if not tmp_path.endswith('.json'): if '/.git/' not in tmp_path: reviseObjectNames(tmp_path) conLog.info('[ReObjNa OK] ' + tmp_path) except Exception as e: try: conLog.error('[ReObjNa Fail] ' + str(e)) finally: e = None del e else: replaceFilesObjNames(tmp_path)
def getProjectPbxprojPath(file_dir): global pbxprojPath fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('project.pbxproj'): if '/Pods/' not in tmp_path: pbxprojPath = tmp_path getPBXGroupMap(tmp_path) conLog.info('[GetPbxPath OK] ' + tmp_path) except Exception as e: try: conLog.error('[GetPbxPath Fail] ' + str(e)) finally: e = None del e else: getProjectPbxprojPath(tmp_path)
def startDeleteNotes(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if not igFil.isIgnoreFiles(tmp_path): if tmp_path.endswith('.h') or tmp_path.endswith( '.m') or tmp_path.endswith( '.mm') or tmp_path.endswith( '.swift') or tmp_path.endswith('.pch'): readFileEveryLine(tmp_path) conLog.info('[DelNote OK] ' + tmp_path) except Exception as e: try: conLog.error('[DelNote Fail] ' + str(e)) finally: e = None del e else: startDeleteNotes(tmp_path)
def findFolderAndMiss(file_dir): global _pchPath global _plistPath fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): if tmp_path.endswith('.pch'): if '/Pods/' not in tmp_path: _pchPath = tmp_path if tmp_path.endswith('/Info.plist'): if 'Tests/' not in tmp_path: if '/Pods/' not in tmp_path: _plistPath = tmp_path else: missName = os.path.isdir(tmp_path) and getThisPathMissName( tmp_path) if missName != None: pathList = tmp_path.split('/') del pathList[-1] pathList.append(missName) temp = '/'.join(pathList) oldname = os.path.join(file_dir, tmp_path) newname = os.path.join(file_dir, temp) try: os.rename(oldname, newname) findFolderAndMiss(newname) conLog.info('[MissFolder OK] ' + newname) except Exception as e: try: conLog.error('[MissFolder Fail] ' + str(e)) findFolderAndMiss(tmp_path) finally: e = None del e else: findFolderAndMiss(tmp_path)
def startUpdateSourceHash(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if not igFil.isIgnoreFiles(tmp_path): if isImage(tmp_path): old_hash = getFileHash(tmp_path) updateImgHash(tmp_path) new_hash = getFileHash(tmp_path) conLog.info('[UPdHash OK] ' + tmp_path) conLog.tips('[UPdHash Meg] Old:' + old_hash + '<->New:' + new_hash) except Exception as e: try: conLog.error('[UPdHash Fail] ' + str(e)) finally: e = None del e else: startUpdateSourceHash(tmp_path)
def cycTraMyPropertyList(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('.m') or tmp_path.endswith('.mm'): if '/Pods/' not in tmp_path: getMyPropertyList(tmp_path) conLog.info('[GetGroL OK] ' + tmp_path) if tmp_path.endswith('.swift'): if '/Pods/' not in tmp_path: getMyPropertyListForSwift(tmp_path) conLog.info('[GetGroL OK] ' + tmp_path) except Exception as e: try: conLog.error('[GetGroL Fail] ' + str(e)) finally: e = None del e else: cycTraMyPropertyList(tmp_path)
def cycTra_for_ConMFile(file_dir): fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if not os.path.isdir(tmp_path): try: if tmp_path.endswith('.m'): if '/Pods/' not in tmp_path: confusionAt_M_Obj(tmp_path) conLog.info('[ConFunM OK] ' + tmp_path) if tmp_path.endswith('.swift'): if '/Pods/' not in tmp_path: confusionSwiftObjFun(tmp_path) conLog.info('[ConFunM OK] ' + tmp_path) except Exception as e: try: conLog.error('[ConFunM Fail] ' + str(e)) finally: e = None del e else: cycTra_for_ConMFile(tmp_path)
def searchXcassets(file_dir, imgPreFix): global sourceTypeMap global xcassetsMap fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if os.path.isdir(tmp_path): pass if tmp_path.endswith('.imageset'): try: if not igFil.isIgnoreFiles(tmp_path): imgArr = saveNameToMap(tmp_path, imgPreFix) new_path = tmp_path.replace(imgArr[0] + '.imageset', imgArr[1] + '.imageset') if tmp_path != new_path: os.rename(tmp_path, new_path) conLog.info('[SeaXcas Scu] ' + tmp_path) searchXcassets(new_path, imgPreFix) except Exception as e: try: conLog.error('[SeaXcas Fail] ' + str(e)) searchXcassets(tmp_path, imgPreFix) finally: e = None del e elif not os.path.isdir(tmp_path): if '.xcassets' in tmp_path: if isImage(tmp_path): imageType = '.' + tmp_path.split('.')[-1] fatherPath = '/'.join(tmp_path.split('/')[:-1]) imageName = tmp_path.split('/')[-1].split('.')[0] newImgName = imgPreFix + zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() new_path = tmp_path.replace('/' + imageName + imageType, '/' + newImgName + imageType) os.rename(tmp_path, new_path) partMap = {} if fatherPath in xcassetsMap.keys(): partMap = xcassetsMap[fatherPath] partMap[imageName] = newImgName xcassetsMap[fatherPath] = partMap elif not os.path.isdir(tmp_path): if isNeedMissImg(tmp_path): if not igFil.isIgnoreFiles(tmp_path): imageName = tmp_path.strip().split('/')[-1] imageType = '' if '@' in imageName: nameList = imageName.split('@') imageName = nameList[0] imageType = '@' + nameList[-1] else: nameList = imageName.split('.') imageName = nameList[0] imageType = '.' + nameList[-1] if imageName not in sourceMap.keys(): newImgName = imgPreFix + zfjTools.getWordFromLexicon( ) + zfjTools.getWordFromLexicon().capitalize() sourceMap[imageName] = newImgName else: newImgName = sourceMap[imageName] if imageName in sourceTypeMap.keys(): old_imageType = sourceTypeMap[imageName] if old_imageType != imageType: old_imageType += ',' + imageType sourceTypeMap[imageName] = old_imageType else: sourceTypeMap[imageName] = imageType new_path = tmp_path.replace(imageName, newImgName) os.rename(tmp_path, new_path) conLog.info('[SeaXcas Scu] ' + tmp_path) else: if os.path.isdir(tmp_path): searchXcassets(tmp_path, imgPreFix)