python学习笔记-解决OC文件重名冲突
来源:互联网 发布:python chm 百度网盘 编辑:程序博客网 时间:2024/05/29 17:20
本人用于解决动态库第三方冲突,添加前缀,防止类名重复
#!/user/bin/python# -*- coding:UTF-8 -*-import osimport fileinputdef prefixFiles(path,prefix): #修改当前目录下全部文件的前缀 - 不包括子文件夹 list = [] files = os.listdir(path) # 路径可以自己 flag = True; for name in files: suffix = ['.m', '.cpp', '.h', '.mm'] a = os.path.splitext(name) if a[1] in suffix: tmpStr = a[0] if tmpStr.startswith(prefix, 0, 4): #如果包含prefix tup = (name[len(prefix):name.find('.')], name[0:name.find('.')]) list.append(tup) else: if name.find("+") != -1: #分类文件处理 pass else: newname = prefix + a[0] + a[1] if flag: os.chdir(path) flag = False tup = (name[0:name.find('.')], newname[0:newname.find('.')]) list.append(tup) os.rename(name, newname) return listdef prefixAllFiles(path,prefix): #修改当前目录及子目录下文件 list = [] list.extend(prefixFiles(path,prefix)) for root, dirs, files in os.walk(path): list.extend(prefixFiles(root,prefix)) for tmp in list: #去除重复 while list.count(tmp) > 1: list.remove(tmp) return listdef replaceSingleDirectory(filepath,tuple): files = os.listdir(filepath) for name in files: suffix = ['.m', '.cpp', '.h', '.mm'] a = os.path.splitext(name) if a[1] in suffix: for tmp in tuple: path = os.path.join(filepath, name) print (path, tmp[0], tmp[1]) os.chdir(filepath) # replaceText2(name,tmp[0], tmp[1]) replaceText(path, tmp[0], tmp[1])def replaceMutableDirectory(path,tuple): replaceSingleDirectory(path,tuple) for root, dirs, files in os.walk(path): replaceSingleDirectory(root,tuple)def replaceText(filepath,oldtext,newtext): tmp = fileinput.input(filepath,inplace=1) tmp.nextfile() for line in tmp: # print fileinput.lineno() if judgeIsOCdefine(line,oldtext,newtext): line = line.replace(oldtext,newtext) print line.strip("\n") else: print line.strip("\n")def judgeIsOCdefine(str,oldtext,newtext): if str.find(oldtext) != -1 and str.find(newtext) == -1 : if len(str) <= len(oldtext): return False tmp = str[str.find(oldtext) + len(oldtext):str.find(oldtext) + len(oldtext) + 1] if tmp == " ": return True elif tmp == ":": return True elif tmp == ";": return True elif tmp == ")": return True elif tmp == "*": return True elif tmp == ".": return True elif tmp == ">": return True elif tmp == ",": return True else: if str.find("@implementation") != -1: return True elif str.find("@interface") != -1: return True else: return Falsedef replaceText2(name,oldtext,newtext): with open(name, "r+") as f: d = f.read() d.replace(oldtext, newtext) f.write(d)def renameOC(path,prefix): tupList = prefixAllFiles(path, prefix) #tuplist (oldname,newname) replaceMutableDirectory(path, tupList) print "success"# find_file_text(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\crt\src','mainCRTStartup')path = raw_input("请输入文件夹路径:").strip()renameOC(path,"HX_")
0 0
- python学习笔记-解决OC文件重名冲突
- git学习- 解决文件冲突
- python学习笔记-批量添加OC文件前缀
- [OC学习笔记]文件管理
- oc文件操作学习笔记
- 解决用户上传文件可能重名问题
- git的学习笔记(冲突解决)
- Maven学习笔记---传递依赖冲突解决
- 文件重名,
- SVN文件冲突解决
- git解决文件冲突
- jquery学习笔记(3)-----jquery与其它库冲突解决
- git学习笔记整理-12-合并冲突解决
- git学习-冲突解决
- Git学习解决冲突
- Python学习笔记--文件读写
- Python 学习笔记【文件对象】
- Python学习笔记--文件操作
- 开始搭建Appium自动化测试环境之安装1.0
- CXF3.1.8开发与spring集成的webService
- stm32L152 使用内部内部flash做EEPROM 出FLASH_ERROR_WRP问题及解决办法
- mysql的between and的用法
- Docker 资源限制之内存
- python学习笔记-解决OC文件重名冲突
- ios动态获取UILabel的高度和宽度
- 异步任务AsyncTask知识点
- MyBatis传入多个参数,传入数组和列表数据的处理
- R语言泛型函数及S3,S4对象机制
- Invalid bound statement (not found)
- Codeforces Round #378 (Div. 2)C. Epidemic in Monstropolis【思维+暴力】
- 时间复杂度的分析
- 100天土鸡饲养计划(79)