From 30cadfd6ad989317710f2668643e6df4e9e902bf Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 20 Sep 2021 13:09:01 +0200 Subject: [PATCH 1/3] don't use 'split_command_to_list' which may break paths if they are incorrectly used --- .../plugins/publish/extract_thumbnail.py | 5 +--- openpype/lib/__init__.py | 2 -- openpype/lib/execute.py | 30 ------------------- openpype/plugins/publish/extract_jpeg_exr.py | 4 +-- .../publish/extract_otio_audio_tracks.py | 6 +--- openpype/plugins/publish/extract_review.py | 8 ++--- .../plugins/publish/extract_review_slate.py | 8 ++--- 7 files changed, 8 insertions(+), 55 deletions(-) diff --git a/openpype/hosts/standalonepublisher/plugins/publish/extract_thumbnail.py b/openpype/hosts/standalonepublisher/plugins/publish/extract_thumbnail.py index cdbfe942f0..d5eb0a8a45 100644 --- a/openpype/hosts/standalonepublisher/plugins/publish/extract_thumbnail.py +++ b/openpype/hosts/standalonepublisher/plugins/publish/extract_thumbnail.py @@ -101,14 +101,11 @@ class ExtractThumbnailSP(pyblish.api.InstancePlugin): jpeg_items.append("\"{}\"".format(full_thumbnail_path)) subprocess_jpeg = " ".join(jpeg_items) - subprocess_args = openpype.lib.split_command_to_list( - subprocess_jpeg - ) # run subprocess self.log.debug("Executing: {}".format(" ".join(subprocess_args))) openpype.api.run_subprocess( - subprocess_args, shell=True, logger=self.log + subprocess_jpeg, shell=True, logger=self.log ) # remove thumbnail key from origin repre diff --git a/openpype/lib/__init__.py b/openpype/lib/__init__.py index 4cf4a2f8ef..74004a1239 100644 --- a/openpype/lib/__init__.py +++ b/openpype/lib/__init__.py @@ -27,7 +27,6 @@ from .execute import ( get_pype_execute_args, execute, run_subprocess, - split_command_to_list, path_to_subprocess_arg, CREATE_NO_WINDOW ) @@ -174,7 +173,6 @@ __all__ = [ "get_pype_execute_args", "execute", "run_subprocess", - "split_command_to_list", "path_to_subprocess_arg", "CREATE_NO_WINDOW", diff --git a/openpype/lib/execute.py b/openpype/lib/execute.py index 3e5b6d3853..a1111fba29 100644 --- a/openpype/lib/execute.py +++ b/openpype/lib/execute.py @@ -147,36 +147,6 @@ def path_to_subprocess_arg(path): return subprocess.list2cmdline([path]) -def split_command_to_list(string_command): - """Split string subprocess command to list. - - Should be able to split complex subprocess command to separated arguments: - `"C:\\ffmpeg folder\\ffmpeg.exe" -i \"D:\\input.mp4\\" \"D:\\output.mp4\"` - - Should result into list: - `["C:\ffmpeg folder\ffmpeg.exe", "-i", "D:\input.mp4", "D:\output.mp4"]` - - This may be required on few versions of python where subprocess can handle - only list of arguments. - - To be able do that is using `shlex` python module. - - Args: - string_command(str): Full subprocess command. - - Returns: - list: Command separated into individual arguments. - """ - if not string_command: - return [] - - kwargs = {} - # Use 'posix' argument only on windows - if platform.system().lower() == "windows": - kwargs["posix"] = False - return shlex.split(string_command, **kwargs) - - def get_pype_execute_args(*args): """Arguments to run pype command. diff --git a/openpype/plugins/publish/extract_jpeg_exr.py b/openpype/plugins/publish/extract_jpeg_exr.py index 31e58025d5..725afb57e7 100644 --- a/openpype/plugins/publish/extract_jpeg_exr.py +++ b/openpype/plugins/publish/extract_jpeg_exr.py @@ -5,7 +5,6 @@ from openpype.lib import ( get_ffmpeg_tool_path, run_subprocess, - split_command_to_list, path_to_subprocess_arg, should_decompress, @@ -116,13 +115,12 @@ class ExtractJpegEXR(pyblish.api.InstancePlugin): jpeg_items.append(path_to_subprocess_arg(full_output_path)) subprocess_command = " ".join(jpeg_items) - subprocess_args = split_command_to_list(subprocess_command) # run subprocess self.log.debug("{}".format(subprocess_command)) try: # temporary until oiiotool is supported cross platform run_subprocess( - subprocess_args, shell=True, logger=self.log + subprocess_command, shell=True, logger=self.log ) except RuntimeError as exp: if "Compression" in str(exp): diff --git a/openpype/plugins/publish/extract_otio_audio_tracks.py b/openpype/plugins/publish/extract_otio_audio_tracks.py index 2cdc072ffd..9750a6df22 100644 --- a/openpype/plugins/publish/extract_otio_audio_tracks.py +++ b/openpype/plugins/publish/extract_otio_audio_tracks.py @@ -3,7 +3,6 @@ import pyblish import openpype.api from openpype.lib import ( get_ffmpeg_tool_path, - split_command_to_list, path_to_subprocess_arg ) import tempfile @@ -62,13 +61,10 @@ class ExtractOtioAudioTracks(pyblish.api.ContextPlugin): cmd += self.create_cmd(audio_inputs) cmd += path_to_subprocess_arg(audio_temp_fpath) - # Split command to list for subprocess - cmd_list = split_command_to_list(cmd) - # run subprocess self.log.debug("Executing: {}".format(cmd)) openpype.api.run_subprocess( - cmd_list, logger=self.log + cmd, logger=self.log ) # remove empty diff --git a/openpype/plugins/publish/extract_review.py b/openpype/plugins/publish/extract_review.py index ecc49a8da6..f5d6789dd4 100644 --- a/openpype/plugins/publish/extract_review.py +++ b/openpype/plugins/publish/extract_review.py @@ -14,7 +14,6 @@ from openpype.lib import ( get_ffmpeg_tool_path, ffprobe_streams, - split_command_to_list, path_to_subprocess_arg, should_decompress, @@ -220,15 +219,12 @@ class ExtractReview(pyblish.api.InstancePlugin): raise NotImplementedError subprcs_cmd = " ".join(ffmpeg_args) - subprocess_args = split_command_to_list(subprcs_cmd) # run subprocess - self.log.debug( - "Executing: {}".format(" ".join(subprocess_args)) - ) + self.log.debug("Executing: {}".format(subprcs_cmd)) openpype.api.run_subprocess( - subprocess_args, shell=True, logger=self.log + subprcs_cmd, shell=True, logger=self.log ) # delete files added to fill gaps diff --git a/openpype/plugins/publish/extract_review_slate.py b/openpype/plugins/publish/extract_review_slate.py index 4d26fd1ebc..aed146bb69 100644 --- a/openpype/plugins/publish/extract_review_slate.py +++ b/openpype/plugins/publish/extract_review_slate.py @@ -200,16 +200,14 @@ class ExtractReviewSlate(openpype.api.Extractor): " ".join(input_args), " ".join(output_args) ] - slate_subprocess_args = openpype.lib.split_command_to_list( - " ".join(slate_args) - ) + slate_subprocess_cmd = " ".join(slate_args) # run slate generation subprocess self.log.debug( - "Slate Executing: {}".format(" ".join(slate_subprocess_args)) + "Slate Executing: {}".format(slate_subprocess_cmd) ) openpype.api.run_subprocess( - slate_subprocess_args, shell=True, logger=self.log + slate_subprocess_cmd, shell=True, logger=self.log ) # create ffmpeg concat text file path From a19ffc1e56e17f765c416ffa3a8ee821ae229d14 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 21 Sep 2021 10:39:38 +0200 Subject: [PATCH 2/3] added shell=True back where command is executed as string --- openpype/plugins/publish/extract_jpeg_exr.py | 2 +- openpype/plugins/publish/extract_otio_audio_tracks.py | 2 +- openpype/plugins/publish/extract_review.py | 2 +- openpype/plugins/publish/extract_review_slate.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openpype/plugins/publish/extract_jpeg_exr.py b/openpype/plugins/publish/extract_jpeg_exr.py index 48db35801e..3c08c1862d 100644 --- a/openpype/plugins/publish/extract_jpeg_exr.py +++ b/openpype/plugins/publish/extract_jpeg_exr.py @@ -120,7 +120,7 @@ class ExtractJpegEXR(pyblish.api.InstancePlugin): self.log.debug("{}".format(subprocess_command)) try: # temporary until oiiotool is supported cross platform run_subprocess( - subprocess_command, logger=self.log + subprocess_command, shell=True, logger=self.log ) except RuntimeError as exp: if "Compression" in str(exp): diff --git a/openpype/plugins/publish/extract_otio_audio_tracks.py b/openpype/plugins/publish/extract_otio_audio_tracks.py index 9750a6df22..be0bae5cdc 100644 --- a/openpype/plugins/publish/extract_otio_audio_tracks.py +++ b/openpype/plugins/publish/extract_otio_audio_tracks.py @@ -64,7 +64,7 @@ class ExtractOtioAudioTracks(pyblish.api.ContextPlugin): # run subprocess self.log.debug("Executing: {}".format(cmd)) openpype.api.run_subprocess( - cmd, logger=self.log + cmd, shell=True, logger=self.log ) # remove empty diff --git a/openpype/plugins/publish/extract_review.py b/openpype/plugins/publish/extract_review.py index a6d652f00b..f5d6789dd4 100644 --- a/openpype/plugins/publish/extract_review.py +++ b/openpype/plugins/publish/extract_review.py @@ -224,7 +224,7 @@ class ExtractReview(pyblish.api.InstancePlugin): self.log.debug("Executing: {}".format(subprcs_cmd)) openpype.api.run_subprocess( - subprcs_cmd, logger=self.log + subprcs_cmd, shell=True, logger=self.log ) # delete files added to fill gaps diff --git a/openpype/plugins/publish/extract_review_slate.py b/openpype/plugins/publish/extract_review_slate.py index c3f8c78c61..7002168cdb 100644 --- a/openpype/plugins/publish/extract_review_slate.py +++ b/openpype/plugins/publish/extract_review_slate.py @@ -207,7 +207,7 @@ class ExtractReviewSlate(openpype.api.Extractor): "Slate Executing: {}".format(slate_subprocess_cmd) ) openpype.api.run_subprocess( - slate_subprocess_cmd, logger=self.log + slate_subprocess_cmd, shell=True, logger=self.log ) # create ffmpeg concat text file path From 4343cf7e27dae1566522e956327220374090f00e Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 21 Sep 2021 10:41:00 +0200 Subject: [PATCH 3/3] one more plugin where ffmpeg command is used as string --- .../standalonepublisher/plugins/publish/extract_thumbnail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/standalonepublisher/plugins/publish/extract_thumbnail.py b/openpype/hosts/standalonepublisher/plugins/publish/extract_thumbnail.py index ab079f6c9c..24690cb840 100644 --- a/openpype/hosts/standalonepublisher/plugins/publish/extract_thumbnail.py +++ b/openpype/hosts/standalonepublisher/plugins/publish/extract_thumbnail.py @@ -105,7 +105,7 @@ class ExtractThumbnailSP(pyblish.api.InstancePlugin): # run subprocess self.log.debug("Executing: {}".format(subprocess_jpeg)) openpype.api.run_subprocess( - subprocess_jpeg, logger=self.log + subprocess_jpeg, shell=True, logger=self.log ) # remove thumbnail key from origin repre