ThirdParty packages: Add comment in README file. Contributed by Darrin Stephens
[OpenFOAM-1.6-ext.git] / bin / foamEditProperties.py
blobb2d6ca6d900ff6c2fbd7bc548e79a1981c6f0b2b
1 #!/usr/bin/python
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
7 import sys
8 import string
9 import glob
10 from os import path,listdir
12 svnCommand="svn"
13 isSVK=False
15 def runSvn(cmd):
16 raus,rein=popen2(svnCommand+" "+cmd)
17 result=raus.readlines()
18 rein.close()
19 raus.close()
20 return result
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))
32 if not value in lst:
33 lst.append(value)
34 else:
35 return False
36 val=string.join(lst,"\n")
37 setProperty(fName,property,val)
38 return True
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")):
49 return
51 for f in glob.glob(path.join(directory,fileFilter)):
52 if not path.isfile(f) and not path.isdir(f):
53 continue
55 if (isDir and path.isfile(f)) or (not isDir and path.isdir(f)):
56 continue
58 if isDir and testSvn and not isSVK:
59 if not path.exists(path.join(f,".svn")):
60 continue
62 if function(f):
63 print "....",f
65 for f in listdir(directory):
66 if f not in [".svn","lnInclude"]:
67 tmp=path.join(directory,f)
68 if path.isdir(tmp):
69 recursivlyDoToFiles(tmp,fileFilter,function,isDir=isDir,testSvn=testSvn)
71 if not path.exists(path.join(sys.argv[1],".svn")):
72 svnCommand="svk"
73 isSVK=True
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)