def delResAtProjectPbxproj(): if _projectPbxprojPath != None: _needDelResName = [] file_data = '' Ropen = open(_projectPbxprojPath, 'r') for line in Ropen: idAdd = True for resName in _resNameMap: if resName in line: idAdd = False if resName not in _needDelResName: _needDelResName.append(resName) if idAdd == True: file_data += line Ropen.close() Wopen = open(_projectPbxprojPath, 'w') Wopen.write(file_data) Wopen.close() for item in _needDelResName: tmp_path = _resNameMap[item] if os.path.exists(tmp_path): pass if not os.path.isdir(tmp_path): _hadDelMap[item] = tmp_path os.remove(tmp_path) del _resNameMap[item] conLog.info_delRes('[DelRubRes OK] ' + tmp_path) continue
def searchProjectCode(file_dir): global _projectPbxprojPath fs = os.listdir(file_dir) for dir in fs: tmp_path = os.path.join(file_dir, dir) if tmp_path.endswith('project.pbxproj'): _projectPbxprojPath = tmp_path if not os.path.isdir(tmp_path): if '/Pods/' not in tmp_path: try: findResNameAtFileLine(tmp_path) conLog.info_delRes('[ReadFileForRes OK] ' + tmp_path) except Exception as e: try: pass finally: e = None del e else: searchProjectCode(tmp_path)
def searchAllResName(file_dir): global _resNameMap 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 isResource(tmp_path) == True: if '/Pods/' not in tmp_path: if '.appiconset' not in tmp_path: pass if '.launchimage' not in tmp_path: imageName = tmp_path.split('/')[-1].split('.')[0] _resNameMap[imageName] = tmp_path conLog.info_delRes('[FindRes OK] ' + tmp_path) elif os.path.isdir(tmp_path): if tmp_path.endswith('.imageset'): if '/Pods/' not in tmp_path: imageName = tmp_path.split('/')[-1].split('.')[0] _resNameMap[imageName] = tmp_path conLog.info_delRes('[FindRes OK] ' + tmp_path) else: searchAllResName(tmp_path)
def delAllRubRes(): global _hadDelMap for resName in list(_resNameMap.keys()): tmp_path = _resNameMap[resName] if tmp_path.endswith('.imageset'): if os.path.exists(tmp_path): if os.path.isdir(tmp_path): try: _hadDelMap[resName] = tmp_path delImagesetFolder(tmp_path) del _resNameMap[resName] conLog.info_delRes('[DelRubRes OK] ' + tmp_path) except Exception as e: try: conLog.error_delRes('[DelRubRes Fail] [' + str(e) + ']' + tmp_path) finally: e = None del e else: conLog.error_delRes('[DelRubRes Fail] [not exists] ' + tmp_path) delResAtProjectPbxproj()
def startCleanRubRes(file_dir, ignoreList=[]): global _isCleaing if _isCleaing == True: return _isCleaing = True initData() conLog.info('------------------------------------------------------------') searchAllResName(file_dir) conLog.info_delRes('----------------------------------------') conLog.info_delRes(_resNameMap) for item in ignoreList: if item in list(_resNameMap.keys()): del _resNameMap[item] conLog.info_delRes('----------------------------------------') conLog.info_delRes(ignoreList) searchProjectCode(file_dir) conLog.info_delRes('----------------------------------------') conLog.info_delRes(_resNameMap) delAllRubRes() conLog.info_delRes('----------------------------------------') conLog.info_delRes(_hadDelMap) conLog.info_delRes('----------------------------------------') conLog.info_delRes(_resNameMap) _isCleaing = False