使用SVN小文件清除脚本的方法
关键字: Python SVN
隐士以前用惯了ClearCase,换到SVN有点不习惯。ClearCase下面的文件都可以直接Copy出来用,SVN下面的就麻烦了,每个目录下面一个.svn子目录,当你要把项目在Check In前拿去别用时,你就体会到你的项目不是一个项目,此刻SVN灵魂附体令你感觉别扭,当然,Check In后可以用SVN的Export来导出一个干净的项目。不爽,隐士整了个Python脚本,清除这些垃圾。
闲话不多,看脚本:
#!/usr/bin/python
#-*-coding:utf8-*-
#################################
#Writtenbycaocao#
#http://www.caocao.mobi#
#http://www.caocao.name#
#################################
importsys,os,stat
defwalk(path):
foriteminos.listdir(path):
subpath=os.path.join(path,item)
mode=os.stat(subpath)[stat.ST_MODE]
ifstat.S_ISDIR(mode):
ifitem==".svn":
print"Cleaning%s..."%subpath
print"%ddeleted"%purge(subpath)
else:
walk(subpath)
defpurge(path):
count=0
foriteminos.listdir(path):
subpath=os.path.join(path,item)
mode=os.stat(subpath)[stat.ST_MODE]
ifstat.S_ISDIR(mode):
count+=purge(subpath)
else:
os.chmod(subpath,stat.S_IREAD|stat.S_IWRITE)
os.unlink(subpath)
count+=1
os.rmdir(path)
count+=1
returncount
iflen(sys.argv)!=2:
print"Usage:pythonSVNClean.pypath"
sys.exit(1)
walk(sys.argv[1])
#-*-coding:utf8-*-
#################################
#Writtenbycaocao#
#http://www.caocao.mobi#
#http://www.caocao.name#
#################################
importsys,os,stat
defwalk(path):
foriteminos.listdir(path):
subpath=os.path.join(path,item)
mode=os.stat(subpath)[stat.ST_MODE]
ifstat.S_ISDIR(mode):
ifitem==".svn":
print"Cleaning%s..."%subpath
print"%ddeleted"%purge(subpath)
else:
walk(subpath)
defpurge(path):
count=0
foriteminos.listdir(path):
subpath=os.path.join(path,item)
mode=os.stat(subpath)[stat.ST_MODE]
ifstat.S_ISDIR(mode):
count+=purge(subpath)
else:
os.chmod(subpath,stat.S_IREAD|stat.S_IWRITE)
os.unlink(subpath)
count+=1
os.rmdir(path)
count+=1
returncount
iflen(sys.argv)!=2:
print"Usage:pythonSVNClean.pypath"
sys.exit(1)
walk(sys.argv[1])
本文地址:http://www.45fan.com/a/question/69060.html