Skip to content

Commit

Permalink
Make lmauncher and workfiles interfaces use master_task info
Browse files Browse the repository at this point in the history
  • Loading branch information
jlorrain authored and ClementHector committed Feb 7, 2022
1 parent 6f79251 commit 592c97e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions openpype/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
get_workdir_data,
get_workdir,
get_workdir_with_workdir_data,
get_master_task,

create_workfile_doc,
save_workfile_data_to_doc,
Expand Down Expand Up @@ -228,6 +229,7 @@
"get_workdir_data",
"get_workdir",
"get_workdir_with_workdir_data",
"get_master_task",

"create_workfile_doc",
"save_workfile_data_to_doc",
Expand Down
42 changes: 42 additions & 0 deletions openpype/lib/avalon_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,44 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None):
return version_doc


# @with_avalon
def get_master_task(asset_doc, task_name, dbcon=None):
"""Retrieve master_task from avalon asset requested task
Return the master task if there is one, return the task otherwise.
Args:
asset_id (int): Id of asset under which the task belongs.
task_name (str): Name of task to retrieve master_task from.
dbcon (avalon.mongodb.AvalonMongoDB, optional): Avalon Mongo connection
with Session.
Returns:
str: master task name if there is one, task name otherwise.
"""

# if not dbcon:
# log.debug("Using `avalon.io` for query.")
# dbcon = avalon.io
# # Make sure is installed
# dbcon.install()
#
# asset_doc = avalon.io.find_one(
# {"type": "asset", "_id": asset_id},
# {"data": True}
# )

if asset_doc:
master_task = (
asset_doc.get("data", {})
.get("tasks", {})
.get(task_name, {})
.get("master_task", None)
)
if master_task:
return master_task
return task_name


def get_workfile_template_key_from_context(
asset_name, task_name, host_name, project_name=None,
dbcon=None, project_settings=None
Expand Down Expand Up @@ -520,6 +558,10 @@ def get_workdir_data(project_doc, asset_doc, task_name, host_name):
if asset_parents:
parent_name = asset_parents[-1]

master_task = get_master_task(asset_doc, task_name)
if master_task:
task_name = master_task

data = {
"project": {
"name": project_doc["name"],
Expand Down
9 changes: 8 additions & 1 deletion openpype/tools/workfiles/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from openpype.tools.utils.delegates import PrettyTimeDelegate
from openpype.lib import (
Anatomy,
get_master_task,
get_workdir,
get_workfile_doc,
create_workfile_doc,
Expand Down Expand Up @@ -459,7 +460,11 @@ def set_asset_task(self, asset_id, task_name, task_type):
if asset_id != self._asset_id:
self._asset_doc = None
self._asset_id = asset_id
self._task_name = task_name
asset_doc = io.find_one(
{"type": "asset", "_id": asset_id},
{"data": True}
)
self._task_name = get_master_task(asset_doc, task_name)
self._task_type = task_type

# Define a custom session so we can query the work root
Expand All @@ -482,6 +487,8 @@ def set_asset_task(self, asset_id, task_name, task_type):
# Manually trigger file selection
self.on_file_select()

self._task_name = task_name

def _get_asset_doc(self):
if self._asset_id is None:
return None
Expand Down

0 comments on commit 592c97e

Please sign in to comment.