diff --git a/openpype/hosts/fusion/hooks/pre_fusion_setup.py b/openpype/hosts/fusion/hooks/pre_fusion_setup.py index 01b2a37b74..eadcb481e3 100644 --- a/openpype/hosts/fusion/hooks/pre_fusion_setup.py +++ b/openpype/hosts/fusion/hooks/pre_fusion_setup.py @@ -20,32 +20,41 @@ class FusionPrelaunch(PreLaunchHook): """ app_groups = ["fusion"] OPENPYPE_FUSION_PROFILE_DIR = "~/.openpype/hosts/fusion/prefs" + PROFILE_NUMBER = 16 - def get_profile_source(self): - fusion_var_prefs_dir = os.getenv("FUSION16_PROFILE_DIR") + def get_fusion_profile(self) -> str: + return os.getenv(f"FUSION{self.PROFILE_NUMBER}_PROFILE", "Default") + + def get_profile_source(self) -> Path: + fusion_var_prefs_dir = os.getenv(f"FUSION{self.PROFILE_NUMBER}_PROFILE_DIR") + + # if FUSION16_PROFILE_DIR variable exists, return the profile filepath if fusion_var_prefs_dir and Path(fusion_var_prefs_dir).is_dir(): - self.log.info(f"local Fusion prefs environment is set to {fusion_var_prefs_dir}") - return os.path.join(fusion_var_prefs_dir, "Fusion.prefs") - - fusion_prefs_path = "Blackmagic Design/Fusion/Profiles/Default/Fusion.prefs" + fusion_profile = self.get_fusion_profile() + fusion_prefs_dir = Path(fusion_var_prefs_dir, fusion_profile) + self.log.info(f"Local Fusion prefs environment is set to {fusion_prefs_dir}") + fusion_prefs_filepath = fusion_prefs_dir / "Fusion.prefs" + return fusion_prefs_filepath + + # otherwise get the profile from default prefs location + fusion_prefs_path = f"Blackmagic Design/Fusion/Profiles/{fusion_var_prefs_dir}/Fusion.prefs" if platform.system() == "Windows": prefs_source = Path(os.getenv("AppData")) / fusion_prefs_path elif platform.system() == "Darwin": - prefs_source = Path(os.path.expanduser("~/Library/Application Support/")) / fusion_prefs_path + prefs_source = Path("~/Library/Application Support/", fusion_prefs_path).expanduser() elif platform.system() == "Linux": - prefs_source = Path(os.path.expanduser("~/.fusion")) / fusion_prefs_path + prefs_source = Path("~/.fusion", fusion_prefs_path).expanduser() + + return prefs_source - return str(prefs_source) - - def copy_existing_prefs(self, profile_directory: str): - dest_folder = Path(profile_directory) / "Default" + def copy_existing_prefs(self, copy_from: Path, copy_to: Path) -> None: + dest_folder = copy_to / self.get_fusion_profile() dest_folder.mkdir(exist_ok=True, parents=True) - prefs_source = self.get_profile_source() - if not Path(prefs_source).exists(): - self.log.warning(f"Fusion preferences file not found in {prefs_source}") + if not copy_from.exists(): + self.log.warning(f"Fusion preferences file not found in {copy_from}") return - shutil.copy(prefs_source, dest_folder) - self.log.info(f"successfully copied preferences:\n {prefs_source} to {dest_folder}") + shutil.copy(str(copy_from), str(dest_folder)) # compatible with Python >= 3.6 + self.log.info(f"successfully copied preferences:\n {copy_from} to {dest_folder}") def execute(self): # making sure python 3 is installed at provided path @@ -54,12 +63,12 @@ class FusionPrelaunch(PreLaunchHook): py3_var = "FUSION_PYTHON3_HOME" fusion_python3_home = self.launch_context.env.get(py3_var, "") - self.log.info(f"Looking for Python 3 in: {fusion_python3_home}") for path in fusion_python3_home.split(os.pathsep): - # Allow defining multiple paths to allow "fallback" to other + # Allow defining multiple paths, separated by os.pathsep, to allow "fallback" to other # path. But make to set only a single path as final variable. py3_dir = os.path.normpath(path) if os.path.isdir(py3_dir): + self.log.info(f"Looking for Python 3 in: {py3_dir}") break else: raise ApplicationLaunchFailed( @@ -88,14 +97,16 @@ class FusionPrelaunch(PreLaunchHook): profile_dir_var = "FUSION16_PROFILE_DIR" # used by Fusion 16, 17 and 18 pref_var = "FUSION16_MasterPrefs" # used by Fusion 16, 17 and 18 - profile_dir = os.path.expanduser(self.OPENPYPE_FUSION_PROFILE_DIR) - prefs = os.path.join(FUSION_HOST_DIR, "deploy", "fusion_shared.prefs") + op_profile_dir = Path(self.OPENPYPE_FUSION_PROFILE_DIR).expanduser() + op_master_prefs = Path(FUSION_HOST_DIR, "deploy", "fusion_shared.prefs") + prefs_source = self.get_profile_source() + self.log.info(f"Got Fusion prefs file: {prefs_source}") # now copy the default Fusion profile to a working directory # only if the openpype profile folder does not exist - if not os.path.exists(profile_dir): - self.copy_existing_prefs(profile_dir) - self.log.info(f"Setting {profile_dir_var}: {profile_dir}") - self.launch_context.env[profile_dir_var] = profile_dir - self.log.info(f"Setting {pref_var}: {prefs}") - self.launch_context.env[pref_var] = prefs + if not op_profile_dir.exists(): + self.copy_existing_prefs(prefs_source, op_profile_dir) + self.log.info(f"Setting {profile_dir_var}: {op_profile_dir}") + self.launch_context.env[profile_dir_var] = str(op_profile_dir) + self.log.info(f"Setting {pref_var}: {op_master_prefs}") + self.launch_context.env[pref_var] = str(op_master_prefs)