3 # this script adds a set of SVN-properties to files and directories under
4 # a directory that is specified on the command line
6 from popen2
import popen2
10 from os
import path
,listdir
16 raus
,rein
=popen2(svnCommand
+" "+cmd
)
17 result
=raus
.readlines()
22 def getProperty(fName
,property):
23 raw
=runSvn("propget %s %s" % (property,fName
))
24 return string
.join(raw
)
26 def setProperty(fName
,property,value
):
27 runSvn("propset %s \"%s\" %s" % (property,value
,fName
))
29 def addToListProperty(fName
,property,value
):
30 tmp
=getProperty(fName
,property)
31 lst
=map(string
.strip
,string
.split(tmp
))
36 val
=string
.join(lst
,"\n")
37 setProperty(fName
,property,val
)
40 def addKeyword(fName
,keyword
):
41 return addToListProperty(fName
,"svn:keywords",keyword
)
43 def addIgnore(fName
,keyword
):
44 return addToListProperty(fName
,"svn:ignore",keyword
)
46 def recursivlyDoToFiles(directory
,fileFilter
,function
,isDir
=False,testSvn
=True):
47 if testSvn
and not isSVK
:
48 if not path
.exists(path
.join(directory
,".svn")):
51 for f
in glob
.glob(path
.join(directory
,fileFilter
)):
52 if not path
.isfile(f
) and not path
.isdir(f
):
55 if (isDir
and path
.isfile(f
)) or (not isDir
and path
.isdir(f
)):
58 if isDir
and testSvn
and not isSVK
:
59 if not path
.exists(path
.join(f
,".svn")):
65 for f
in listdir(directory
):
66 if f
not in [".svn","lnInclude"]:
67 tmp
=path
.join(directory
,f
)
69 recursivlyDoToFiles(tmp
,fileFilter
,function
,isDir
=isDir
,testSvn
=testSvn
)
71 if not path
.exists(path
.join(sys
.argv
[1],".svn")):
75 print "\nAdding Id-keyword to Python-files"
76 recursivlyDoToFiles(sys
.argv
[1],"*.py",lambda x
:addKeyword(x
,"Id"))
78 print "\nAdding Id-keyword to C++-files"
79 recursivlyDoToFiles(sys
.argv
[1],"*.C",lambda x
:addKeyword(x
,"Id"))
81 print "\nAdding Id-keyword to C++-headers"
82 recursivlyDoToFiles(sys
.argv
[1],"*.H",lambda x
:addKeyword(x
,"Id"))
84 print "\nAdding *Opt to ignore-list for Make-directories"
85 recursivlyDoToFiles(sys
.argv
[1],"Make",lambda x
:addIgnore(x
,"*Opt"),isDir
=True)
87 print "\nAdding *Debug to ignore-list for Make-directories"
88 recursivlyDoToFiles(sys
.argv
[1],"Make",lambda x
:addIgnore(x
,"*Debug"),isDir
=True)
90 print "\nAdding lnInclude to ignore-list for all directories"
91 recursivlyDoToFiles(sys
.argv
[1],"*",lambda x
:addIgnore(x
,"lnInclude"),isDir
=True)
93 print "\nAdding *.dep to ignore-list for all directories"
94 recursivlyDoToFiles(sys
.argv
[1],"*",lambda x
:addIgnore(x
,"*.dep"),isDir
=True)