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()

最新文章

  1. linux 时间管理——概念、注意点(一)【转】
  2. elasticsearch 初学 笔记(1)
  3. Linux终端下安装jdk
  4. 图片延迟加载jquery插件imgLazyLoad(三)
  5. Winform 窗体最小化隐藏在桌面右下角:转
  6. iOS界面开发
  7. C#深度拷贝和浅度拷贝方法
  8. 理解Null,Undefined,NAN
  9. oracle 表空间、用户名 相关语句
  10. Linux Shell脚本之自动修改IP
  11. [React] Extracting Private React Components
  12. linux学习(二)-目录的操作命令
  13. nodeValue的兼容问题
  14. CentOS7.0安装Nginx
  15. H5自定义属性data-*
  16. Linux系统——MHA-Atlas-MySQL高可用集群
  17. 软件开发者路线图梗概&amp;书摘chapter4
  18. 【bzoj2229】 Zjoi2011—最小割
  19. 【IDEA】【7】Git更新及提交
  20. 11.8java课后动手动脑

热门文章

  1. django 安装cerlery error in anyjson setup command: use_2to3 is invalid.
  2. go 语言操作es示例
  3. [转]C#的反射
  4. android系统签名文件路径及签名方法
  5. debian11用iso制作本地apt源
  6. 操作系统实战45讲笔记- 05 CPU工作模式:程序执行的三种模式
  7. OKHttp 之--------http/https协议处理方法 (Finn_ZengYuan博客)
  8. Review1(C#语言基础)
  9. mybatis-关联查询4-多对多查询
  10. Quartus II 17.1新建一个流水灯