From de3f865d7729c8b4d2fe2bc1d815080135fdbe13 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 18 Feb 2022 02:40:25 +0100 Subject: [PATCH] Fix matching in Python 2 --- openpype/tools/workfiles/app.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/openpype/tools/workfiles/app.py b/openpype/tools/workfiles/app.py index 785e87738f..4b5bf07b47 100644 --- a/openpype/tools/workfiles/app.py +++ b/openpype/tools/workfiles/app.py @@ -116,7 +116,7 @@ class CommentMatcher(object): "|".join(re.escape(ext[1:]) for ext in extensions) ) - # Use placeholders that we can safely escape with regex + # Use placeholders that will never be in the filename temp_data = copy.deepcopy(data) temp_data["comment"] = "<>" temp_data["version"] = "<>" @@ -126,11 +126,14 @@ class CommentMatcher(object): fname_pattern = formatted[template_key]["file"] fname_pattern = re.escape(fname_pattern) - # Replace comment and version with something we can match with - # regex - fname_pattern = fname_pattern.replace("<>", "(.+)") - fname_pattern = fname_pattern.replace("<>", "[0-9]+") - fname_pattern = fname_pattern.replace("<>", any_extension) + # Replace comment and version with something we can match with regex + replacements = { + "<>": "(.+)", + "<>": "[0-9]+", + "<>": any_extension, + } + for src, dest in replacements.items(): + fname_pattern = fname_pattern.replace(re.escape(src), dest) # Match from beginning to end of string to be safe fname_pattern = "^{}$".format(fname_pattern)