Merge remote-tracking branch 'origin/feature/publisher_common_cache_function' into feature/OP-3909_Make-New-Publisher-default-in-AfterEffects

This commit is contained in:
Petr Kalis 2022-11-03 10:31:29 +01:00
commit 313180d617
8 changed files with 96 additions and 65 deletions

View file

@ -1532,7 +1532,7 @@ def get_container_members(container):
if ref.rsplit(":", 1)[-1].startswith("_UNKNOWN_REF_NODE_"):
continue
reference_members = cmds.referenceQuery(ref, nodes=True)
reference_members = cmds.referenceQuery(ref, nodes=True, dagPath=True)
reference_members = cmds.ls(reference_members,
long=True,
objectsOnly=True)

View file

@ -1,49 +1,32 @@
from openpype.lib.attribute_definitions import FileDef
from openpype.lib.transcoding import IMAGE_EXTENSIONS, VIDEO_EXTENSIONS
from openpype.pipeline.create import (
Creator,
HiddenCreator,
CreatedInstance
CreatedInstance,
cache_and_get_instances,
)
from .pipeline import (
list_instances,
update_instances,
remove_instances,
HostContext,
)
from openpype.lib.transcoding import IMAGE_EXTENSIONS, VIDEO_EXTENSIONS
REVIEW_EXTENSIONS = IMAGE_EXTENSIONS + VIDEO_EXTENSIONS
def _cache_and_get_instances(creator):
"""Cache instances in shared data.
Args:
creator (Creator): Plugin which would like to get instances from host.
Returns:
List[Dict[str, Any]]: Cached instances list from host implementation.
"""
shared_key = "openpype.traypublisher.instances"
if shared_key not in creator.collection_shared_data:
creator.collection_shared_data[shared_key] = list_instances()
return creator.collection_shared_data[shared_key]
REVIEW_EXTENSIONS = set(IMAGE_EXTENSIONS) | set(VIDEO_EXTENSIONS)
SHARED_DATA_KEY = "openpype.traypublisher.instances"
class HiddenTrayPublishCreator(HiddenCreator):
host_name = "traypublisher"
def collect_instances(self):
for instance_data in _cache_and_get_instances(self):
creator_id = instance_data.get("creator_identifier")
if creator_id == self.identifier:
instance = CreatedInstance.from_existing(
instance_data, self
)
self._add_instance_to_context(instance)
instances_by_identifier = cache_and_get_instances(
self, SHARED_DATA_KEY, list_instances
)
for instance_data in instances_by_identifier[self.identifier]:
instance = CreatedInstance.from_existing(instance_data, self)
self._add_instance_to_context(instance)
def update_instances(self, update_list):
update_instances(update_list)
@ -74,13 +57,12 @@ class TrayPublishCreator(Creator):
host_name = "traypublisher"
def collect_instances(self):
for instance_data in _cache_and_get_instances(self):
creator_id = instance_data.get("creator_identifier")
if creator_id == self.identifier:
instance = CreatedInstance.from_existing(
instance_data, self
)
self._add_instance_to_context(instance)
instances_by_identifier = cache_and_get_instances(
self, SHARED_DATA_KEY, list_instances
)
for instance_data in instances_by_identifier[self.identifier]:
instance = CreatedInstance.from_existing(instance_data, self)
self._add_instance_to_context(instance)
def update_instances(self, update_list):
update_instances(update_list)

View file

@ -7,7 +7,12 @@ import json
import platform
import uuid
import re
from Deadline.Scripting import RepositoryUtils, FileUtils, DirectoryUtils
from Deadline.Scripting import (
RepositoryUtils,
FileUtils,
DirectoryUtils,
ProcessUtils,
)
def get_openpype_version_from_path(path, build=True):
@ -162,9 +167,8 @@ def inject_openpype_environment(deadlinePlugin):
print(">>> Temporary path: {}".format(export_url))
args = [
exe,
"--headless",
'extractenvironments',
"extractenvironments",
export_url
]
@ -188,15 +192,18 @@ def inject_openpype_environment(deadlinePlugin):
if not os.environ.get("OPENPYPE_MONGO"):
print(">>> Missing OPENPYPE_MONGO env var, process won't work")
env = os.environ
env["OPENPYPE_HEADLESS_MODE"] = "1"
env["AVALON_TIMEOUT"] = "5000"
os.environ["AVALON_TIMEOUT"] = "5000"
print(">>> Executing: {}".format(" ".join(args)))
std_output = subprocess.check_output(args,
cwd=os.path.dirname(exe),
env=env)
print(">>> Process result {}".format(std_output))
args_str = subprocess.list2cmdline(args)
print(">>> Executing: {} {}".format(exe, args_str))
process = ProcessUtils.SpawnProcess(
exe, args_str, os.path.dirname(exe)
)
ProcessUtils.WaitForExit(process, -1)
if process.ExitCode != 0:
raise RuntimeError(
"Failed to run OpenPype process to extract environments."
)
print(">>> Loading file ...")
with open(export_url) as fp:

