From 5436cf08d54ff2dd14bd9e6482bd1c5874ecb662 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 12 Mar 2024 02:55:39 +0100 Subject: [PATCH] Simplify get workdir --- client/ayon_core/hosts/zbrush/api/lib.py | 42 ++----------------- client/ayon_core/hosts/zbrush/api/pipeline.py | 24 +++++------ 2 files changed, 16 insertions(+), 50 deletions(-) diff --git a/client/ayon_core/hosts/zbrush/api/lib.py b/client/ayon_core/hosts/zbrush/api/lib.py index 7b288008e4..5814146b42 100644 --- a/client/ayon_core/hosts/zbrush/api/lib.py +++ b/client/ayon_core/hosts/zbrush/api/lib.py @@ -1,16 +1,11 @@ +import functools import os import uuid import time import tempfile import logging -from ayon_core.client import ( - get_project, - get_asset_by_name, -) -from ayon_core.pipeline import Anatomy -from string import Formatter + from . import CommunicationWrapper -from ayon_core.pipeline.template_data import get_template_data log = logging.getLogger("zbrush.lib") @@ -88,37 +83,8 @@ def execute_zscript_and_wait(zscript, ) -def find_first_filled_path(path): - if not path: - return "" - - fields = set() - for item in Formatter().parse(path): - _, field_name, format_spec, conversion = item - if not field_name: - continue - conversion = "!{}".format(conversion) if conversion else "" - format_spec = ":{}".format(format_spec) if format_spec else "" - orig_key = "{{{}{}{}}}".format( - field_name, conversion, format_spec) - fields.add(orig_key) - - for field in fields: - path = path.split(field, 1)[0] - return path - - -def get_workdir(project_name, asset_name, task_name): - project = get_project(project_name) - asset = get_asset_by_name(project_name, asset_name) - - data = get_template_data(project, asset, task_name) - - anatomy = Anatomy(project_name) - workdir = anatomy.templates_obj["work"]["folder"].format(data) - - # Remove any potential un-formatted parts of the path - valid_workdir = find_first_filled_path(workdir) +def get_workdir(): + return os.environ["AYON_WORKDIR"] # Path is not filled at all if not valid_workdir: diff --git a/client/ayon_core/hosts/zbrush/api/pipeline.py b/client/ayon_core/hosts/zbrush/api/pipeline.py index 657e623cb8..74254db177 100644 --- a/client/ayon_core/hosts/zbrush/api/pipeline.py +++ b/client/ayon_core/hosts/zbrush/api/pipeline.py @@ -125,7 +125,7 @@ class ZbrushHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() txt_dir = os.path.join( work_dir, ".zbrush_metadata").replace( "\\", "/" @@ -213,7 +213,7 @@ def write_context_metadata(metadata_key, context): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", metadata_key).replace( "\\", "/" @@ -241,7 +241,7 @@ def write_workfile_metadata(metadata_key, data=None): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, metadata_key).replace( @@ -288,7 +288,7 @@ def write_load_metadata(metadata_key, data): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() name = next((d["name"] for d in data), None) json_dir = os.path.join( work_dir, ".zbrush_metadata", @@ -310,7 +310,7 @@ def get_load_context_metadata(metadata_key): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", metadata_key).replace( "\\", "/" @@ -338,7 +338,7 @@ def get_load_workfile_metadata(metadata_key): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, metadata_key).replace( @@ -368,7 +368,7 @@ def get_instance_workfile_metadata(metadata_key): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, metadata_key).replace( @@ -391,7 +391,7 @@ def remove_container_data(name): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, ZBRUSH_SECTION_NAME_CONTAINERS).replace( @@ -408,7 +408,7 @@ def remove_tmp_data(): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() for name in [ZBRUSH_METADATA_CREATE_CONTEXT, ZBRUSH_SECTION_NAME_INSTANCES, ZBRUSH_SECTION_NAME_CONTAINERS]: @@ -433,7 +433,7 @@ def copy_ayon_data(filepath): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() for name in [ZBRUSH_METADATA_CREATE_CONTEXT, ZBRUSH_SECTION_NAME_INSTANCES, ZBRUSH_SECTION_NAME_CONTAINERS]: @@ -461,7 +461,7 @@ def set_current_file(filepath=None): project_name = get_current_context()["project_name"] folder_path = get_current_context()["folder_path"] task_name = get_current_context()["task_name"] - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() txt_dir = os.path.join( work_dir, ".zbrush_metadata").replace( "\\", "/" @@ -491,7 +491,7 @@ def imprint(container, representation_id): if current_file: current_file = os.path.splitext( os.path.basename(current_file))[0].strip() - work_dir = get_workdir(project_name, folder_path, task_name) + work_dir = get_workdir() json_dir = os.path.join( work_dir, ".zbrush_metadata", current_file, ZBRUSH_SECTION_NAME_CONTAINERS).replace(