From c8ecb024ae325ea3960d402951bf5afa152fd844 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Thu, 2 Sep 2021 10:32:39 +0100 Subject: [PATCH 1/6] Load workfile from published. --- .../tvpaint/plugins/load/load_workfile.py | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 openpype/hosts/tvpaint/plugins/load/load_workfile.py diff --git a/openpype/hosts/tvpaint/plugins/load/load_workfile.py b/openpype/hosts/tvpaint/plugins/load/load_workfile.py new file mode 100644 index 0000000000..2b70528918 --- /dev/null +++ b/openpype/hosts/tvpaint/plugins/load/load_workfile.py @@ -0,0 +1,77 @@ +import getpass +import os + +from avalon.tvpaint import lib, pipeline +from avalon import api, io + +from openpype import Anatomy + + +class LoadWorkfile(pipeline.Loader): + """Load workfile.""" + + families = ["workfile"] + representations = ["tvpp"] + + label = "Load Workfile" + + def load(self, context, name, namespace, options): + filepath = self.fname.replace("\\", "/") + + if not os.path.exists(filepath): + raise FileExistsError( + "The loaded file does not exist. Try downloading it first." + ) + + george_script = "tv_LoadProject '\"'\"{}\"'\"'".format( + filepath + ) + lib.execute_george_through_file(george_script) + + # Save workfile. + host = api.registered_host() + + project = io.find_one({ + "type": "project" + }) + session = api.Session + data = { + "project": { + "name": project["name"], + "code": project["data"].get("code") + }, + "asset": session["AVALON_ASSET"], + "task": session["AVALON_TASK"], + "version": 1, + "user": getpass.getuser() + } + anatomy = Anatomy(project["name"]) + template = anatomy.templates["work"]["file"] + + # Define saving file extension + current_file = host.current_file() + if current_file: + # Match the extension of current file + _, extension = os.path.splitext(current_file) + else: + # Fall back to the first extension supported for this host. + extension = host.file_extensions()[0] + + data["ext"] = extension + + version = api.last_workfile_with_version( + host.work_root(session), template, data, [data["ext"]] + )[1] + + if version is None: + version = 1 + else: + version += 1 + + data["version"] = version + + path = os.path.join( + host.work_root(session), + api.format_template_with_optional_keys(data, template) + ) + host.save_file(path) From e080cce1921e63cb56650f4efe716d1850271fba Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Sat, 25 Sep 2021 11:40:27 +0100 Subject: [PATCH 2/6] Context aware loading --- .../tvpaint/plugins/load/load_workfile.py | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/openpype/hosts/tvpaint/plugins/load/load_workfile.py b/openpype/hosts/tvpaint/plugins/load/load_workfile.py index 2b70528918..167b75edf9 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_workfile.py +++ b/openpype/hosts/tvpaint/plugins/load/load_workfile.py @@ -1,10 +1,9 @@ import getpass import os -from avalon.tvpaint import lib, pipeline +from avalon.tvpaint import lib, pipeline, get_current_workfile_context from avalon import api, io - -from openpype import Anatomy +import openpype class LoadWorkfile(pipeline.Loader): @@ -34,19 +33,29 @@ class LoadWorkfile(pipeline.Loader): project = io.find_one({ "type": "project" }) - session = api.Session + context = get_current_workfile_context() + template_key = openpype.lib.get_workfile_template_key_from_context( + context["asset"], + context["task"], + host, + project_name=project["name"] + ) + anatomy = openpype.Anatomy(project["name"]) data = { "project": { "name": project["name"], "code": project["data"].get("code") }, - "asset": session["AVALON_ASSET"], - "task": session["AVALON_TASK"], + "asset": context["asset"], + "task": context["task"], "version": 1, - "user": getpass.getuser() + "user": getpass.getuser(), + "root": { + template_key: anatomy.roots[template_key] + }, + "hierarchy": openpype.lib.get_hierarchy() } - anatomy = Anatomy(project["name"]) - template = anatomy.templates["work"]["file"] + template = anatomy.templates[template_key]["file"] # Define saving file extension current_file = host.current_file() @@ -59,8 +68,11 @@ class LoadWorkfile(pipeline.Loader): data["ext"] = extension + work_root = api.format_template_with_optional_keys( + data, anatomy.templates[template_key]["folder"] + ) version = api.last_workfile_with_version( - host.work_root(session), template, data, [data["ext"]] + work_root, template, data, [data["ext"]] )[1] if version is None: @@ -71,7 +83,7 @@ class LoadWorkfile(pipeline.Loader): data["version"] = version path = os.path.join( - host.work_root(session), + work_root, api.format_template_with_optional_keys(data, template) ) host.save_file(path) From 4442454f9e850f5a4e768f5af9cc23c8c4375d29 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Wed, 6 Oct 2021 18:26:06 +0200 Subject: [PATCH 3/6] Update openpype/hosts/tvpaint/plugins/load/load_workfile.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- openpype/hosts/tvpaint/plugins/load/load_workfile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openpype/hosts/tvpaint/plugins/load/load_workfile.py b/openpype/hosts/tvpaint/plugins/load/load_workfile.py index 167b75edf9..a183621d64 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_workfile.py +++ b/openpype/hosts/tvpaint/plugins/load/load_workfile.py @@ -50,9 +50,7 @@ class LoadWorkfile(pipeline.Loader): "task": context["task"], "version": 1, "user": getpass.getuser(), - "root": { - template_key: anatomy.roots[template_key] - }, + "root": anatomy.roots, "hierarchy": openpype.lib.get_hierarchy() } template = anatomy.templates[template_key]["file"] From 23c5b85a77db37f2355fc0a80b37672455f2fecb Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Wed, 6 Oct 2021 18:26:22 +0200 Subject: [PATCH 4/6] Update openpype/hosts/tvpaint/plugins/load/load_workfile.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- openpype/hosts/tvpaint/plugins/load/load_workfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/tvpaint/plugins/load/load_workfile.py b/openpype/hosts/tvpaint/plugins/load/load_workfile.py index a183621d64..be9b4da87d 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_workfile.py +++ b/openpype/hosts/tvpaint/plugins/load/load_workfile.py @@ -70,7 +70,7 @@ class LoadWorkfile(pipeline.Loader): data, anatomy.templates[template_key]["folder"] ) version = api.last_workfile_with_version( - work_root, template, data, [data["ext"]] + work_root, template, data, host.file_extensions() )[1] if version is None: From 249007aae379b32bb1dc0c764747f6bd577e5470 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 12 Nov 2021 17:03:08 +0100 Subject: [PATCH 5/6] made few fixes of using the right context and right moment and fixed passed host as name to function resolvint wokr template key --- .../tvpaint/plugins/load/load_workfile.py | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/openpype/hosts/tvpaint/plugins/load/load_workfile.py b/openpype/hosts/tvpaint/plugins/load/load_workfile.py index be9b4da87d..820e7f349f 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_workfile.py +++ b/openpype/hosts/tvpaint/plugins/load/load_workfile.py @@ -3,7 +3,11 @@ import os from avalon.tvpaint import lib, pipeline, get_current_workfile_context from avalon import api, io -import openpype +from openpype.lib import ( + get_workfile_template_key_from_context, + get_workdir_data +) +from openpype.api import Anatomy class LoadWorkfile(pipeline.Loader): @@ -15,6 +19,13 @@ class LoadWorkfile(pipeline.Loader): label = "Load Workfile" def load(self, context, name, namespace, options): + # Load context of current workfile as first thing + # - which context and extension has + host = api.registered_host() + current_file = host.current_file() + + context = get_current_workfile_context() + filepath = self.fname.replace("\\", "/") if not os.path.exists(filepath): @@ -28,35 +39,35 @@ class LoadWorkfile(pipeline.Loader): lib.execute_george_through_file(george_script) # Save workfile. - host = api.registered_host() + host_name = "tvpaint" + asset_name = context["asset"] + task_name = context["task"] - project = io.find_one({ + project_doc = io.find_one({ "type": "project" }) - context = get_current_workfile_context() - template_key = openpype.lib.get_workfile_template_key_from_context( - context["asset"], - context["task"], - host, - project_name=project["name"] + asset_doc = io.find_one({ + "type": "asset", + "name": asset_name + }) + project_name = project_doc["name"] + + template_key = get_workfile_template_key_from_context( + asset_name, + task_name, + host_name, + project_name=project_name, + dbcon=io ) - anatomy = openpype.Anatomy(project["name"]) - data = { - "project": { - "name": project["name"], - "code": project["data"].get("code") - }, - "asset": context["asset"], - "task": context["task"], - "version": 1, - "user": getpass.getuser(), - "root": anatomy.roots, - "hierarchy": openpype.lib.get_hierarchy() - } + anatomy = Anatomy(project_name) + + data = get_workdir_data(project_doc, asset_doc, task_name, host_name) + data["roots"] = anatomy.roots + data["user"] = getpass.getuser() + template = anatomy.templates[template_key]["file"] # Define saving file extension - current_file = host.current_file() if current_file: # Match the extension of current file _, extension = os.path.splitext(current_file) From 5868db1ac209a5c4179d4f3c3724219630520c2d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 12 Nov 2021 18:33:03 +0100 Subject: [PATCH 6/6] final fixes --- openpype/hosts/tvpaint/plugins/load/load_workfile.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openpype/hosts/tvpaint/plugins/load/load_workfile.py b/openpype/hosts/tvpaint/plugins/load/load_workfile.py index 820e7f349f..f410a1ab9d 100644 --- a/openpype/hosts/tvpaint/plugins/load/load_workfile.py +++ b/openpype/hosts/tvpaint/plugins/load/load_workfile.py @@ -40,8 +40,12 @@ class LoadWorkfile(pipeline.Loader): # Save workfile. host_name = "tvpaint" - asset_name = context["asset"] - task_name = context["task"] + asset_name = context.get("asset") + task_name = context.get("task") + # Far cases when there is workfile without context + if not asset_name: + asset_name = io.Session["AVALON_ASSET"] + task_name = io.Session["AVALON_TASK"] project_doc = io.find_one({ "type": "project" @@ -62,7 +66,7 @@ class LoadWorkfile(pipeline.Loader): anatomy = Anatomy(project_name) data = get_workdir_data(project_doc, asset_doc, task_name, host_name) - data["roots"] = anatomy.roots + data["root"] = anatomy.roots data["user"] = getpass.getuser() template = anatomy.templates[template_key]["file"]