View file

@ -24,6 +24,8 @@ from .creator_plugins import (
deregister_creator_plugin,
register_creator_plugin_path,
deregister_creator_plugin_path,
cache_and_get_instances,
)
from .context import (

View file

@ -1,5 +1,6 @@
import os
import copy
import collections
from abc import (
ABCMeta,
@ -660,3 +661,34 @@ def deregister_creator_plugin_path(path):
deregister_plugin_path(BaseCreator, path)
deregister_plugin_path(LegacyCreator, path)
deregister_plugin_path(SubsetConvertorPlugin, path)
def cache_and_get_instances(creator, shared_key, list_instances_func):
"""Common approach to cache instances in shared data.
This is helper function which does not handle cases when a 'shared_key' is
used for different list instances functions. The same approach of caching
instances into 'collection_shared_data' is not required but is so common
we've decided to unify it to some degree.
Function 'list_instances_func' is called only if 'shared_key' is not
available in 'collection_shared_data' on creator.
Args:
creator (Creator): Plugin which would like to get instance data.
shared_key (str): Key under which output of function will be stored.
list_instances_func (Function): Function that will return instance data
if data were not yet stored under 'shared_key'.
Returns:
Dict[str, Dict[str, Any]]: Cached instances by creator identifier from
result of passed function.
"""
if shared_key not in creator.collection_shared_data:
value = collections.defaultdict(list)
for instance in list_instances_func():
identifier = instance.get("creator_identifier")
value[identifier].append(instance)
creator.collection_shared_data[shared_key] = value
return creator.collection_shared_data[shared_key]

View file

@ -515,7 +515,7 @@ class SubsetWidget(QtWidgets.QWidget):
if not one_item_selected:
# Filter loaders from first subset by intersected combinations
for repre, loader in first_loaders:
if (repre["name"], loader) not in found_combinations:
if (repre["name"].lower(), loader) not in found_combinations:
continue
loaders.append((repre, loader))

View file

@ -225,6 +225,12 @@ class PublisherWindow(QtWidgets.QDialog):
# Floating publish frame
publish_frame = PublishFrame(controller, self.footer_border, self)
# Timer started on show -> connected to timer counter
# - helps to deffer on show logic by 3 event loops
show_timer = QtCore.QTimer()
show_timer.setInterval(1)
show_timer.timeout.connect(self._on_show_timer)
errors_dialog_message_timer = QtCore.QTimer()
errors_dialog_message_timer.setInterval(100)
errors_dialog_message_timer.timeout.connect(
@ -329,7 +335,6 @@ class PublisherWindow(QtWidgets.QDialog):
# forin init
self._reset_on_first_show = reset_on_show
self._reset_on_show = True
self._restart_timer = None
self._publish_frame_visible = None
self._error_messages_to_show = collections.deque()
@ -337,6 +342,9 @@ class PublisherWindow(QtWidgets.QDialog):
self._set_publish_visibility(False)
self._show_timer = show_timer
self._show_counter = 0
@property
def controller(self):
return self._controller
@ -347,17 +355,7 @@ class PublisherWindow(QtWidgets.QDialog):
self._first_show = False
self._on_first_show()
if not self._reset_on_show:
return
self._reset_on_show = False
# Detach showing - give OS chance to draw the window
timer = QtCore.QTimer()
timer.setSingleShot(True)
timer.setInterval(1)
timer.timeout.connect(self._on_show_restart_timer)
self._restart_timer = timer
timer.start()
self._show_timer.start()
def resizeEvent(self, event):
super(PublisherWindow, self).resizeEvent(event)
@ -374,11 +372,21 @@ class PublisherWindow(QtWidgets.QDialog):
self.setStyleSheet(style.load_stylesheet())
self._reset_on_show = self._reset_on_first_show
def _on_show_restart_timer(self):
"""Callback for '_restart_timer' timer."""
def _on_show_timer(self):
# Add 1 to counter until hits 2
if self._show_counter < 3:
self._show_counter += 1
return
self._restart_timer = None
self.reset()
# Stop the timer
self._show_timer.stop()
# Reset counter when done for next show event
self._show_counter = 0
# Reset if requested
if self._reset_on_show:
self._reset_on_show = False
self.reset()
def closeEvent(self, event):
self.save_changes()

View file

@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
"""Package declaring Pype version."""
__version__ = "3.14.7-nightly.1"
__version__ = "3.14.7-nightly.2"