From e7296cd7586c00c41dbdffc657e612caee75d915 Mon Sep 17 00:00:00 2001 From: jmkerloch Date: Thu, 12 Sep 2024 15:34:07 +0200 Subject: [PATCH] feat(profiles): support qgis run in other profiles path than default - closes Profile Manager does not respect --profiles-path start up option #5 --- profile_manager/profile_manager.py | 65 ++------------------- profile_manager/profiles/profile_creator.py | 7 +-- profile_manager/profiles/utils.py | 23 +------- 3 files changed, 9 insertions(+), 86 deletions(-) diff --git a/profile_manager/profile_manager.py b/profile_manager/profile_manager.py index d4f4892..2898112 100644 --- a/profile_manager/profile_manager.py +++ b/profile_manager/profile_manager.py @@ -50,6 +50,7 @@ from profile_manager.profile_manager_dialog import ProfileManagerDialog from profile_manager.profiles.profile_action_handler import ProfileActionHandler from profile_manager.utils import adjust_to_operating_system, wait_cursor +from profile_manager.profiles.utils import qgis_profiles_path, get_profile_qgis_ini_path class ProfileManager: @@ -251,38 +252,7 @@ def run(self): def set_paths(self): """Sets various OS and profile dependent paths""" - home_path = Path.home() - if platform.startswith("win32"): - self.qgis_profiles_path = ( - f"{home_path}/AppData/Roaming/QGIS/QGIS3/profiles".replace("\\", "/") - ) - self.ini_path = ( - self.qgis_profiles_path - + "/" - + self.dlg.comboBoxNamesSource.currentText() - + "/QGIS/QGIS3.ini" - ) - self.operating_system = "windows" - elif platform == "darwin": - self.qgis_profiles_path = ( - f"{home_path}/Library/Application Support/QGIS/QGIS3/profiles" - ) - self.ini_path = ( - self.qgis_profiles_path - + "/" - + self.dlg.comboBoxNamesSource.currentText() - + "/qgis.org/QGIS3.ini" - ) - self.operating_system = "mac" - else: - self.qgis_profiles_path = f"{home_path}/.local/share/QGIS/QGIS3/profiles" - self.ini_path = ( - self.qgis_profiles_path - + "/" - + self.dlg.comboBoxNamesSource.currentText() - + "/QGIS/QGIS3.ini" - ) - self.operating_system = "unix" + self.qgis_profiles_path = str(qgis_profiles_path()) self.backup_path = adjust_to_operating_system( str(Path.home()) + "/QGIS Profile Manager Backup/" @@ -487,36 +457,9 @@ def get_profile_paths(self) -> tuple[str, str]: def get_ini_paths(self): """Gets path to current chosen source and target qgis.ini file""" - if self.operating_system == "mac": - ini_path_source = adjust_to_operating_system( - self.qgis_profiles_path - + "/" - + self.dlg.comboBoxNamesSource.currentText() - + "/qgis.org/QGIS3.ini" - ) - ini_path_target = adjust_to_operating_system( - self.qgis_profiles_path - + "/" - + self.dlg.comboBoxNamesTarget.currentText() - + "/qgis.org/QGIS3.ini" - ) - else: - ini_path_source = adjust_to_operating_system( - self.qgis_profiles_path - + "/" - + self.dlg.comboBoxNamesSource.currentText() - + "/QGIS/QGIS3.ini" - ) - ini_path_target = adjust_to_operating_system( - self.qgis_profiles_path - + "/" - + self.dlg.comboBoxNamesTarget.currentText() - + "/QGIS/QGIS3.ini" - ) - ini_paths = { - "source": ini_path_source, - "target": ini_path_target, + "source": str(get_profile_qgis_ini_path(self.dlg.comboBoxNamesSource.currentText())), + "target": str(get_profile_qgis_ini_path(self.dlg.comboBoxNamesTarget.currentText())), } return ini_paths diff --git a/profile_manager/profiles/profile_creator.py b/profile_manager/profiles/profile_creator.py index 5abc03f..e1a53f6 100644 --- a/profile_manager/profiles/profile_creator.py +++ b/profile_manager/profiles/profile_creator.py @@ -1,4 +1,5 @@ from os import mkdir +from sys import platform from qgis.core import QgsUserProfileManager from qgis.PyQt.QtWidgets import QDialog, QMessageBox @@ -27,10 +28,8 @@ def create_new_profile(self): assert profile_name != "" # should be forced by the GUI self.qgs_profile_manager.createUserProfile(profile_name) try: - if self.profile_manager.operating_system == "mac": - profile_path = ( - self.qgis_path + "/" + profile_name + "/qgis.org/" - ) + if platform is 'darwin': + profile_path = self.qgis_path + "/" + profile_name + "/qgis.org/" else: profile_path = self.qgis_path + "/" + profile_name + "/QGIS/" diff --git a/profile_manager/profiles/utils.py b/profile_manager/profiles/utils.py index 62a13c0..fc8bef2 100644 --- a/profile_manager/profiles/utils.py +++ b/profile_manager/profiles/utils.py @@ -12,31 +12,12 @@ def qgis_profiles_path() -> Path: - """Get QGIS profiles paths from current platforms - - - Windows : $HOME / "AppData" / "Roaming" / "QGIS" / "QGIS3" / "profiles" - - MacOS : $HOME / "Library" / "Application Support" / "QGIS" / "QGIS3" / "profiles" - - Linux : $HOME / ".local" / "share" / "QGIS" / "QGIS3" / "profiles" + """Get QGIS profiles paths from current QGIS application Returns: Path: QGIS profiles path """ - home_path = Path.home() - # Windows - if platform.startswith("win32"): - return home_path / "AppData" / "Roaming" / "QGIS" / "QGIS3" / "profiles" - # MacOS - if platform == "darwin": - return ( - home_path - / "Library" - / "Application Support" - / "QGIS" - / "QGIS3" - / "profiles" - ) - # Linux - return home_path / ".local" / "share" / "QGIS" / "QGIS3" / "profiles" + return Path(iface.userProfileManager().rootLocation()) def get_profile_qgis_ini_path(profile_name: str) -> Path: