Skip to content

Commit

Permalink
Switch Build Asset Template to abstract base class
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitConnan authored and ClementHector committed Feb 8, 2022
1 parent 69d04fc commit 6d6bfd0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion openpype/hosts/maya/api/template_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def import_template(self, path):
ValueError: "Build already generated"
"""
if cmds.objExists(PLACEHOLDER_SET):
raise ValueError("Build already generated. Please clean scene")
raise ValueError("Build already generated. Please clean scene if "
"you really want to rebuild. (File>New Scene)")
cmds.sets(name=PLACEHOLDER_SET, empty=True)
self.new_nodes = cmds.file(path, i=True, returnNewNodes=True)
cmds.setAttr(PLACEHOLDER_SET + '.hiddenInOutliner', True)
Expand Down
21 changes: 16 additions & 5 deletions openpype/lib/abstract_load_template.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import os
import re
import avalon
from abc import ABCMeta, abstractmethod

import six

from openpype.settings import get_project_settings
from openpype.lib import Anatomy, get_linked_assets, get_loaders_by_name,\
collect_last_version_repres


class AbstractTemplateLoader(object):
@six.add_metaclass(ABCMeta)
class AbstractTemplateLoader:
"""
Abstraction of Template Loader.
Expand Down Expand Up @@ -85,8 +90,8 @@ def template_path(self):

if not os.path.exists(solved_path):
raise IOError(
"Template found in openPype settings for task '{}' with DCC \
'{}' does not exists. (Not found : {})".format(
"Template found in openPype settings for task '{}' with DCC "
"'{}' does not exists. (Not found : {})".format(
current_task, current_dcc, solved_path))
return solved_path

Expand Down Expand Up @@ -158,6 +163,7 @@ def populate_template(self, current_asset,
print("or that the build template is malformed, "
"continue at your own risks.")

@abstractmethod
def import_template(self, template_path):
"""
Import template in current dcc
Expand All @@ -169,8 +175,9 @@ def import_template(self, template_path):
Return:
None
"""
raise NotImplementedError
pass

@abstractmethod
def get_template_nodes(self):
"""
Returning a list of nodes acting as DCC placeholders for
Expand All @@ -183,9 +190,10 @@ def get_template_nodes(self):
Returns:
list(AnyNode): Solved template path
"""
raise NotImplementedError
pass


@six.add_metaclass(ABCMeta)
class AbstractPlaceholder:
"""Abstraction of placeholders logic
Expand Down Expand Up @@ -215,6 +223,7 @@ class AbstractPlaceholder:
def __init__(self, node):
self.get_data(node)

@abstractmethod
def get_data(self, node):
"""
Collect placeholders information.
Expand Down Expand Up @@ -265,6 +274,7 @@ def is_valid(self):
"""
return set(self.attributes).issubset(self.data.keys())

@abstractmethod
def parent_in_hierarchy(self, containers):
"""Place container in correct hierarchy
given by placeholder
Expand All @@ -275,6 +285,7 @@ def parent_in_hierarchy(self, containers):
"""
raise NotImplementedError

@abstractmethod
def clean(self):
"""Clean placeholder from hierarchy after loading assets.
"""
Expand Down

0 comments on commit 6d6bfd0

Please sign in to comment.