From 714f58fbd692dd31f5446c8f4b1270dcd0cb0b32 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:10:54 +0200 Subject: [PATCH 1/2] excape parenthesis for shell --- client/ayon_core/plugins/publish/extract_review.py | 7 +++++++ client/ayon_core/plugins/publish/extract_review_slate.py | 7 +++++++ client/ayon_core/plugins/publish/extract_thumbnail.py | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index c2793f98a2..b2531ebae9 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -454,6 +454,13 @@ def _render_output_definitions( raise NotImplementedError subprcs_cmd = " ".join(ffmpeg_args) + if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): + # Escape parentheses for bash + subprcs_cmd = ( + subprcs_cmd + .replace("(", "\\(") + .replace(")", "\\)") + ) # run subprocess self.log.debug("Executing: {}".format(subprcs_cmd)) diff --git a/client/ayon_core/plugins/publish/extract_review_slate.py b/client/ayon_core/plugins/publish/extract_review_slate.py index 35f55e275c..01a65e89ae 100644 --- a/client/ayon_core/plugins/publish/extract_review_slate.py +++ b/client/ayon_core/plugins/publish/extract_review_slate.py @@ -269,6 +269,13 @@ def process(self, instance): " ".join(output_args) ] slate_subprocess_cmd = " ".join(slate_args) + if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): + # Escape parentheses for bash + slate_subprocess_cmd = ( + slate_subprocess_cmd + .replace("(", "\\(") + .replace(")", "\\)") + ) # run slate generation subprocess self.log.debug( diff --git a/client/ayon_core/plugins/publish/extract_thumbnail.py b/client/ayon_core/plugins/publish/extract_thumbnail.py index d1b6e4e0cc..328cb308b9 100644 --- a/client/ayon_core/plugins/publish/extract_thumbnail.py +++ b/client/ayon_core/plugins/publish/extract_thumbnail.py @@ -455,6 +455,14 @@ def _create_thumbnail_ffmpeg(self, src_path, dst_path): # output file jpeg_items.append(path_to_subprocess_arg(dst_path)) subprocess_command = " ".join(jpeg_items) + if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): + # Escape parentheses for bash + subprocess_command = ( + subprocess_command + .replace("(", "\\(") + .replace(")", "\\)") + ) + try: run_subprocess( subprocess_command, shell=True, logger=self.log From 911ef45a458a51a90d5e5caee2058748cfc68b67 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:33:48 +0200 Subject: [PATCH 2/2] handle escape in 'run_subprocess' --- client/ayon_core/lib/execute.py | 14 ++++++++++++++ client/ayon_core/plugins/publish/extract_review.py | 7 ------- .../plugins/publish/extract_review_slate.py | 7 ------- .../ayon_core/plugins/publish/extract_thumbnail.py | 7 ------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/client/ayon_core/lib/execute.py b/client/ayon_core/lib/execute.py index bc55c27bd8..4e6cb415e7 100644 --- a/client/ayon_core/lib/execute.py +++ b/client/ayon_core/lib/execute.py @@ -108,6 +108,20 @@ def run_subprocess(*args, **kwargs): | getattr(subprocess, "CREATE_NO_WINDOW", 0) ) + # Escape parentheses for bash + if ( + kwargs.get("shell") is True + and len(args) == 1 + and isinstance(args[0], str) + and os.getenv("SHELL") in ("/bin/bash", "/bin/sh") + ): + new_arg = ( + args[0] + .replace("(", "\\(") + .replace(")", "\\)") + ) + args = (new_arg, ) + # Get environents from kwarg or use current process environments if were # not passed. env = kwargs.get("env") or os.environ diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index b2531ebae9..c2793f98a2 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -454,13 +454,6 @@ def _render_output_definitions( raise NotImplementedError subprcs_cmd = " ".join(ffmpeg_args) - if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): - # Escape parentheses for bash - subprcs_cmd = ( - subprcs_cmd - .replace("(", "\\(") - .replace(")", "\\)") - ) # run subprocess self.log.debug("Executing: {}".format(subprcs_cmd)) diff --git a/client/ayon_core/plugins/publish/extract_review_slate.py b/client/ayon_core/plugins/publish/extract_review_slate.py index 01a65e89ae..35f55e275c 100644 --- a/client/ayon_core/plugins/publish/extract_review_slate.py +++ b/client/ayon_core/plugins/publish/extract_review_slate.py @@ -269,13 +269,6 @@ def process(self, instance): " ".join(output_args) ] slate_subprocess_cmd = " ".join(slate_args) - if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): - # Escape parentheses for bash - slate_subprocess_cmd = ( - slate_subprocess_cmd - .replace("(", "\\(") - .replace(")", "\\)") - ) # run slate generation subprocess self.log.debug( diff --git a/client/ayon_core/plugins/publish/extract_thumbnail.py b/client/ayon_core/plugins/publish/extract_thumbnail.py index 328cb308b9..4ffabf6028 100644 --- a/client/ayon_core/plugins/publish/extract_thumbnail.py +++ b/client/ayon_core/plugins/publish/extract_thumbnail.py @@ -455,13 +455,6 @@ def _create_thumbnail_ffmpeg(self, src_path, dst_path): # output file jpeg_items.append(path_to_subprocess_arg(dst_path)) subprocess_command = " ".join(jpeg_items) - if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): - # Escape parentheses for bash - subprocess_command = ( - subprocess_command - .replace("(", "\\(") - .replace(")", "\\)") - ) try: run_subprocess(