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

Commit

Permalink
Merge pull request #3527 from pypeclub/feature/OP-3593_Move-load-func…
Browse files Browse the repository at this point in the history
…tions-into-pipeline

General: Move load related functions into pipeline
  • Loading branch information
iLLiCiTiT authored Jul 25, 2022
2 parents bc1f394 + e8bfbf4 commit cfc11bb
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 114 deletions.
4 changes: 4 additions & 0 deletions openpype/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
get_last_version_by_subset_name,
get_output_link_versions,

version_is_latest,

get_representation_by_id,
get_representation_by_name,
get_representations,
Expand Down Expand Up @@ -66,6 +68,8 @@
"get_last_version_by_subset_name",
"get_output_link_versions",

"version_is_latest",

"get_representation_by_id",
"get_representation_by_name",
"get_representations",
Expand Down
36 changes: 36 additions & 0 deletions openpype/client/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,42 @@ def get_version_by_name(project_name, version, subset_id, fields=None):
return conn.find_one(query_filter, _prepare_fields(fields))


def version_is_latest(project_name, version_id):
"""Is version the latest from it's subset.
Note:
Hero versions are considered as latest.
Todo:
Maybe raise exception when version was not found?
Args:
project_name (str):Name of project where to look for queried entities.
version_id (Union[str, ObjectId]): Version id which is checked.
Returns:
bool: True if is latest version from subset else False.
"""

version_id = _convert_id(version_id)
if not version_id:
return False
version_doc = get_version_by_id(
project_name, version_id, fields=["_id", "type", "parent"]
)
# What to do when version is not found?
if not version_doc:
return False

if version_doc["type"] == "hero_version":
return True

last_version = get_last_version_by_subset_id(
project_name, version_doc["parent"], fields=["_id"]
)
return last_version["_id"] == version_id


def _get_versions(
project_name,
subset_ids=None,
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/aftereffects/api/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys

from Qt import QtWidgets

Expand All @@ -15,6 +14,7 @@
AVALON_CONTAINER_ID,
legacy_io,
)
from openpype.pipeline.load import any_outdated_containers
import openpype.hosts.aftereffects
from openpype.lib import register_event_callback

Expand Down Expand Up @@ -136,7 +136,7 @@ def ls():

def check_inventory():
"""Checks loaded containers if they are of highest version"""
if not lib.any_outdated():
if not any_outdated_containers():
return

# Warn about outdated containers.
Expand Down
15 changes: 2 additions & 13 deletions openpype/hosts/harmony/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

import pyblish.api

from openpype import lib
from openpype.client import get_representation_by_id
from openpype.lib import register_event_callback
from openpype.pipeline import (
legacy_io,
register_loader_plugin_path,
register_creator_plugin_path,
deregister_loader_plugin_path,
deregister_creator_plugin_path,
AVALON_CONTAINER_ID,
)
from openpype.pipeline.load import get_outdated_containers
from openpype.pipeline.context_tools import get_current_project_asset
import openpype.hosts.harmony
import openpype.hosts.harmony.api as harmony
Expand Down Expand Up @@ -108,16 +106,7 @@ def check_inventory():
in Harmony.
"""

project_name = legacy_io.active_project()
outdated_containers = []
for container in ls():
representation_id = container['representation']
representation_doc = get_representation_by_id(
project_name, representation_id, fields=["parent"]
)
if representation_doc and not lib.is_latest(representation_doc):
outdated_containers.append(container)

outdated_containers = get_outdated_containers()
if not outdated_containers:
return

Expand Down
9 changes: 3 additions & 6 deletions openpype/hosts/harmony/plugins/load/load_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
load,
get_representation_path,
)
from openpype.pipeline.context_tools import is_representation_from_latest
import openpype.hosts.harmony.api as harmony
import openpype.lib


copy_files = """function copyFile(srcFilename, dstFilename)
Expand Down Expand Up @@ -280,9 +280,7 @@ def load(self, context, name=None, namespace=None, data=None):
)

