forked from ynput/OpenPype
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add abstract template loader to OP lib
Also add posibility to find template loader child class by heritance instead of by name
- Loading branch information
1 parent
8c65d01
commit 721701f
Showing
4 changed files
with
47 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |