From 3c6d807df54a44d51956a33cda083fb93ec3a92e Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Wed, 20 Oct 2021 10:20:13 +0200 Subject: [PATCH] add dict for task name short and type --- openpype/hosts/maya/api/customize.py | 9 +++-- .../plugins/publish/extract_harmony_zip.py | 11 ++++-- openpype/lib/anatomy.py | 8 +++++ openpype/lib/avalon_context.py | 36 +++++++++---------- .../defaults/project_anatomy/templates.json | 4 +-- .../schemas/schema_anatomy_templates.json | 4 +++ openpype/settings/lib.py | 7 ++++ openpype/tools/workfiles/app.py | 21 +++++++++-- 8 files changed, 74 insertions(+), 26 deletions(-) diff --git a/openpype/hosts/maya/api/customize.py b/openpype/hosts/maya/api/customize.py index a84412963b..0b95073ea0 100644 --- a/openpype/hosts/maya/api/customize.py +++ b/openpype/hosts/maya/api/customize.py @@ -84,7 +84,7 @@ def override_toolbox_ui(): log.warning("Could not import Loader tool") try: - from avalon.maya.pipeline import launch_workfiles_app + from openpype.tools import workfiles as launch_workfiles_app except Exception: log.warning("Could not import Workfiles tool") @@ -142,7 +142,12 @@ def override_toolbox_ui(): annotation="Work Files", label="Work Files", image=os.path.join(icons, "workfiles.png"), - command=lambda: launch_workfiles_app(), + command=lambda: launch_workfiles_app.show( + os.path.join( + mc.workspace(query=True, rootDirectory=True), + mc.workspace(fileRuleEntry="scene") + ) + ), bgc=background_color, width=icon_size, height=icon_size, diff --git a/openpype/hosts/standalonepublisher/plugins/publish/extract_harmony_zip.py b/openpype/hosts/standalonepublisher/plugins/publish/extract_harmony_zip.py index adbac6ef09..8014349de3 100644 --- a/openpype/hosts/standalonepublisher/plugins/publish/extract_harmony_zip.py +++ b/openpype/hosts/standalonepublisher/plugins/publish/extract_harmony_zip.py @@ -220,6 +220,10 @@ class ExtractHarmonyZip(openpype.api.Extractor): anatomy = openpype.api.Anatomy() project_entity = instance.context.data["projectEntity"] + task_name = instance.data.get("task") + task_type = instance.data['tasks'].get(task_name, {}).get('type') + task_short = project_entity['config']['tasks'][task_type]['short_name'] + data = { "root": api.registered_root(), "project": { @@ -229,14 +233,17 @@ class ExtractHarmonyZip(openpype.api.Extractor): "asset": instance.data["asset"], "hierarchy": openpype.api.get_hierarchy(instance.data["asset"]), "family": instance.data["family"], - "task": instance.data.get("task"), + "task": { + "name": task_name, + "type": task_type, + "short": task_short, + }, "subset": instance.data["subset"], "version": 1, "ext": "zip", } host_name = "harmony" template_name = get_workfile_template_key_from_context( - instance.data["asset"], instance.data.get("task"), host_name, project_name=project_entity["name"], diff --git a/openpype/lib/anatomy.py b/openpype/lib/anatomy.py index 7a4a55363c..78dc323d4d 100644 --- a/openpype/lib/anatomy.py +++ b/openpype/lib/anatomy.py @@ -989,6 +989,10 @@ class Templates: invalid_required = [] missing_required = [] replace_keys = [] + + if "{task[name]}" in orig_template and not isinstance(data["task"], dict): + data['task']= {'name': data.get("task")} + for group in self.key_pattern.findall(template): orig_key = group[1:-1] key = str(orig_key) @@ -1074,6 +1078,10 @@ class Templates: output = collections.defaultdict(dict) for key, orig_value in templates.items(): if isinstance(orig_value, StringType): + # Replace {task} by '{task[name]}' for backward compatibility + if '{task}' in orig_value: + orig_value = orig_value.replace('{task}', '{task[name]}') + output[key] = self._format(orig_value, data) continue diff --git a/openpype/lib/avalon_context.py b/openpype/lib/avalon_context.py index b043cbfdb4..1f28a5088f 100644 --- a/openpype/lib/avalon_context.py +++ b/openpype/lib/avalon_context.py @@ -7,6 +7,7 @@ import platform import logging import collections import functools +import getpass from openpype.settings import get_project_settings from .anatomy import Anatomy @@ -346,7 +347,7 @@ def get_latest_version(asset_name, subset_name, dbcon=None, project_name=None): def get_workfile_template_key_from_context( - asset_name, task_name, host_name, project_name=None, + task_info, host_name, project_name=None, dbcon=None, project_settings=None ): """Helper function to get template key for workfile template. @@ -358,9 +359,8 @@ def get_workfile_template_key_from_context( 'project_name' arguments. Args: - asset_name(str): Name of asset document. - task_name(str): Task name for which is template key retrieved. - Must be available on asset document under `data.tasks`. + task_info(dict): Information about the task is used to retrieve the + `type` of the task. host_name(str): Name of host implementation for which is workfile used. project_name(str): Project name where asset and task is. Not required @@ -387,17 +387,6 @@ def get_workfile_template_key_from_context( elif not project_name: project_name = dbcon.Session["AVALON_PROJECT"] - asset_doc = dbcon.find_one( - { - "type": "asset", - "name": asset_name - }, - { - "data.tasks": 1 - } - ) - asset_tasks = asset_doc.get("data", {}).get("tasks") or {} - task_info = asset_tasks.get(task_name) or {} task_type = task_info.get("type") return get_workfile_template_key( @@ -479,15 +468,27 @@ def get_workdir_data(project_doc, asset_doc, task_name, host_name): """ hierarchy = "/".join(asset_doc["data"]["parents"]) + task_type = asset_doc['data']['tasks'].get(task_name, {}).get('type') + + if task_type: + task_code = project_doc['config']['tasks'][task_type]['short_name'] + else: + task_code = None + data = { "project": { "name": project_doc["name"], "code": project_doc["data"].get("code") }, - "task": task_name, + "task": { + "name": task_name, + "type": task_type, + "short": task_code, + }, "asset": asset_doc["name"], "app": host_name, - "hierarchy": hierarchy + "user": getpass.getuser(), + "hierarchy": hierarchy, } return data @@ -530,7 +531,6 @@ def get_workdir_with_workdir_data( if not template_key: template_key = get_workfile_template_key_from_context( - workdir_data["asset"], workdir_data["task"], workdir_data["app"], project_name=workdir_data["project"]["name"], diff --git a/openpype/settings/defaults/project_anatomy/templates.json b/openpype/settings/defaults/project_anatomy/templates.json index 53abd35ed5..c6e79b8dcd 100644 --- a/openpype/settings/defaults/project_anatomy/templates.json +++ b/openpype/settings/defaults/project_anatomy/templates.json @@ -6,8 +6,8 @@ "frame": "{frame:0>{@frame_padding}}" }, "work": { - "folder": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task}", - "file": "{project[code]}_{asset}_{task}_{@version}<_{comment}>.{ext}", + "folder": "{root[work]}/{project[name]}/{hierarchy}/{asset}/work/{task[user]}", + "file": "{project[code]}_{asset}_{task[user]}_{@version}<_{comment}>.{ext}", "path": "{@folder}/{@file}" }, "render": { diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_anatomy_templates.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_anatomy_templates.json index a8534e7e29..be8d6661cf 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_anatomy_templates.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_anatomy_templates.json @@ -11,6 +11,10 @@ "type": "dict", "key": "defaults", "children": [ + { + "type": "label", + "label": "The list of existing default placeholders for the construction of paths:
{root[`root_name`]}, {project[name]}, {project[short]}, {hierarchy}, {asset}, {task[name]}, {task[type]}, {task[code]}, {family}, {subset}, {output}, {ext}, {thumbnail_root}, {_id}, {thumbnail_type} " + }, { "type": "number", "key": "version_padding", diff --git a/openpype/settings/lib.py b/openpype/settings/lib.py index 60ed54bd4a..88ce8b6719 100644 --- a/openpype/settings/lib.py +++ b/openpype/settings/lib.py @@ -856,6 +856,13 @@ def get_anatomy_settings( apply_local_settings_on_anatomy_settings( result, local_settings, project_name, site_name ) + + # Replace {task} by '{task[name]}' in all template for backward compatibility + for template in result.get('templates', {}).values(): + for sub_template_name, sub_template_value in template.items(): + if isinstance(sub_template_value, str) and '{task}' in sub_template_value: + template[sub_template_name] = sub_template_value.replace('{task}', '{task[name]}') + return result diff --git a/openpype/tools/workfiles/app.py b/openpype/tools/workfiles/app.py index 6fff0d0278..716c417cd1 100644 --- a/openpype/tools/workfiles/app.py +++ b/openpype/tools/workfiles/app.py @@ -65,16 +65,33 @@ class NameWindow(QtWidgets.QDialog): {"type": "project"}, { "name": True, - "data.code": True + "data.code": True, + "config.tasks": True, } ) + asset_doc = io.find_one({ + "type": "asset", + "name": asset_name + }) + + task_type = asset_doc['data']['tasks'].get(session["AVALON_TASK"], {}).get('type') + + if task_type: + task_short = project_doc['config']['tasks'][task_type]['short_name'] + else: + task_short = None + self.data = { "project": { "name": project_doc["name"], "code": project_doc["data"].get("code") }, "asset": asset_name, - "task": session["AVALON_TASK"], + "task": { + "name": session["AVALON_TASK"], + "type": task_type, + "short": task_short, + }, "version": 1, "user": getpass.getuser(), "comment": "",