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

General: Move workfiles functions into pipeline #3637

Merged
Merged
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
47 changes: 47 additions & 0 deletions openpype/client/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CURRENT_SUBSET_SCHEMA = "openpype:subset-3.0"
CURRENT_VERSION_SCHEMA = "openpype:version-3.0"
CURRENT_REPRESENTATION_SCHEMA = "openpype:representation-2.0"
CURRENT_WORKFILE_INFO_SCHEMA = "openpype:workfile-1.0"


def _create_or_convert_to_mongo_id(mongo_id):
Expand Down Expand Up @@ -188,6 +189,38 @@ def new_representation_doc(
}


def new_workfile_info_doc(
filename, asset_id, task_name, files, data=None, entity_id=None
):
"""Create skeleton data of workfile info document.

Workfile document is at this moment used primarily for artist notes.

Args:
filename (str): Filename of workfile.
asset_id (Union[str, ObjectId]): Id of asset under which workfile live.
task_name (str): Task under which was workfile created.
files (List[str]): List of rootless filepaths related to workfile.
data (Dict[str, Any]): Additional metadata.

Returns:
Dict[str, Any]: Skeleton of workfile info document.
"""

if not data:
data = {}

return {
"_id": _create_or_convert_to_mongo_id(entity_id),
"type": "workfile",
"parent": ObjectId(asset_id),
"task_name": task_name,
"filename": filename,
"data": data,
"files": files
}


def _prepare_update_data(old_doc, new_doc, replace):
changes = {}
for key, value in new_doc.items():
Expand Down Expand Up @@ -243,6 +276,20 @@ def prepare_representation_update_data(old_doc, new_doc, replace=True):
return _prepare_update_data(old_doc, new_doc, replace)


def prepare_workfile_info_update_data(old_doc, new_doc, replace=True):
"""Compare two workfile info documents and prepare update data.

Based on compared values will create update data for 'UpdateOperation'.

Empty output means that documents are identical.

Returns:
Dict[str, Any]: Changes between old and new document.
"""

return _prepare_update_data(old_doc, new_doc, replace)


