1 | import os,sys
|
---|
2 |
|
---|
3 | class DirWalker(object):
|
---|
4 |
|
---|
5 | def walk(self,dir,meth):
|
---|
6 | #walks a directory, and executes a callback on each file
|
---|
7 | dir = os.path.abspath(dir)
|
---|
8 | for file in [file for file in os.listdir(dir) if not file in [".",".."]]:
|
---|
9 | nfile = os.path.join(dir,file)
|
---|
10 | if nfile.find(".svn") == -1:
|
---|
11 | if os.path.isdir(nfile):
|
---|
12 | self.walk(nfile,meth)
|
---|
13 | else:
|
---|
14 | meth(nfile)
|
---|
15 |
|
---|
16 | def addShadowFlags(fileName):
|
---|
17 | if fileName.find("xml") != -1:
|
---|
18 | file = open(fileName, "r")
|
---|
19 | text = file.read()
|
---|
20 | file.close()
|
---|
21 |
|
---|
22 | text = text.replace("<castshadow/>\n","")
|
---|
23 | text = text.replace("</actor>"," <castshadow/>\n <receiveshadow/>\n\n</actor>")
|
---|
24 | #print text
|
---|
25 |
|
---|
26 | file = open(fileName, "w")
|
---|
27 | file.write(text)
|
---|
28 | file.close()
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | DirWalker().walk(".", addShadowFlags)
|
---|
33 | #addShadowFlags("units/hellenes/siege_spear_packed.xml")
|
---|