From 5a3e99bd8681a05bbc476cd149f3e4a59f04da3c Mon Sep 17 00:00:00 2001 From: Jeff Beeland Date: Fri, 5 Jan 2018 16:13:37 -0800 Subject: [PATCH 1/3] Removes a utf-8 string encode that was creating file paths that shotgun_api3 didn't like. --- python/tk_photoshopcc/adobe_bridge.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/python/tk_photoshopcc/adobe_bridge.py b/python/tk_photoshopcc/adobe_bridge.py index 14ec171..598d804 100644 --- a/python/tk_photoshopcc/adobe_bridge.py +++ b/python/tk_photoshopcc/adobe_bridge.py @@ -207,9 +207,6 @@ def get_active_document_path(self): except Exception: path = None - if isinstance(path, unicode): - path = path.encode("utf-8") - return path def log_message(self, level, msg): From c64eac3c9c5babc52c0a70d48e3488efb9064d5f Mon Sep 17 00:00:00 2001 From: Jeff Beeland Date: Mon, 22 Jan 2018 17:22:26 -0800 Subject: [PATCH 2/3] Resolves Windows-specific issues with utf-8 encoded document paths. --- hooks/tk-multi-publish2/basic/publish_document.py | 12 ++++++++++++ python/tk_photoshopcc/adobe_bridge.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/hooks/tk-multi-publish2/basic/publish_document.py b/hooks/tk-multi-publish2/basic/publish_document.py index 3cd1d4f..ff43a18 100644 --- a/hooks/tk-multi-publish2/basic/publish_document.py +++ b/hooks/tk-multi-publish2/basic/publish_document.py @@ -9,6 +9,7 @@ # not expressly granted therein are reserved by Shotgun Software Inc. import os +import sys import sgtk HookBaseClass = sgtk.get_hook_baseclass() @@ -391,4 +392,15 @@ def _document_path(document): except Exception: path = None + # The RPC API is always going to return a utf-8 encoded string + # here. This is fine (and correct) in almost all cases, but there + # are some situations on Windows where the encoded path, if it + # includes non-ascii characters, will test as false when checking + # existence. In that case, we're forced to decode the string to + # unicode. + # + # Note: This does not appear to be an issue on OS X. + if path and sys.platform.startswith("win") and not os.path.exists(path): + path = path.decode("utf-8") + return path diff --git a/python/tk_photoshopcc/adobe_bridge.py b/python/tk_photoshopcc/adobe_bridge.py index 598d804..5a6b446 100644 --- a/python/tk_photoshopcc/adobe_bridge.py +++ b/python/tk_photoshopcc/adobe_bridge.py @@ -9,6 +9,7 @@ # not expressly granted therein are reserved by Shotgun Software Inc. import os +import sys import functools import threading @@ -207,6 +208,17 @@ def get_active_document_path(self): except Exception: path = None + # The RPC API is always going to return a utf-8 encoded string + # here. This is fine (and correct) in almost all cases, but there + # are some situations on Windows where the encoded path, if it + # includes non-ascii characters, will test as false when checking + # existence. In that case, we're forced to decode the string to + # unicode. + # + # Note: This does not appear to be an issue on OS X. + if path and sys.platform.startswith("win") and not os.path.exists(path): + path = path.decode("utf-8") + return path def log_message(self, level, msg): From ee91184928f7e3ea5522bdc5437c1881f843350c Mon Sep 17 00:00:00 2001 From: Jeff Beeland Date: Wed, 24 Jan 2018 17:07:23 -0800 Subject: [PATCH 3/3] Addresses CR comments. We now return unicode paths when using the bridge methods. --- hooks/tk-multi-publish2/basic/collector.py | 10 +++---- .../basic/publish_document.py | 24 +++++------------ .../basic/start_version_control.py | 9 ++----- .../tk-multi-publish2/basic/upload_version.py | 9 +++---- python/tk_photoshopcc/adobe_bridge.py | 27 ++++++++++++------- 5 files changed, 35 insertions(+), 44 deletions(-) diff --git a/hooks/tk-multi-publish2/basic/collector.py b/hooks/tk-multi-publish2/basic/collector.py index 7b62a60..2550658 100644 --- a/hooks/tk-multi-publish2/basic/collector.py +++ b/hooks/tk-multi-publish2/basic/collector.py @@ -194,10 +194,10 @@ def _document_path(document): Returns the path on disk to the supplied document. May be ``None`` if the document has not been saved. """ + engine = sgtk.platform.current_engine() + return engine.adobe.get_document_path(document) + + + - try: - path = document.fullName.fsName - except Exception: - path = None - return path diff --git a/hooks/tk-multi-publish2/basic/publish_document.py b/hooks/tk-multi-publish2/basic/publish_document.py index ff43a18..5a4d956 100644 --- a/hooks/tk-multi-publish2/basic/publish_document.py +++ b/hooks/tk-multi-publish2/basic/publish_document.py @@ -386,21 +386,11 @@ def _document_path(document): Returns the path on disk to the supplied document. May be ``None`` if the document has not been saved. """ + engine = sgtk.platform.current_engine() + return engine.adobe.get_document_path(document) + + + + + - try: - path = document.fullName.fsName - except Exception: - path = None - - # The RPC API is always going to return a utf-8 encoded string - # here. This is fine (and correct) in almost all cases, but there - # are some situations on Windows where the encoded path, if it - # includes non-ascii characters, will test as false when checking - # existence. In that case, we're forced to decode the string to - # unicode. - # - # Note: This does not appear to be an issue on OS X. - if path and sys.platform.startswith("win") and not os.path.exists(path): - path = path.decode("utf-8") - - return path diff --git a/hooks/tk-multi-publish2/basic/start_version_control.py b/hooks/tk-multi-publish2/basic/start_version_control.py index 388a5a6..aaab7d0 100644 --- a/hooks/tk-multi-publish2/basic/start_version_control.py +++ b/hooks/tk-multi-publish2/basic/start_version_control.py @@ -349,10 +349,5 @@ def _document_path(document): Returns the path on disk to the supplied document. May be ``None`` if the document has not been saved. """ - - try: - path = document.fullName.fsName - except Exception: - path = None - - return path + engine = sgtk.platform.current_engine() + return engine.adobe.get_document_path(document) diff --git a/hooks/tk-multi-publish2/basic/upload_version.py b/hooks/tk-multi-publish2/basic/upload_version.py index c3d61af..a97df31 100644 --- a/hooks/tk-multi-publish2/basic/upload_version.py +++ b/hooks/tk-multi-publish2/basic/upload_version.py @@ -382,10 +382,9 @@ def _document_path(document): Returns the path on disk to the supplied document. May be ``None`` if the document has not been saved. """ + engine = sgtk.platform.current_engine() + return engine.adobe.get_document_path(document) + + - try: - path = document.fullName.fsName - except Exception: - path = None - return path \ No newline at end of file diff --git a/python/tk_photoshopcc/adobe_bridge.py b/python/tk_photoshopcc/adobe_bridge.py index 5a6b446..7b5e900 100644 --- a/python/tk_photoshopcc/adobe_bridge.py +++ b/python/tk_photoshopcc/adobe_bridge.py @@ -202,24 +202,31 @@ def get_active_document_path(self): if not doc: return None + return self.get_document_path(doc) + + def get_document_path(self, document): + """ + Gets the path on disk for the given Photoshop document. The path + is returned in unicode form to avoid string encoding issues when + the document's name contains non-ascii characters. + + :returns: The document's file path on disk as a unicode string, + or None if the document has never been saved to disk. + :rtype: unicode or None + """ with self.response_logging_silenced(): try: - path = doc.fullName.fsName + path = document.fullName.fsName except Exception: - path = None + return None # The RPC API is always going to return a utf-8 encoded string # here. This is fine (and correct) in almost all cases, but there # are some situations on Windows where the encoded path, if it # includes non-ascii characters, will test as false when checking - # existence. In that case, we're forced to decode the string to - # unicode. - # - # Note: This does not appear to be an issue on OS X. - if path and sys.platform.startswith("win") and not os.path.exists(path): - path = path.decode("utf-8") - - return path + # existence. To avoid these kinds of problems, we're forced to + # decode the string into unicode and return that. + return path.decode("utf-8") def log_message(self, level, msg): """