@six.add_metaclass(ABCMeta)
class AbstractOperation(object):
"""Base operation class.
Expand Down
52 changes: 18 additions & 34 deletions openpype/hooks/pre_copy_template_workfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import shutil
from openpype.lib import (
PreLaunchHook,
get_custom_workfile_template_by_context,
from openpype.lib import PreLaunchHook
from openpype.settings import get_project_settings
from openpype.pipeline.workfile import (
get_custom_workfile_template,
get_custom_workfile_template_by_string_context
)
from openpype.settings import get_project_settings


class CopyTemplateWorkfile(PreLaunchHook):
Expand Down Expand Up @@ -54,52 +54,36 @@ def execute(self):
project_name = self.data["project_name"]
asset_name = self.data["asset_name"]
task_name = self.data["task_name"]
host_name = self.application.host_name

project_settings = get_project_settings(project_name)
host_settings = project_settings[self.application.host_name]

workfile_builder_settings = host_settings.get("workfile_builder")
if not workfile_builder_settings:
# TODO remove warning when deprecated
self.log.warning((
"Seems like old version of settings is used."
" Can't access custom templates in host \"{}\"."
).format(self.application.full_label))
return

if not workfile_builder_settings["create_first_version"]:
self.log.info((
"Project \"{}\" has turned off to create first workfile for"
" application \"{}\""
).format(project_name, self.application.full_label))
return

# Backwards compatibility
template_profiles = workfile_builder_settings.get("custom_templates")
if not template_profiles:
self.log.info(
"Custom templates are not filled. Skipping template copy."
)
return

project_doc = self.data.get("project_doc")
asset_doc = self.data.get("asset_doc")
anatomy = self.data.get("anatomy")
if project_doc and asset_doc:
self.log.debug("Started filtering of custom template paths.")
template_path = get_custom_workfile_template_by_context(
template_profiles, project_doc, asset_doc, task_name, anatomy
template_path = get_custom_workfile_template(
project_doc,
asset_doc,
task_name,
host_name,
anatomy,
project_settings
)

else:
self.log.warning((
"Global data collection probably did not execute."
" Using backup solution."
))
dbcon = self.data.get("dbcon")
template_path = get_custom_workfile_template_by_string_context(
template_profiles, project_name, asset_name, task_name,
dbcon, anatomy
project_name,
asset_name,
task_name,
host_name,
anatomy,
project_settings
)

if not template_path:
Expand Down
10 changes: 8 additions & 2 deletions openpype/hosts/flame/plugins/publish/integrate_batch_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from collections import OrderedDict
from pprint import pformat
import pyblish
from openpype.lib import get_workdir
import openpype.hosts.flame.api as opfapi
import openpype.pipeline as op_pipeline
from openpype.pipeline.workfile import get_workdir


class IntegrateBatchGroup(pyblish.api.InstancePlugin):
Expand Down Expand Up @@ -324,7 +324,13 @@ def _get_shot_task_dir_path(self, instance, task_data):
project_doc = instance.data["projectEntity"]
asset_entity = instance.data["assetEntity"]
anatomy = instance.context.data["anatomy"]
project_settings = instance.context.data["project_settings"]

return get_workdir(
project_doc, asset_entity, task_data["name"], "flame", anatomy
project_doc,
asset_entity,
task_data["name"],
"flame",
anatomy,
project_settings=project_settings
)
2 changes: 1 addition & 1 deletion openpype/hosts/fusion/scripts/fusion_switch_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from openpype.lib import version_up
from openpype.hosts.fusion import api
from openpype.hosts.fusion.api import lib
from openpype.lib.avalon_context import get_workdir_from_session
from openpype.pipeline.context_tools import get_workdir_from_session

log = logging.getLogger("Update Slap Comp")

Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/fusion/utility_scripts/switch_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
legacy_io,
)
from openpype.hosts.fusion import api
from openpype.lib.avalon_context import get_workdir_from_session
from openpype.pipeline.context_tools import get_workdir_from_session

log = logging.getLogger("Fusion Switch Shot")

Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/maya/api/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import maya.utils
import maya.cmds as cmds

from openpype.api import BuildWorkfile
from openpype.settings import get_project_settings
from openpype.pipeline import legacy_io
from openpype.pipeline.workfile import BuildWorkfile
from openpype.tools.utils import host_tools
from openpype.hosts.maya.api import lib, lib_rendersettings
from .lib import get_main_window, IS_HEADLESS
Expand Down
19 changes: 9 additions & 10 deletions openpype/hosts/nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
)
from openpype.api import (
Logger,
BuildWorkfile,
get_version_from_path,
get_current_project_settings,
)
Expand All @@ -39,7 +38,11 @@
legacy_io,
Anatomy,
)
from openpype.pipeline.context_tools import get_current_project_asset
from openpype.pipeline.context_tools import (
get_current_project_asset,
get_custom_workfile_template_from_session
)
from openpype.pipeline.workfile import BuildWorkfile

from . import gizmo_menu

Expand Down Expand Up @@ -2444,15 +2447,12 @@ def _launch_workfile_app():


def process_workfile_builder():
from openpype.lib import (
env_value_to_bool,
get_custom_workfile_template
)
# to avoid looping of the callback, remove it!
nuke.removeOnCreate(process_workfile_builder, nodeClass="Root")

# get state from settings
workfile_builder = get_current_project_settings()["nuke"].get(
project_settings = get_current_project_settings()
workfile_builder = project_settings["nuke"].get(
"workfile_builder", {})

# get all imortant settings
Expand All @@ -2462,16 +2462,15 @@ def process_workfile_builder():

# get settings
createfv_on = workfile_builder.get("create_first_version") or None
custom_templates = workfile_builder.get("custom_templates") or None
builder_on = workfile_builder.get("builder_on_start") or None

last_workfile_path = os.environ.get("AVALON_LAST_WORKFILE")

# generate first version in file not existing and feature is enabled
if createfv_on and not os.path.exists(last_workfile_path):
# get custom template path if any
custom_template_path = get_custom_workfile_template(
custom_templates
custom_template_path = get_custom_workfile_template_from_session(
project_settings=project_settings
)

# if custom template is defined
Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/nuke/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import openpype
from openpype.api import (
Logger,
BuildWorkfile,
get_current_project_settings
)
from openpype.lib import register_event_callback
Expand All @@ -22,6 +21,7 @@
deregister_inventory_action_path,
AVALON_CONTAINER_ID,
)
from openpype.pipeline.workfile import BuildWorkfile
from openpype.tools.utils import host_tools

from .command import viewer_update_and_undo_stop
Expand Down
13 changes: 6 additions & 7 deletions openpype/hosts/tvpaint/plugins/load/load_workfile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os

from openpype.lib import (
StringTemplate,
get_workfile_template_key_from_context,
get_last_workfile_with_version,
)
from openpype.lib import StringTemplate
from openpype.pipeline import (
registered_host,
legacy_io,
Anatomy,
)
from openpype.pipeline.workfile import (
get_workfile_template_key_from_context,
get_last_workfile_with_version,
)
from openpype.pipeline.template_data import get_template_data_with_names
from openpype.hosts.tvpaint.api import lib, pipeline, plugin

Expand Down Expand Up @@ -57,8 +57,7 @@ def load(self, context, name, namespace, options):
asset_name,
task_name,
host_name,
project_name=project_name,
dbcon=legacy_io
project_name=project_name
)
anatomy = Anatomy(project_name)

Expand Down
24 changes: 17 additions & 7 deletions openpype/lib/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
from . import PypeLogger
from .profiles_filtering import filter_profiles
from .local_settings import get_openpype_username
from .avalon_context import (
get_workdir_with_workdir_data,
get_workfile_template_key,
get_last_workfile
)

from .python_module_tools import (
modules_from_path,
Expand Down Expand Up @@ -1635,7 +1630,14 @@ def prepare_context_environments(data, env_group=None):
data["task_type"] = task_type

try:
workdir = get_workdir_with_workdir_data(workdir_data, anatomy)
from openpype.pipeline.workfile import get_workdir_with_workdir_data

workdir = get_workdir_with_workdir_data(
workdir_data,
anatomy.project_name,
anatomy,
project_settings=project_settings
)

except Exception as exc:
raise ApplicationLaunchFailed(
Expand Down Expand Up @@ -1725,11 +1727,19 @@ def _prepare_last_workfile(data, workdir):
if not last_workfile_path:
extensions = HOST_WORKFILE_EXTENSIONS.get(app.host_name)
if extensions:
from openpype.pipeline.workfile import (
get_workfile_template_key,
get_last_workfile
)

anatomy = data["anatomy"]
project_settings = data["project_settings"]
task_type = workdir_data["task"]["type"]
template_key = get_workfile_template_key(
task_type, app.host_name, project_settings=project_settings
task_type,
app.host_name,
project_name,
project_settings=project_settings
)
# Find last workfile
file_template = str(anatomy.templates[template_key]["file"])
Expand Down
Loading