pull/76/head
meisnate12 4 years ago
parent 861df0a97e
commit 92d5e29a91

@ -54,10 +54,7 @@ class CollectionBuilder:
if template["default"]: if template["default"]:
if isinstance(template["default"], dict): if isinstance(template["default"], dict):
for dv in template["default"]: for dv in template["default"]:
if template["default"][dv]: default[dv] = template["default"][dv]
default[dv] = template["default"][dv]
else:
raise Failed(f"Collection Error: template default sub-attribute {dv} is blank")
else: else:
raise Failed("Collection Error: template sub-attribute default is not a dictionary") raise Failed("Collection Error: template sub-attribute default is not a dictionary")
else: else:
@ -75,34 +72,39 @@ class CollectionBuilder:
txt = txt.replace("<<collection_name>>", str(self.name)) txt = txt.replace("<<collection_name>>", str(self.name))
for dm in default: for dm in default:
if f"<<{dm}>>" in txt: if f"<<{dm}>>" in txt:
if default[dm] is None:
raise Failed(f"template default {dm} is blank")
txt = txt.replace(f"<<{dm}>>", str(default[dm])) txt = txt.replace(f"<<{dm}>>", str(default[dm]))
if txt in ["true", "True"]: return True if txt in ["true", "True"]: return True
elif txt in ["false", "False"]: return False elif txt in ["false", "False"]: return False
else: else:
try: return int(txt) try: return int(txt)
except ValueError: return txt except ValueError: return txt
if isinstance(template[m], dict): try:
attr = {} if isinstance(template[m], dict):
for sm in template[m]: attr = {}
if isinstance(template[m][sm], list): for sm in template[m]:
temp_list = [] if isinstance(template[m][sm], list):
for li in template[m][sm]: temp_list = []
temp_list.append(replace_txt(li)) for li in template[m][sm]:
attr[sm] = temp_list temp_list.append(replace_txt(li))
else: attr[sm] = temp_list
attr[sm] = replace_txt(template[m][sm]) else:
elif isinstance(template[m], list): attr[sm] = replace_txt(template[m][sm])
attr = [] elif isinstance(template[m], list):
for li in template[m]: attr = []
if isinstance(li, dict): for li in template[m]:
temp_dict = {} if isinstance(li, dict):
for sm in li: temp_dict = {}
temp_dict[sm] = replace_txt(li[sm]) for sm in li:
attr.append(temp_dict) temp_dict[sm] = replace_txt(li[sm])
else: attr.append(temp_dict)
attr.append(replace_txt(li)) else:
else: attr.append(replace_txt(li))
attr = replace_txt(template[m]) else:
attr = replace_txt(template[m])
except Failed:
continue
self.data[m] = attr self.data[m] = attr
else: else:
raise Failed(f"Collection Error: template attribute {m} is blank") raise Failed(f"Collection Error: template attribute {m} is blank")

Loading…
Cancel
Save