Skip to content

Commit

Permalink
add filtering by task name and task type
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitConnan authored and ClementHector committed Feb 8, 2022
1 parent 9d346a2 commit b09c00a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
80 changes: 49 additions & 31 deletions openpype/lib/abstract_load_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def __init__(self, placeholder_class):
self.loaders_by_name = get_loaders_by_name()
self.current_asset = avalon.io.Session["AVALON_ASSET"]
self.placeholder_class = placeholder_class
self.current_asset_docs = avalon.io.find_one({
"type": "asset",
"name": self.current_asset
})

# Skip if there is no loader
if not self.loaders_by_name:
Expand Down Expand Up @@ -57,22 +61,32 @@ def template_path(self):
in avalon context
IOError: Solved path does not exists on current filesystem
"""
project = avalon.io.Session["AVALON_PROJECT"]
anatomy = Anatomy(project)
project_settings = get_project_settings(project)
current_dcc = avalon.io.Session["AVALON_APP"]
current_task = avalon.io.Session["AVALON_TASK"]
build_info = project_settings[current_dcc]['templated_workfile_build']
project_name = avalon.io.Session["AVALON_PROJECT"]
anatomy = Anatomy(project_name)
project_settings = get_project_settings(project_name)
host_name = avalon.io.Session["AVALON_APP"]
task_name = avalon.io.Session["AVALON_TASK"]
task_type = (
self.current_asset_docs
.get("data", {})
.get("tasks", {})
.get(task_name, {})
.get("type")
)
build_info = project_settings[host_name]['templated_workfile_build']
profiles = build_info['profiles']

for profile in profiles:
if current_task in profile['task_types']:
path = profile['path']
break
for prf in profiles:
if prf['task_types'] and task_type not in prf['task_types']:
continue
if prf['task_names'] and task_name not in prf['task_names']:
continue
path = prf['path']
break
else:
raise ValueError(
"No matching profile found for task '{}' in DCC '{}'".format(
current_task, current_dcc)
"No matching profile found for task '{}' of type '{}' "
"with host '{}'".format(task_name, task_type, host_name)
)

try:
Expand All @@ -89,9 +103,9 @@ def template_path(self):

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

def populate_template(self):
Expand All @@ -106,24 +120,16 @@ def populate_template(self):
Returns:
None
"""
placeholder_class = self.placeholder_class
loaders_by_name = self.loaders_by_name
current_asset = self.current_asset
current_asset_entity = avalon.io.find_one({
"type": "asset",
"name": current_asset
})
current_asset_docs = self.current_asset_docs

linked_asset_entities = get_linked_assets(current_asset_entity)
assets_to_load = {asset['name'] for asset in linked_asset_entities}
linked_asset_docs = get_linked_assets(current_asset_docs)
assets_to_load = {asset['name'] for asset in linked_asset_docs}
version_repres = collect_last_version_repres(
[current_asset_entity] + linked_asset_entities)
[current_asset_docs] + linked_asset_docs)

representations_by_id = {
representation['_id']: representation
for asset in version_repres.values()
for subset in asset['subsets'].values()
for representation in subset['version']['repres']}
representations_by_id = self.get_representations_by_id(version_repres)

context_representations_by_id = dict()
linked_representations_by_id = dict()
Expand All @@ -134,10 +140,7 @@ def populate_template(self):
else:
linked_representations_by_id[k] = representations_by_id[k]

placeholders = map(placeholder_class, self.get_template_nodes())
valid_placeholders = filter(placeholder_class.is_valid, placeholders)
sorted_placeholders = sorted(valid_placeholders,
key=placeholder_class.order)
sorted_placeholders = self.get_sorted_placeholders()

loaded_assets = set()
for placeholder in sorted_placeholders:
Expand All @@ -164,6 +167,21 @@ def populate_template(self):
print("or that the build template is malformed, "
"continue at your own risks.")

def get_sorted_placeholders(self):
placeholder_class = self.placeholder_class
placeholders = map(placeholder_class, self.get_template_nodes())
valid_placeholders = filter(placeholder_class.is_valid, placeholders)
sorted_placeholders = sorted(valid_placeholders,
key=placeholder_class.order)
return sorted_placeholders

def get_representations_by_id(self, version_representations):
return {
representation['_id']: representation
for asset in version_representations.values()
for subset in asset['subsets'].values()
for representation in subset['version']['repres']}

@abstractmethod
def import_template(self, template_path):
"""
Expand Down
1 change: 1 addition & 0 deletions openpype/settings/defaults/project_settings/maya.json
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@
"profiles": [
{
"task_types": [],
"task_names": [],
"path": "path\\to\\template"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
"label": "Task types",
"type": "task-types-enum"
},
{
"key": "task_names",
"label": "Task names",
"type": "list",
"object_type": "text"
},
{
"key": "path",
"label": "Path to template",
Expand All @@ -25,4 +31,4 @@
}
}
]
}
}

0 comments on commit b09c00a

Please sign in to comment.