Added functionality to read include statements on the go
This commit is contained in:
parent
25fa68ca2e
commit
47a6e6b292
|
@ -3,6 +3,7 @@
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class Section():
|
class Section():
|
||||||
def __init__(self,data = {'__order__':[]},part = ''):
|
def __init__(self,data = {'__order__':[]},part = ''):
|
||||||
classes = {
|
classes = {
|
||||||
|
@ -173,24 +174,59 @@ class Material():
|
||||||
else: # plain key
|
else: # plain key
|
||||||
self.data[part][name_section][items[0]] = items[1:]
|
self.data[part][name_section][items[0]] = items[1:]
|
||||||
|
|
||||||
def read(self,file=None):
|
c = []
|
||||||
fileNames = [None] * 10
|
def myRead(c,sub_file):
|
||||||
fileNames[0] = file
|
|
||||||
re_include = re.compile(r'^{(.+)}$') # pattern for include
|
re_include = re.compile(r'^{(.+)}$') # pattern for include
|
||||||
c = []
|
with open(sub_file,'r') as f:
|
||||||
with open(file,'r') as f:
|
|
||||||
for entry in f:
|
for entry in f:
|
||||||
if not entry.strip(): continue
|
if not entry.strip():
|
||||||
|
continue
|
||||||
match = re_include.match(entry.split()[0])
|
match = re_include.match(entry.split()[0])
|
||||||
if match:
|
if match:
|
||||||
if match.group(1).startswith('/'):
|
if match.group(1).startswith('/'):
|
||||||
sub_file = match.group(1)
|
sub_file = match.group(1)
|
||||||
else:
|
else:
|
||||||
sub_file = os.path.normpath(os.path.dirname(file).join(match.group(1)))
|
sub_file = os.path.normpath(os.path.dirname(sub_file).join(match.group(1)))
|
||||||
with open(sub_file,'r') as f1: #using the target_path to open the file
|
with open(sub_file,'r') as f1:
|
||||||
for l in f1.readlines(): c.append(l)
|
for l in f1.readlines():
|
||||||
|
if l not in c:
|
||||||
|
c.append(l)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
myRead(c,sub_file)
|
||||||
else:
|
else:
|
||||||
c.append(entry)
|
if entry not in c:
|
||||||
|
c.append(entry)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
return c,sub_file
|
||||||
|
|
||||||
|
def read(self,file=None):
|
||||||
|
fileNames = [None] * 10
|
||||||
|
fileNames[0] = file
|
||||||
|
re_include = re.compile(r'^{(.+)}$') # pattern for include
|
||||||
|
c = []
|
||||||
|
i = 0
|
||||||
|
for files in fileNames:
|
||||||
|
if files is not None:
|
||||||
|
with open(file,'r') as f:
|
||||||
|
for entry in f:
|
||||||
|
if not entry.strip():
|
||||||
|
continue
|
||||||
|
match = re_include.match(entry.split()[0])
|
||||||
|
if match:
|
||||||
|
if match.group(1).startswith('/'):
|
||||||
|
sub_file = match.group(1)
|
||||||
|
else:
|
||||||
|
sub_file = os.path.normpath(os.path.dirname(file).join(match.group(1)))
|
||||||
|
i = i + 1
|
||||||
|
fileNames[i] = sub_file
|
||||||
|
myRead(c,sub_file)
|
||||||
|
else:
|
||||||
|
if entry not in c:
|
||||||
|
c.append(entry)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
for l in c:
|
for l in c:
|
||||||
print(l)
|
print(l)
|
||||||
|
|
Loading…
Reference in New Issue