parent
1eb82b99da
commit
cebdecfa70
|
@ -173,15 +173,17 @@ class Material():
|
||||||
|
|
||||||
|
|
||||||
def read(self,filename=None):
|
def read(self,filename=None):
|
||||||
|
"""Reads material.config file"""
|
||||||
def recursiveRead(filename):
|
def recursiveRead(filename):
|
||||||
|
"""Takes care of include statements like '{}'"""
|
||||||
result = []
|
result = []
|
||||||
re_include = re.compile(r'^{(.+)}$')
|
re_include = re.compile(r'^{(.+)}$')
|
||||||
with open(filename) as f: lines = f.readlines()
|
with open(filename) as f: lines = f.readlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
match = re_include.match(line.split()[0]) if line.strip() else False
|
match = re_include.match(line.split()[0]) if line.strip() else False
|
||||||
result += [line] if match else recursiveRead(match.group(1) if match.group(1).startswith('/') else
|
result += [line] if not match else \
|
||||||
os.path.normpath(os.path.join(os.path.dirname(filename),match.group(1))))
|
recursiveRead(match.group(1) if match.group(1).startswith('/') else
|
||||||
|
os.path.normpath(os.path.join(os.path.dirname(filename),match.group(1))))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
c = recursiveRead(filename)
|
c = recursiveRead(filename)
|
||||||
|
@ -189,6 +191,7 @@ class Material():
|
||||||
self.parse(part=p, content=c)
|
self.parse(part=p, content=c)
|
||||||
|
|
||||||
def write(self,filename='material.config', overwrite=False):
|
def write(self,filename='material.config', overwrite=False):
|
||||||
|
"""Writes to material.config"""
|
||||||
i = 0
|
i = 0
|
||||||
outname = filename
|
outname = filename
|
||||||
while os.path.exists(outname) and not overwrite:
|
while os.path.exists(outname) and not overwrite:
|
||||||
|
|
Loading…
Reference in New Issue