|
|
@ -74,14 +74,14 @@ class DataFile:
|
|
|
|
util.print_stacktrace()
|
|
|
|
util.print_stacktrace()
|
|
|
|
raise Failed(f"YAML Error: {e}")
|
|
|
|
raise Failed(f"YAML Error: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
def apply_template(self, name, data, template):
|
|
|
|
def apply_template(self, name, data, template_call):
|
|
|
|
if not self.templates:
|
|
|
|
if not self.templates:
|
|
|
|
raise Failed(f"{self.data_type} Error: No templates found")
|
|
|
|
raise Failed(f"{self.data_type} Error: No templates found")
|
|
|
|
elif not template:
|
|
|
|
elif not template_call:
|
|
|
|
raise Failed(f"{self.data_type} Error: template attribute is blank")
|
|
|
|
raise Failed(f"{self.data_type} Error: template attribute is blank")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
logger.debug(f"Value: {template}")
|
|
|
|
logger.debug(f"Value: {template_call}")
|
|
|
|
for variables in util.get_list(template, split=False):
|
|
|
|
for variables in util.get_list(template_call, split=False):
|
|
|
|
if not isinstance(variables, dict):
|
|
|
|
if not isinstance(variables, dict):
|
|
|
|
raise Failed(f"{self.data_type} Error: template attribute is not a dictionary")
|
|
|
|
raise Failed(f"{self.data_type} Error: template attribute is not a dictionary")
|
|
|
|
elif "name" not in variables:
|
|
|
|
elif "name" not in variables:
|
|
|
@ -93,9 +93,10 @@ class DataFile:
|
|
|
|
elif not isinstance(self.templates[variables["name"]], dict):
|
|
|
|
elif not isinstance(self.templates[variables["name"]], dict):
|
|
|
|
raise Failed(f"{self.data_type} Error: template {variables['name']} is not a dictionary")
|
|
|
|
raise Failed(f"{self.data_type} Error: template {variables['name']} is not a dictionary")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
optional = []
|
|
|
|
for tm in variables:
|
|
|
|
for tm in variables:
|
|
|
|
if not variables[tm]:
|
|
|
|
if variables[tm] is None:
|
|
|
|
raise Failed(f"{self.data_type} Error: template sub-attribute {tm} is blank")
|
|
|
|
optional.append(str(tm))
|
|
|
|
if self.data_type == "Collection" and "collection_name" not in variables:
|
|
|
|
if self.data_type == "Collection" and "collection_name" not in variables:
|
|
|
|
variables["collection_name"] = str(name)
|
|
|
|
variables["collection_name"] = str(name)
|
|
|
|
if self.data_type == "Playlist" and "playlist_name" not in variables:
|
|
|
|
if self.data_type == "Playlist" and "playlist_name" not in variables:
|
|
|
@ -109,8 +110,14 @@ class DataFile:
|
|
|
|
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]:
|
|
|
|
if str(dv) not in optional:
|
|
|
|
default[dv] = template["default"][dv]
|
|
|
|
if template["default"][dv] is not None:
|
|
|
|
|
|
|
|
final_value = str(template["default"][dv])
|
|
|
|
|
|
|
|
if "<<collection_name>>" in final_value:
|
|
|
|
|
|
|
|
final_value = final_value.replace("<<collection_name>>", str(name))
|
|
|
|
|
|
|
|
if "<<playlist_name>>" in final_value:
|
|
|
|
|
|
|
|
final_value = final_value.replace("<<playlist_name>>", str(name))
|
|
|
|
|
|
|
|
default[dv] = final_value
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
raise Failed(f"{self.data_type} Error: template default sub-attribute {dv} is blank")
|
|
|
|
raise Failed(f"{self.data_type} Error: template default sub-attribute {dv} is blank")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -118,7 +125,6 @@ class DataFile:
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
raise Failed(f"{self.data_type} Error: template sub-attribute default is blank")
|
|
|
|
raise Failed(f"{self.data_type} Error: template sub-attribute default is blank")
|
|
|
|
|
|
|
|
|
|
|
|
optional = []
|
|
|
|
|
|
|
|
if "optional" in template:
|
|
|
|
if "optional" in template:
|
|
|
|
if template["optional"]:
|
|
|
|
if template["optional"]:
|
|
|
|
for op in util.get_list(template["optional"]):
|
|
|
|
for op in util.get_list(template["optional"]):
|
|
|
|