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 Oct 2, 2024
1 parent 65e7da8 commit 107b7c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 86 deletions.
65 changes: 4 additions & 61 deletions profile_manager/profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/"
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions profile_manager/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.core import QgsUserProfileManager
from qgis.PyQt.QtWidgets import QDialog, QMessageBox
Expand Down Expand Up @@ -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/"

Expand Down
23 changes: 2 additions & 21 deletions profile_manager/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 107b7c3

Please sign in to comment.