mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
use validations from interfaces
This commit is contained in:
parent
0ff8e2bcc6
commit
b81dbf9ee4
4 changed files with 17 additions and 43 deletions
|
|
@ -6,6 +6,7 @@ import inspect
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
from openpype.host import INewPublisher
|
||||||
from openpype.pipeline import legacy_io
|
from openpype.pipeline import legacy_io
|
||||||
from openpype.pipeline.mongodb import (
|
from openpype.pipeline.mongodb import (
|
||||||
AvalonMongoDB,
|
AvalonMongoDB,
|
||||||
|
|
@ -651,12 +652,6 @@ class CreateContext:
|
||||||
discover_publish_plugins(bool): Discover publish plugins during reset
|
discover_publish_plugins(bool): Discover publish plugins during reset
|
||||||
phase.
|
phase.
|
||||||
"""
|
"""
|
||||||
# Methods required in host implementaion to be able create instances
|
|
||||||
# or change context data.
|
|
||||||
required_methods = (
|
|
||||||
"get_context_data",
|
|
||||||
"update_context_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, host, dbcon=None, headless=False, reset=True,
|
self, host, dbcon=None, headless=False, reset=True,
|
||||||
|
|
@ -738,10 +733,10 @@ class CreateContext:
|
||||||
Args:
|
Args:
|
||||||
host(ModuleType): Host implementaion.
|
host(ModuleType): Host implementaion.
|
||||||
"""
|
"""
|
||||||
missing = set()
|
|
||||||
for attr_name in cls.required_methods:
|
missing = set(
|
||||||
if not hasattr(host, attr_name):
|
INewPublisher.get_missing_publish_methods(host)
|
||||||
missing.add(attr_name)
|
)
|
||||||
return missing
|
return missing
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use singleton approach with global functions (using helper anyway).
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import pyblish.api
|
import pyblish.api
|
||||||
|
from openpype.host import IWorkfileHost, ILoadHost
|
||||||
from openpype.pipeline import (
|
from openpype.pipeline import (
|
||||||
registered_host,
|
registered_host,
|
||||||
legacy_io,
|
legacy_io,
|
||||||
|
|
@ -49,12 +49,11 @@ class HostToolsHelper:
|
||||||
def get_workfiles_tool(self, parent):
|
def get_workfiles_tool(self, parent):
|
||||||
"""Create, cache and return workfiles tool window."""
|
"""Create, cache and return workfiles tool window."""
|
||||||
if self._workfiles_tool is None:
|
if self._workfiles_tool is None:
|
||||||
from openpype.tools.workfiles.app import (
|
from openpype.tools.workfiles.app import Window
|
||||||
Window, validate_host_requirements
|
|
||||||
)
|
|
||||||
# Host validation
|
# Host validation
|
||||||
host = registered_host()
|
host = registered_host()
|
||||||
validate_host_requirements(host)
|
IWorkfileHost.validate_workfile_methods(host)
|
||||||
|
|
||||||
workfiles_window = Window(parent=parent)
|
workfiles_window = Window(parent=parent)
|
||||||
self._workfiles_tool = workfiles_window
|
self._workfiles_tool = workfiles_window
|
||||||
|
|
@ -92,6 +91,9 @@ class HostToolsHelper:
|
||||||
if self._loader_tool is None:
|
if self._loader_tool is None:
|
||||||
from openpype.tools.loader import LoaderWindow
|
from openpype.tools.loader import LoaderWindow
|
||||||
|
|
||||||
|
host = registered_host()
|
||||||
|
ILoadHost.validate_load_methods(host)
|
||||||
|
|
||||||
loader_window = LoaderWindow(parent=parent or self._parent)
|
loader_window = LoaderWindow(parent=parent or self._parent)
|
||||||
self._loader_tool = loader_window
|
self._loader_tool = loader_window
|
||||||
|
|
||||||
|
|
@ -164,6 +166,9 @@ class HostToolsHelper:
|
||||||
if self._scene_inventory_tool is None:
|
if self._scene_inventory_tool is None:
|
||||||
from openpype.tools.sceneinventory import SceneInventoryWindow
|
from openpype.tools.sceneinventory import SceneInventoryWindow
|
||||||
|
|
||||||
|
host = registered_host()
|
||||||
|
ILoadHost.validate_load_methods(host)
|
||||||
|
|
||||||
scene_inventory_window = SceneInventoryWindow(
|
scene_inventory_window = SceneInventoryWindow(
|
||||||
parent=parent or self._parent
|
parent=parent or self._parent
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
from .window import Window
|
from .window import Window
|
||||||
from .app import (
|
from .app import (
|
||||||
show,
|
show,
|
||||||
validate_host_requirements,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Window",
|
"Window",
|
||||||
|
|
||||||
"show",
|
"show",
|
||||||
"validate_host_requirements",
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from openpype.host import IWorkfileHost
|
||||||
from openpype.pipeline import (
|
from openpype.pipeline import (
|
||||||
registered_host,
|
registered_host,
|
||||||
legacy_io,
|
legacy_io,
|
||||||
|
|
@ -14,31 +15,6 @@ module = sys.modules[__name__]
|
||||||
module.window = None
|
module.window = None
|
||||||
|
|
||||||
|
|
||||||
def validate_host_requirements(host):
|
|
||||||
if host is None:
|
|
||||||
raise RuntimeError("No registered host.")
|
|
||||||
|
|
||||||
# Verify the host has implemented the api for Work Files
|
|
||||||
required = [
|
|
||||||
"open_file",
|
|
||||||
"save_file",
|
|
||||||
"current_file",
|
|
||||||
"has_unsaved_changes",
|
|
||||||
"work_root",
|
|
||||||
"file_extensions",
|
|
||||||
]
|
|
||||||
missing = []
|
|
||||||
for name in required:
|
|
||||||
if not hasattr(host, name):
|
|
||||||
missing.append(name)
|
|
||||||
if missing:
|
|
||||||
raise RuntimeError(
|
|
||||||
"Host is missing required Work Files interfaces: "
|
|
||||||
"%s (host: %s)" % (", ".join(missing), host)
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def show(root=None, debug=False, parent=None, use_context=True, save=True):
|
def show(root=None, debug=False, parent=None, use_context=True, save=True):
|
||||||
"""Show Work Files GUI"""
|
"""Show Work Files GUI"""
|
||||||
# todo: remove `root` argument to show()
|
# todo: remove `root` argument to show()
|
||||||
|
|
@ -50,7 +26,7 @@ def show(root=None, debug=False, parent=None, use_context=True, save=True):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
host = registered_host()
|
host = registered_host()
|
||||||
validate_host_requirements(host)
|
IWorkfileHost.validate_workfile_methods(host)
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
legacy_io.Session["AVALON_ASSET"] = "Mock"
|
legacy_io.Session["AVALON_ASSET"] = "Mock"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue