diff --git a/openpype/hosts/maya/api/template_loader.py b/openpype/hosts/maya/api/template_loader.py index 37f424ad73a..7cb6f5bd20b 100644 --- a/openpype/hosts/maya/api/template_loader.py +++ b/openpype/hosts/maya/api/template_loader.py @@ -1,11 +1,10 @@ -from openpype.lib.abstract_load_template import AbstractTemplateLoader,\ - AbstractPlaceholder +import openpype.lib from maya import cmds PLACEHOLDER_SET = 'PLACEHOLDERS_SET' -class TemplateLoader(AbstractTemplateLoader): +class MayaTemplateLoader(openpype.lib.AbstractTemplateLoader): """Concrete implementation of AbstractTemplateLoader for maya """ @@ -34,7 +33,7 @@ def get_template_nodes(): return [attribute.rpartition('.')[0] for attribute in attributes] -class Placeholder(AbstractPlaceholder): +class MayaPlaceholder(openpype.lib.AbstractPlaceholder): """Concrete implementation of AbstractPlaceholder for maya """ diff --git a/openpype/lib/__init__.py b/openpype/lib/__init__.py index 9a1600dfb3e..f45ce3d816b 100644 --- a/openpype/lib/__init__.py +++ b/openpype/lib/__init__.py @@ -181,6 +181,11 @@ is_current_version_higher_than_expected ) +from .abstract_template_loader import ( + AbstractPlaceholder, + AbstractTemplateLoader +) + terminal = Terminal __all__ = [ @@ -317,4 +322,7 @@ "is_running_from_build", "is_running_staging", "is_current_version_studio_latest", + + "AbstractPlaceholder", + "AbstractTemplateLoader" ] diff --git a/openpype/lib/abstract_load_template.py b/openpype/lib/abstract_template_loader.py similarity index 100% rename from openpype/lib/abstract_load_template.py rename to openpype/lib/abstract_template_loader.py diff --git a/openpype/lib/build_template.py b/openpype/lib/build_template.py index 1a1526d17aa..86e65682179 100644 --- a/openpype/lib/build_template.py +++ b/openpype/lib/build_template.py @@ -1,29 +1,43 @@ -import avalon +import openpype +from openpype.lib import AbstractPlaceholder, AbstractTemplateLoader + import importlib -concrete_loaders_modules = { - 'maya': 'openpype.hosts.maya.api.template_loader' -} +module_path_format = 'openpype.hosts.{host}.api.template_loader' def build_workfile_template(self): - host_name = avalon.io.Session['AVALON_APP'] - module_path = concrete_loaders_modules.get(host_name, None) + host_name = openpype.avalon.registered_host().__name__.partition('.')[2] + module_path = module_path_format.format(host=host_name) + module = importlib.import_module(module_path) + if not module: + raise MissingHostTemplateModule( + "No template loader found for host {}".format(host_name)) - if not module_path: - raise NotImplementedError( - "Template not found for host '{}'".format(host_name) - ) + template_loader_class = openpype.lib.classes_from_module( + AbstractTemplateLoader, module) + template_placeholder_class = openpype.lib.classes_from_module( + AbstractPlaceholder, module) - module = importlib.import_module(module_path) - if not hasattr(module, 'TemplateLoader'): - raise NotImplementedError( - "Linked module '{}' does not " - "implement a template loader".format(module_path)) - if not hasattr(module, 'Placeholder'): - raise NotImplementedError( - "Linked module '{}' does not " - "implement a placeholder template".format(module_path)) - concrete_loader = module.TemplateLoader - concrete_template_loader = concrete_loader(module.Placeholder) - concrete_template_loader.process() + if not template_loader_class: + raise MissingTemplateLoaderClass() + template_loader_class = template_loader_class[0] + + if not template_placeholder_class: + raise MissingTemplatePlaceholderClass() + template_placeholder_class = template_placeholder_class[0] + + template_loader = template_loader_class(template_placeholder_class) + template_loader.process() + +class MissingHostTemplateModule(Exception): + """Error raised when expected module does not exists""" + pass + +class MissingTemplatePlaceholderClass(Exception): + """ """ + pass + +class MissingTemplateLoaderClass(Exception): + """ """ + pass \ No newline at end of file