Skip to content

Commit

Permalink
feat(profiles): support qgis run in other profiles path than default
Browse files Browse the repository at this point in the history
- closes Profile Manager does not respect --profiles-path start up option WhereGroup#5
  • Loading branch information
jmkerloch committed Sep 12, 2024
1 parent 45f7861 commit 1573993
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 53 deletions.
36 changes: 5 additions & 31 deletions profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .profiles.profile_action_handler import ProfileActionHandler
from .userInterface.interface_handler import InterfaceHandler
from .utils import adjust_to_operating_system, wait_cursor
from .profiles.utils import qgis_profiles_path, get_profile_qgis_ini_path


class ProfileManager:
Expand All @@ -57,8 +58,6 @@ def __init__(self, iface):
self.is_ok_button_clicked = False
self.backup_path = ""
self.qgis_profiles_path = ""
self.ini_path = ""
self.operating_system = ""
self.qgs_profile_manager = None # TODO in QGIS 3.30 we could and should use iface.userProfileManager()
self.data_source_handler: DataSourceHandler = None
self.profile_manager_action_handler: ProfileActionHandler = None
Expand Down Expand Up @@ -234,23 +233,9 @@ 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 is '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"
self.qgis_profiles_path = str(qgis_profiles_path())
if platform is 'darwin':
self.interface_handler.adjust_to_macOSDark()
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.backup_path = adjust_to_operating_system(str(Path.home()) + "/QGIS Profile Manager Backup/")

Expand Down Expand Up @@ -412,20 +397,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
Expand Down
3 changes: 2 additions & 1 deletion profiles/profile_creator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os import mkdir
from sys import platform

from qgis.PyQt.QtWidgets import QDialog, QMessageBox
from qgis.core import QgsUserProfileManager
Expand Down Expand Up @@ -27,7 +28,7 @@ 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 is "mac":
if platform is 'darwin':
profile_path = self.qgis_path + "/" + profile_name + "/qgis.org/"
else:
profile_path = self.qgis_path + "/" + profile_name + "/QGIS/"
Expand Down
23 changes: 2 additions & 21 deletions profiles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1573993

Please sign in to comment.