Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

[QUAD] Ftrack Task Status Update: Rework of the task status change + cleanup #6327

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openpype/hosts/houdini/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def on_file_event_callback(event):
emit_event("open")
elif event == hou.hipFileEventType.AfterSave:
emit_event("save")
emit_event("after.save")
elif event == hou.hipFileEventType.BeforeSave:
emit_event("before.save")
elif event == hou.hipFileEventType.AfterClear:
Expand Down
2 changes: 2 additions & 0 deletions openpype/hosts/nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2600,12 +2600,14 @@ def make_format_string(self, **kwargs):
)

def set_context_settings(self):
os.environ["OP_NUKE_SKIP_SAVE_EVENT"] = "True"
# replace reset resolution from avalon core to pype's
self.reset_resolution()
# replace reset resolution from avalon core to pype's
self.reset_frame_range_handles()
# add colorspace menu item
self.set_colorspace()
del os.environ["OP_NUKE_SKIP_SAVE_EVENT"]

def set_favorites(self):
from .utils import set_context_favorites
Expand Down
18 changes: 16 additions & 2 deletions openpype/hosts/nuke/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
IPublishHost
)
from openpype.settings import get_current_project_settings
from openpype.lib import register_event_callback, Logger
from openpype.lib import register_event_callback, emit_event, Logger
from openpype.pipeline import (
register_loader_plugin_path,
register_creator_plugin_path,
Expand All @@ -32,7 +32,6 @@
ROOT_DATA_KNOB,
INSTANCE_DATA_KNOB,
get_main_window,
add_publish_knob,
WorkfileSettings,
# TODO: remove this once workfile builder will be removed
process_workfile_builder,
Expand Down Expand Up @@ -178,6 +177,10 @@ def add_nuke_callbacks():
# set apply all workfile settings on script load and save
nuke.addOnScriptLoad(WorkfileSettings().set_context_settings)

# Emit events
nuke.addOnCreate(_on_scene_open, nodeClass="Root")
nuke.addOnScriptSave(_on_scene_save)


if nuke_settings["nuke-dirmap"]["enabled"]:
log.info("Added Nuke's dir-mapping callback ...")
Expand Down Expand Up @@ -636,3 +639,14 @@ def select_instance(instance):
"""
instance_node = instance.transient_data["node"]
instance_node["selected"].setValue(True)


def _on_scene_open(*args):
emit_event("open")


def _on_scene_save(*args):
skip = os.getenv("OP_NUKE_SKIP_SAVE_EVENT")
if skip:
return
emit_event("after.save")
136 changes: 135 additions & 1 deletion openpype/modules/ftrack/ftrack_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
import collections
import platform

from openpype.lib import register_event_callback
from openpype.modules import (
click_wrap,
OpenPypeModule,
ITrayModule,
IPluginPaths,
ISettingsChangeListener
)
from openpype.settings import SaveWarningExc
from openpype.settings import SaveWarningExc, get_project_settings
from openpype.lib import Logger

from openpype.pipeline import (
get_current_project_name,
get_current_asset_name,
get_current_task_name
)

FTRACK_MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
_URL_NOT_SET = object()

Expand Down Expand Up @@ -62,6 +69,133 @@ def initialize(self, settings):
self.timers_manager_connector = None
self._timers_manager_module = None

# Hooks when a file has been opened or saved
register_event_callback("open", self.after_file_open)
register_event_callback("after.save", self.after_file_save)

def find_ftrack_task_entity(
self, session, project_name, asset_name, task_name
):
project_entity = session.query(
"Project where full_name is \"{}\"".format(project_name)
).first()
if not project_entity:
self.log.warning(
"Couldn't find project \"{}\" in Ftrack.".format(project_name)
)
return

potential_task_entities = session.query((
"TypedContext where parent.name is \"{}\" and project_id is \"{}\""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for hanging indent
line too long (119 > 79 characters)

).format(asset_name, project_entity["id"])).all()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for hanging indent
line too long (97 > 79 characters)

filtered_entities = []
for _entity in potential_task_entities:
if (
_entity.entity_type.lower() == "task"
and _entity["name"] == task_name
):
filtered_entities.append(_entity)

if not filtered_entities:
self.log.warning((
"Couldn't find task \"{}\" under parent \"{}\" in Ftrack."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for hanging indent
line too long (91 > 79 characters)

).format(task_name, asset_name))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for hanging indent

return

if len(filtered_entities) > 1:
self.log.warning((
"Found more than one task \"{}\""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for hanging indent

" under parent \"{}\" in Ftrack."
).format(task_name, asset_name))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for hanging indent

return

return filtered_entities[0]

def after_file_open(self, event):
self._auto_update_task_status("status_change_on_file_open")

def after_file_save(self, event):
self._auto_update_task_status("status_change_on_file_save")

def _auto_update_task_status(self, setting_mapping_section):
# Create ftrack session
try:
session = self.create_ftrack_session()
except Exception: # noqa
self.log.warning("Couldn't create ftrack session.", exc_info=True)
return
# ----------------------

project_name = get_current_project_name()
project_settings = get_project_settings(project_name)

# Do we want/need/can update the status?
change_task_status = project_settings["ftrack"]["application_handlers"]["change_task_status"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (101 > 79 characters)

if not change_task_status["enabled"]:
return

mapping = change_task_status[setting_mapping_section]
if not mapping:
# No rules registered, skip.
return
# --------------------------------------

asset_name = get_current_asset_name()
task_name = get_current_task_name()

# Find the entity
entity = self.find_ftrack_task_entity(session, project_name, asset_name, task_name)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 79 characters)

if not entity:
# No valid entity found, quit.
return
# ---------------

ent_path = "/".join([ent["name"] for ent in entity["link"]])
actual_status = entity["status"]["name"]

# Find the next status
if "__ignore__" in mapping:
ignored_statuses = [status for status in mapping["__ignore__"]]
if actual_status in ignored_statuses:
# We can exit, the status is flagged to be ignored.
return

# Removing to avoid looping on it
mapping.pop("__ignore__")

next_status = None

for to_status, from_statuses in mapping.items():
from_statuses = [status for status in from_statuses]
if "__any__" in from_statuses:
next_status = to_status
# Not breaking, in case a better mapping is set after.
continue

if actual_status in from_statuses:
next_status = to_status
# We found a valid mapping (other that __any__) we stop looking.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

break

if not next_status:
# No valid next status found, skip.
return
# --------------------

# Change the status on ftrack
try:
query = "Status where name is \"{}\"".format(next_status)
next_status_obj = session.query(query).one()

entity["status"] = next_status_obj
session.commit()
self.log.debug("Changing current task status to \"{}\" <{}>".format(next_status, ent_path))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (103 > 79 characters)

except Exception: # noqa
session.rollback()
msg = "Status \"{}\" in presets wasn't found on Ftrack entity type \"{}\"".format(next_status,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (106 > 79 characters)

entity.entity_type)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (113 > 79 characters)

self.log.error(msg)

def get_ftrack_url(self):
"""Resolved ftrack url.

Expand Down
165 changes: 0 additions & 165 deletions openpype/modules/ftrack/launch_hooks/post_ftrack_changes.py

This file was deleted.

Loading
Loading