svn批量的添加ignore
2024-09-08 17:04:06
svn没有批量添加ignore file的功能,只能一个个目录去设置,故写了脚本自动化的执行
使用了svn propset,故改了ignore file,可以反复的执行此脚本
#!/usr/bin/python
# -*- coding: utf8 -*-
# antsmallant 2018.09.05 import time
import os
import sys
import commands def print_usage():
myname = os.path.basename(sys.argv[0])
help = '''
#######################################################
usage : {0} ignore_file
e.g : {0} ../server/ignore.txt ignore_file looks like:
bin/3rd/a
bin/b
bin/c/d/e #######################################################
'''.format(myname)
print(help) #exe shell cmd, return True if no error, otherwise False
def exe_cmd(cmdstr):
print("exe_cmd, cmdstr={0}".format(cmdstr))
status, output = commands.getstatusoutput(cmdstr)
if status != 0:
print("exe_cmd fail, error={0}, errorcode={1}, cmdstr={2}".format(output, status>>8, cmdstr))
return False
print("exe_cmd success, output={0}".format(output))
return True #retrun dict
def parse_ignore_file(file_path):
f = open(file_path, "r")
allline = f.readlines()
f.close()
ret = {}
for line in allline:
line = line.strip()
line = line.replace("\n", "")
line = line.replace("\r", "")
if len(line) == 0:
continue
dn = os.path.dirname(line)
bn = os.path.basename(line)
if ret.has_key(dn):
ret[dn].append(bn)
else:
ret[dn] = []
ret[dn].append(bn)
return ret def set_ignore(dn, filelist):
assert len(filelist) > 0, "filelist has no data"+str(filelist)
print("set_ignore" + dn)
#make temp ignore file
temp_ignore = os.path.join(dn, "temp_ignore.txt")
f = open(temp_ignore, "w")
if not f:
return False
for i in filelist:
f.write(i+"\n")
f.flush()
f.close()
cmd = "cd {0} && svn up && svn propset svn:ignore ./ -F {1}".format(dn, temp_ignore)
ok = exe_cmd(cmd)
if not ok:
os.remove(temp_ignore)
return False
cmd = "cd {0}/../ && svn up && svn ci -m 'add ignore' ./".format(dn)
ok = exe_cmd(cmd)
if not ok:
os.remove(temp_ignore)
return False
os.remove(temp_ignore)
return True def main():
if len(sys.argv) < 2:
print("err: arg not given")
print_usage()
return False
ignore_file = os.path.abspath(sys.argv[1])
print("ignore_file: " + ignore_file)
if not os.path.exists(ignore_file):
print("ignore_file not exists")
return False
dn = os.path.dirname(ignore_file)
print("dirname: " + dn)
file_2_ignore = parse_ignore_file(ignore_file)
for k, v in file_2_ignore.items():
ok = set_ignore(os.path.join(dn, k), v)
if not ok:
print("something wrong when doing: "+k+" "+str(v))
return False
return True if __name__ == '__main__':
main()
最新文章
- linux 时间管理——概念、注意点(一)【转】
- elasticsearch 初学 笔记(1)
- Linux终端下安装jdk
- 图片延迟加载jquery插件imgLazyLoad(三)
- Winform 窗体最小化隐藏在桌面右下角:转
- iOS界面开发
- C#深度拷贝和浅度拷贝方法
- 理解Null,Undefined,NAN
- oracle 表空间、用户名 相关语句
- Linux Shell脚本之自动修改IP
- [React] Extracting Private React Components
- linux学习(二)-目录的操作命令
- nodeValue的兼容问题
- CentOS7.0安装Nginx
- H5自定义属性data-*
- Linux系统——MHA-Atlas-MySQL高可用集群
- 软件开发者路线图梗概&;书摘chapter4
- 【bzoj2229】 Zjoi2011—最小割
- 【IDEA】【7】Git更新及提交
- 11.8java课后动手动脑
热门文章
- django 安装cerlery error in anyjson setup command: use_2to3 is invalid.
- go 语言操作es示例
- [转]C#的反射
- android系统签名文件路径及签名方法
- debian11用iso制作本地apt源
- 操作系统实战45讲笔记- 05 CPU工作模式:程序执行的三种模式
- OKHttp 之--------http/https协议处理方法 (Finn_ZengYuan博客)
- Review1(C#语言基础)
- mybatis-关联查询4-多对多查询
- Quartus II 17.1新建一个流水灯