mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +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 contextlib import contextmanager
|
||||
|
||||
from openpype.host import INewPublisher
|
||||
from openpype.pipeline import legacy_io
|
||||
from openpype.pipeline.mongodb import (
|
||||
AvalonMongoDB,
|
||||
|
|
@ -651,12 +652,6 @@ class CreateContext:
|
|||
discover_publish_plugins(bool): Discover publish plugins during reset
|
||||
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__(
|
||||
self, host, dbcon=None, headless=False, reset=True,
|
||||
|
|
@ -738,10 +733,10 @@ class CreateContext:
|
|||
Args:
|
||||
host(ModuleType): Host implementaion.
|
||||
"""
|
||||
missing = set()
|
||||
for attr_name in cls.required_methods:
|
||||
if not hasattr(host, attr_name):
|
||||
missing.add(attr_name)
|
||||
|
||||
missing = set(
|
||||
INewPublisher.get_missing_publish_methods(host)
|
||||
)
|
||||
return missing
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use singleton approach with global functions (using helper anyway).
|
|||
import os
|
||||
|
||||
import pyblish.api
|
||||
|
||||
from openpype.host import IWorkfileHost, ILoadHost
|
||||
from openpype.pipeline import (
|
||||
registered_host,
|
||||
legacy_io,
|
||||
|
|
@ -49,12 +49,11 @@ class HostToolsHelper:
|
|||
def get_workfiles_tool(self, parent):
|
||||
"""Create, cache and return workfiles tool window."""
|
||||
if self._workfiles_tool is None:
|
||||
from openpype.tools.workfiles.app import (
|
||||
Window, validate_host_requirements
|
||||
)
|
||||
from openpype.tools.workfiles.app import Window
|
||||
|
||||
# Host validation
|
||||
host = registered_host()
|
||||
validate_host_requirements(host)
|
||||
IWorkfileHost.validate_workfile_methods(host)
|
||||
|
||||
workfiles_window = Window(parent=parent)
|
||||
self._workfiles_tool = workfiles_window
|
||||
|
|
@ -92,6 +91,9 @@ class HostToolsHelper:
|
|||
if self._loader_tool is None:
|
||||
from openpype.tools.loader import LoaderWindow
|
||||
|
||||
host = registered_host()
|
||||
ILoadHost.validate_load_methods(host)
|
||||
|
||||
loader_window = LoaderWindow(parent=parent or self._parent)
|
||||
self._loader_tool = loader_window
|
||||
|
||||
|
|
@ -164,6 +166,9 @@ class HostToolsHelper:
|
|||
if self._scene_inventory_tool is None:
|
||||
from openpype.tools.sceneinventory import SceneInventoryWindow
|
||||
|
||||
host = registered_host()
|
||||
ILoadHost.validate_load_methods(host)
|
||||
|
||||
scene_inventory_window = SceneInventoryWindow(
|
||||
parent=parent or self._parent
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
from .window import Window
|
||||
from .app import (
|
||||
show,
|
||||
validate_host_requirements,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Window",
|
||||
|
||||
"show",
|
||||
"validate_host_requirements",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import sys
|
||||
import logging
|
||||
|
||||
from openpype.host import IWorkfileHost
|
||||
from openpype.pipeline import (
|
||||
registered_host,
|
||||
legacy_io,
|
||||
|
|
@ -14,31 +15,6 @@ module = sys.modules[__name__]
|
|||
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):
|
||||
"""Show Work Files GUI"""
|
||||
# todo: remove `root` argument to show()
|
||||
|
|
@ -50,7 +26,7 @@ def show(root=None, debug=False, parent=None, use_context=True, save=True):
|
|||
pass
|
||||
|
||||
host = registered_host()
|
||||
validate_host_requirements(host)
|
||||
IWorkfileHost.validate_workfile_methods(host)
|
||||
|
||||
if debug:
|
||||
legacy_io.Session["AVALON_ASSET"] = "Mock"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue