[28] allow name in templates

pull/968/head
meisnate12 2 years ago
parent d95e2b145c
commit c52c2a5de6

@ -1 +1 @@
1.17.1-develop27 1.17.1-develop28

@ -202,33 +202,31 @@ class CollectionBuilder:
logger.separator(f"Validating {self.mapping_name} Attributes", space=False, border=False) logger.separator(f"Validating {self.mapping_name} Attributes", space=False, border=False)
if "name" in methods: if f"{self.type}_name" in methods:
name = self.data[methods["name"]]
elif f"{self.type}_name" in methods:
logger.warning(f"Config Warning: Running {self.type}_name as name") logger.warning(f"Config Warning: Running {self.type}_name as name")
name = self.data[methods[f"{self.type}_name"]] self.data["name"] = self.data[methods[f"{self.type}_name"]]
else: methods["name"] = "name"
name = None
if name:
logger.debug("")
logger.debug("Validating Method: name")
if not name:
raise Failed(f"{self.Type} Error: name attribute is blank")
logger.debug(f"Value: {name}")
self.name = str(name)
else:
self.name = str(self.mapping_name)
if "template" in methods: if "template" in methods:
logger.debug("") logger.debug("")
logger.debug("Validating Method: template") logger.debug("Validating Method: template")
new_attributes = self.metadata.apply_template(self.name, self.data, self.data[methods["template"]]) name = self.data[methods["name"]] if "name" in methods else None
new_attributes = self.metadata.apply_template(name, self.mapping_name, self.data, self.data[methods["template"]])
for attr in new_attributes: for attr in new_attributes:
if attr.lower() not in methods: if attr.lower() not in methods:
self.data[attr] = new_attributes[attr] self.data[attr] = new_attributes[attr]
methods[attr.lower()] = attr methods[attr.lower()] = attr
if "name" in methods:
logger.debug("")
logger.debug("Validating Method: name")
if not self.data[methods["name"]]:
raise Failed(f"{self.Type} Error: name attribute is blank")
logger.debug(f"Value: {self.data[methods['name']]}")
self.name = str(self.data[methods["name"]])
else:
self.name = None
if "allowed_library_types" in methods and not self.playlist: if "allowed_library_types" in methods and not self.playlist:
logger.debug("") logger.debug("")
logger.debug("Validating Method: allowed_library_types") logger.debug("Validating Method: allowed_library_types")

@ -103,7 +103,7 @@ class DataFile:
raise Failed(f"File Error: File does not exist {os.path.abspath(file_path)}") raise Failed(f"File Error: File does not exist {os.path.abspath(file_path)}")
return yaml.data return yaml.data
def apply_template(self, name, data, template_call): def apply_template(self, name, mapping_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_call: elif not template_call:
@ -132,6 +132,11 @@ class DataFile:
variables.pop(remove_variable) variables.pop(remove_variable)
optional.append(str(remove_variable)) optional.append(str(remove_variable))
template, temp_vars = self.templates[variables["name"]]
if not name and "name" in template:
name = template["name"]
name_var = f"{self.data_type.lower()}_name" name_var = f"{self.data_type.lower()}_name"
if name_var not in variables: if name_var not in variables:
variables[name_var] = str(name) variables[name_var] = str(name)
@ -139,8 +144,6 @@ class DataFile:
variables["library_type"] = self.library.type.lower() if self.library else "items" variables["library_type"] = self.library.type.lower() if self.library else "items"
variables["library_name"] = self.library.name if self.library else "playlist" variables["library_name"] = self.library.name if self.library else "playlist"
template_name = variables["name"]
template, temp_vars = self.templates[template_name]
for temp_key, temp_value in temp_vars.items(): for temp_key, temp_value in temp_vars.items():
if temp_value is None: if temp_value is None:

Loading…
Cancel
Save