From c52c2a5de6a949f0847a775e90d68692951700e1 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 14 Jul 2022 15:37:10 -0400 Subject: [PATCH] [28] allow name in templates --- VERSION | 2 +- modules/builder.py | 32 +++++++++++++++----------------- modules/meta.py | 9 ++++++--- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/VERSION b/VERSION index a7bd648d..c85ac8ae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.1-develop27 +1.17.1-develop28 diff --git a/modules/builder.py b/modules/builder.py index 7139dbbd..e4cbfaa1 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -202,33 +202,31 @@ class CollectionBuilder: logger.separator(f"Validating {self.mapping_name} Attributes", space=False, border=False) - if "name" in methods: - name = self.data[methods["name"]] - elif f"{self.type}_name" in methods: + if f"{self.type}_name" in methods: logger.warning(f"Config Warning: Running {self.type}_name as name") - name = self.data[methods[f"{self.type}_name"]] - else: - 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) + self.data["name"] = self.data[methods[f"{self.type}_name"]] + methods["name"] = "name" if "template" in methods: logger.debug("") 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: if attr.lower() not in methods: self.data[attr] = new_attributes[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: logger.debug("") logger.debug("Validating Method: allowed_library_types") diff --git a/modules/meta.py b/modules/meta.py index 46a52a98..c41e756c 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -103,7 +103,7 @@ class DataFile: raise Failed(f"File Error: File does not exist {os.path.abspath(file_path)}") 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: raise Failed(f"{self.data_type} Error: No templates found") elif not template_call: @@ -132,6 +132,11 @@ class DataFile: variables.pop(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" if name_var not in variables: 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_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(): if temp_value is None: