From d4bf25f01a823b042777730d6e09333223841656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 10 Jan 2020 13:07:11 +0000 Subject: [PATCH 1/4] resolving `${TOKEN}` variables in PATH to env variables --- pype/plugins/maya/publish/collect_yeti_rig.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pype/plugins/maya/publish/collect_yeti_rig.py b/pype/plugins/maya/publish/collect_yeti_rig.py index 7ab5649c0b..3b05e19fdb 100644 --- a/pype/plugins/maya/publish/collect_yeti_rig.py +++ b/pype/plugins/maya/publish/collect_yeti_rig.py @@ -140,9 +140,21 @@ class CollectYetiRig(pyblish.api.InstancePlugin): "atttribute'" % node) # Collect all texture files + # find all ${TOKEN} tokens and replace them with $TOKEN env. variable + env_re = re.compile(r"\$\{(\w+)\}") for texture in texture_filenames: files = [] + + matches = re.finditer(env_re, texture) + for m in matches: + try: + texture = texture.replace(m.group(), os.environ[m.group(1)]) + except KeyError: + msg = "Cannot find requested {} in environment".format(1) + self.log.error(msg) + raise RuntimeError(msg) + if os.path.isabs(texture): self.log.debug("Texture is absolute path, ignoring " "image search paths for: %s" % texture) From 9a7f36023b5f9f9d9a29ff4ae9a6c88c7a01069b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 10 Jan 2020 13:16:41 +0000 Subject: [PATCH 2/4] fixed error message --- pype/plugins/maya/publish/collect_yeti_rig.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pype/plugins/maya/publish/collect_yeti_rig.py b/pype/plugins/maya/publish/collect_yeti_rig.py index 3b05e19fdb..831bc5e0ca 100644 --- a/pype/plugins/maya/publish/collect_yeti_rig.py +++ b/pype/plugins/maya/publish/collect_yeti_rig.py @@ -151,7 +151,8 @@ class CollectYetiRig(pyblish.api.InstancePlugin): try: texture = texture.replace(m.group(), os.environ[m.group(1)]) except KeyError: - msg = "Cannot find requested {} in environment".format(1) + msg = "Cannot find requested {} in environment".format( + m.group(1)) self.log.error(msg) raise RuntimeError(msg) From acdc0fed0cbb1463c6f0b354c92d293f9cc1f13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 10 Jan 2020 13:23:07 +0000 Subject: [PATCH 3/4] refactored to class method --- pype/plugins/maya/publish/collect_yeti_rig.py | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/pype/plugins/maya/publish/collect_yeti_rig.py b/pype/plugins/maya/publish/collect_yeti_rig.py index 831bc5e0ca..39426ea623 100644 --- a/pype/plugins/maya/publish/collect_yeti_rig.py +++ b/pype/plugins/maya/publish/collect_yeti_rig.py @@ -119,6 +119,8 @@ class CollectYetiRig(pyblish.api.InstancePlugin): texture_filenames = [] if image_search_paths: + # find all ${TOKEN} tokens and replace them with $TOKEN env. variable + image_search_paths = self._replace_tokens(image_search_paths) # TODO: Somehow this uses OS environment path separator, `:` vs `;` # Later on check whether this is pipeline OS cross-compatible. image_search_paths = [p for p in @@ -141,21 +143,11 @@ class CollectYetiRig(pyblish.api.InstancePlugin): # Collect all texture files # find all ${TOKEN} tokens and replace them with $TOKEN env. variable - env_re = re.compile(r"\$\{(\w+)\}") + texture_filenames = self._replace_tokens(texture_filenames) for texture in texture_filenames: files = [] - - matches = re.finditer(env_re, texture) - for m in matches: - try: - texture = texture.replace(m.group(), os.environ[m.group(1)]) - except KeyError: - msg = "Cannot find requested {} in environment".format( - m.group(1)) - self.log.error(msg) - raise RuntimeError(msg) - + if os.path.isabs(texture): self.log.debug("Texture is absolute path, ignoring " "image search paths for: %s" % texture) @@ -296,3 +288,20 @@ class CollectYetiRig(pyblish.api.InstancePlugin): collection, remainder = clique.assemble(files, patterns=pattern) return collection + + def _replace_tokens(self, strings): + env_re = re.compile(r"\$\{(\w+)\}") + + replaced = [] + for s in strings: + matches = re.finditer(env_re, s) + for m in matches: + try: + s = s.replace(m.group(), os.environ[m.group(1)]) + except KeyError: + msg = "Cannot find requested {} in environment".format( + m.group(1)) + self.log.error(msg) + raise RuntimeError(msg) + replaced.append(s) + return replaced From efd71c7ef72090f6f989d9b237dce53333c8f6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 10 Jan 2020 13:53:49 +0000 Subject: [PATCH 4/4] changed place where tokens are replaced for `image_search_path` --- pype/plugins/maya/publish/collect_yeti_rig.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pype/plugins/maya/publish/collect_yeti_rig.py b/pype/plugins/maya/publish/collect_yeti_rig.py index 39426ea623..c743b2c00b 100644 --- a/pype/plugins/maya/publish/collect_yeti_rig.py +++ b/pype/plugins/maya/publish/collect_yeti_rig.py @@ -119,13 +119,15 @@ class CollectYetiRig(pyblish.api.InstancePlugin): texture_filenames = [] if image_search_paths: - # find all ${TOKEN} tokens and replace them with $TOKEN env. variable - image_search_paths = self._replace_tokens(image_search_paths) + # TODO: Somehow this uses OS environment path separator, `:` vs `;` # Later on check whether this is pipeline OS cross-compatible. image_search_paths = [p for p in image_search_paths.split(os.path.pathsep) if p] + # find all ${TOKEN} tokens and replace them with $TOKEN env. variable + image_search_paths = self._replace_tokens(image_search_paths) + # List all related textures texture_filenames = cmds.pgYetiCommand(node, listTextures=True) self.log.info("Found %i texture(s)" % len(texture_filenames)) @@ -147,7 +149,6 @@ class CollectYetiRig(pyblish.api.InstancePlugin): for texture in texture_filenames: files = [] - if os.path.isabs(texture): self.log.debug("Texture is absolute path, ignoring " "image search paths for: %s" % texture)