def update(self, container, representation):

path = get_representation_path(representation)

with open(path) as json_file:
data = json.load(json_file)

Expand All @@ -300,10 +298,9 @@ def update(self, container, representation):

bg_folder = os.path.dirname(path)

path = get_representation_path(representation)

print(container)

is_latest = is_representation_from_latest(representation)
for layer in sorted(layers):
file_to_import = [
os.path.join(bg_folder, layer).replace("\\", "/")
Expand Down Expand Up @@ -347,7 +344,7 @@ def update(self, container, representation):
}
%s
""" % (sig, sig)
if openpype.lib.is_latest(representation):
if is_latest:
harmony.send({"function": func, "args": [node, "green"]})
else:
harmony.send({"function": func, "args": [node, "red"]})
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/harmony/plugins/load/load_imagesequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
load,
get_representation_path,
)
from openpype.pipeline.context_tools import is_representation_from_latest
import openpype.hosts.harmony.api as harmony
import openpype.lib


class ImageSequenceLoader(load.LoaderPlugin):
Expand Down Expand Up @@ -109,7 +109,7 @@ def update(self, container, representation):
)

# Colour node.
if openpype.lib.is_latest(representation):
if is_representation_from_latest(representation):
harmony.send(
{
"function": "PypeHarmony.setColor",
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/harmony/plugins/load/load_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
load,
get_representation_path,
)
from openpype.pipeline.context_tools import is_representation_from_latest
import openpype.hosts.harmony.api as harmony
import openpype.lib


class TemplateLoader(load.LoaderPlugin):
Expand Down Expand Up @@ -83,7 +83,7 @@ def update(self, container, representation):
self_name = self.__class__.__name__

update_and_replace = False
if openpype.lib.is_latest(representation):
if is_representation_from_latest(representation):
self._set_green(node)
else:
self._set_red(node)
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/houdini/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
register_loader_plugin_path,
AVALON_CONTAINER_ID,
)
from openpype.pipeline.load import any_outdated_containers
import openpype.hosts.houdini
from openpype.hosts.houdini.api import lib

from openpype.lib import (
register_event_callback,
emit_event,
any_outdated,
)

from .lib import get_asset_fps
Expand Down Expand Up @@ -245,7 +245,7 @@ def on_open():
# ensure it is using correct FPS for the asset
lib.validate_fps()

if any_outdated():
if any_outdated_containers():
from openpype.widgets import popup

log.warning("Scene has outdated content.")
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/maya/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import openpype.hosts.maya
from openpype.tools.utils import host_tools
from openpype.lib import (
any_outdated,
register_event_callback,
emit_event
)
Expand All @@ -28,6 +27,7 @@
deregister_creator_plugin_path,
AVALON_CONTAINER_ID,
)
from openpype.pipeline.load import any_outdated_containers
from openpype.hosts.maya.lib import copy_workspace_mel
from . import menu, lib
from .workio import (
Expand Down Expand Up @@ -470,7 +470,7 @@ def on_open():
lib.validate_fps()
lib.fix_incompatible_containers()

if any_outdated():
if any_outdated_containers():
log.warning("Scene has outdated content.")

# Find maya main window
Expand Down
5 changes: 2 additions & 3 deletions openpype/hosts/photoshop/api/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from Qt import QtWidgets
from bson.objectid import ObjectId

import pyblish.api

Expand All @@ -13,8 +12,8 @@
deregister_loader_plugin_path,
deregister_creator_plugin_path,
AVALON_CONTAINER_ID,
registered_host,
)
from openpype.pipeline.load import any_outdated_containers
import openpype.hosts.photoshop

from . import lib
Expand All @@ -30,7 +29,7 @@


def check_inventory():
if not lib.any_outdated():
if not any_outdated_containers():
return

# Warn about outdated containers.
Expand Down
Loading

0 comments on commit cfc11bb

Please sign in to comment.