From 6376692fec24267af13f7900e2ac60fd65aed373 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Tue, 22 Aug 2023 13:56:47 +0200 Subject: [PATCH 1/4] :recycle: use temp dir for project creation --- .../unreal/hooks/pre_workfile_preparation.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py index 202d7854f64..fad7a7ed0b9 100644 --- a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py +++ b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py @@ -2,6 +2,7 @@ """Hook to launch Unreal and prepare projects.""" import os import copy +import tempfile from pathlib import Path from qtpy import QtCore @@ -224,10 +225,19 @@ def execute(self): project_file = project_path / unreal_project_filename if not project_file.is_file(): - self.exec_ue_project_gen(engine_version, - unreal_project_name, - engine_path, - project_path) + with tempfile.TemporaryDirectory() as temp_dir: + temp_path = Path(temp_dir) / unreal_project_filename + self.exec_ue_project_gen(engine_version, + unreal_project_name, + engine_path, + temp_path) + try: + temp_path.rename(project_path) + except FileExistsError as e: + raise ApplicationLaunchFailed(( + f"{self.signature} Project folder " + f"already exists {project_path.as_posix()}" + )) from e self.launch_context.env["AYON_UNREAL_VERSION"] = engine_version # Append project file to launch arguments From 92165f521ef5f51e46758b3068083339f8d7a14d Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Tue, 22 Aug 2023 15:41:24 +0200 Subject: [PATCH 2/4] :bug: fix copy function --- .../unreal/hooks/pre_workfile_preparation.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py index fad7a7ed0b9..fb489f04f73 100644 --- a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py +++ b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py @@ -2,6 +2,7 @@ """Hook to launch Unreal and prepare projects.""" import os import copy +import shutil import tempfile from pathlib import Path @@ -230,13 +231,19 @@ def execute(self): self.exec_ue_project_gen(engine_version, unreal_project_name, engine_path, - temp_path) + Path(temp_dir)) try: - temp_path.rename(project_path) - except FileExistsError as e: + self.log.info(( + f"Moving from {temp_dir} to " + f"{project_path.as_posix()}" + )) + shutil.copytree( + temp_dir, project_path, dirs_exist_ok=True) + + except shutil.Error as e: raise ApplicationLaunchFailed(( - f"{self.signature} Project folder " - f"already exists {project_path.as_posix()}" + f"{self.signature} Cannot copy directory {temp_dir} " + f"to {project_path.as_posix()} - {e}" )) from e self.launch_context.env["AYON_UNREAL_VERSION"] = engine_version From c2b49a897eee6c33e405a3229bd48bcaee6c8178 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Tue, 22 Aug 2023 15:43:48 +0200 Subject: [PATCH 3/4] :recycle: remove unused variable --- openpype/hosts/unreal/hooks/pre_workfile_preparation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py index fb489f04f73..efbbed27c80 100644 --- a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py +++ b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py @@ -227,7 +227,6 @@ def execute(self): if not project_file.is_file(): with tempfile.TemporaryDirectory() as temp_dir: - temp_path = Path(temp_dir) / unreal_project_filename self.exec_ue_project_gen(engine_version, unreal_project_name, engine_path, From 92000bc21e03d3ddf1fc99a62421ead1f278865f Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Tue, 22 Aug 2023 15:48:19 +0200 Subject: [PATCH 4/4] :rotating_light: fix hound :dog: --- openpype/hosts/unreal/hooks/pre_workfile_preparation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py index efbbed27c80..a635bd4cab9 100644 --- a/openpype/hosts/unreal/hooks/pre_workfile_preparation.py +++ b/openpype/hosts/unreal/hooks/pre_workfile_preparation.py @@ -233,8 +233,8 @@ def execute(self): Path(temp_dir)) try: self.log.info(( - f"Moving from {temp_dir} to " - f"{project_path.as_posix()}" + f"Moving from {temp_dir} to " + f"{project_path.as_posix()}" )) shutil.copytree( temp_dir, project_path, dirs_exist_ok=True)