Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and jmkerloch committed Oct 3, 2024
1 parent a42e122 commit 016484e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 41 deletions.
5 changes: 2 additions & 3 deletions profile_manager/gui/interface_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from pathlib import Path

from qgis.core import Qgis, QgsApplication, QgsMessageLog
from qgis.PyQt.QtCore import Qt, QVariant
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QDialog, QListWidgetItem
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog

from profile_manager.datasources.dataservices.datasource_provider import (
DATA_SOURCE_SEARCH_LOCATIONS,
Expand Down
5 changes: 3 additions & 2 deletions profile_manager/gui/mdl_profiles.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pathlib import Path
from qgis.PyQt.QtCore import QObject, Qt, QModelIndex

from qgis.core import QgsApplication, QgsUserProfile, QgsUserProfileManager
from qgis.PyQt.QtCore import QModelIndex, QObject, Qt
from qgis.PyQt.QtGui import QStandardItemModel
from qgis.core import QgsUserProfileManager, QgsUserProfile, QgsApplication

from profile_manager.profiles.utils import qgis_profiles_path

Expand Down
13 changes: 8 additions & 5 deletions profile_manager/profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from os import path
from pathlib import Path
from shutil import copytree
from sys import platform

# PyQGIS
from qgis.core import Qgis, QgsMessageLog, QgsUserProfileManager
Expand All @@ -49,8 +48,8 @@
from profile_manager.gui.interface_handler import InterfaceHandler
from profile_manager.profile_manager_dialog import ProfileManagerDialog
from profile_manager.profiles.profile_action_handler import ProfileActionHandler
from profile_manager.profiles.utils import get_profile_qgis_ini_path, qgis_profiles_path
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 @@ -252,7 +251,7 @@ def run(self):

def set_paths(self):
"""Sets various OS and profile dependent paths"""
self.qgis_profiles_path = str(qgis_profiles_path())
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 @@ -458,8 +457,12 @@ def get_profile_paths(self) -> tuple[str, str]:
def get_ini_paths(self):
"""Gets path to current chosen source and target qgis.ini file"""
ini_paths = {
"source": str(get_profile_qgis_ini_path(self.dlg.comboBoxNamesSource.currentText())),
"target": str(get_profile_qgis_ini_path(self.dlg.comboBoxNamesTarget.currentText())),
"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
35 changes: 18 additions & 17 deletions profile_manager/profile_manager_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@

# plugin
from profile_manager.gui.mdl_profiles import ProfileListModel
from profile_manager.qdt_export.profile_export import export_profile_for_qdt, get_qdt_profile_infos_from_file, QDTProfileInfos
from profile_manager.qdt_export.profile_export import (
QDTProfileInfos,
export_profile_for_qdt,
get_qdt_profile_infos_from_file,
)

# This loads your .ui file so that PyQt can populate your plugin with the elements from Qt Designer
FORM_CLASS, _ = uic.loadUiType(
Expand Down Expand Up @@ -71,7 +75,7 @@ def get_list_selection_profile_name(self) -> Optional[str]:
if index.isValid():
return self.list_profiles.model().data(index, ProfileListModel.NAME_COL)
return None

def _qdt_export_dir_changed(self) -> None:
"""Update UI when QDT export dir is changed:
- enabled/disable button
Expand All @@ -82,26 +86,27 @@ def _qdt_export_dir_changed(self) -> None:
self.export_qdt_button.setEnabled(True)
profile_json = Path(export_dir) / "profile.json"
if profile_json.exists():
self._set_qdt_profile_infos(get_qdt_profile_infos_from_file(profile_json))
self._set_qdt_profile_infos(
get_qdt_profile_infos_from_file(profile_json)
)
else:
self.export_qdt_button.setEnabled(False)


def _get_qdt_profile_infos(self) -> QDTProfileInfos:
"""Get QDTProfileInfos from UI
Returns:
QDTProfileInfos: QDT Profile Information
"""
return QDTProfileInfos(
description=self.qdt_description_edit.toPlainText(),
email=self.qdt_email_edit.text(),
version=self.qdt_version_edit.text(),
qgis_min_version=self.qdt_qgis_min_version_edit.text(),
qgis_max_version=self.qdt_qgis_max_version_edit.text(),
)

def _set_qdt_profile_infos(self, qdt_profile_infos : QDTProfileInfos) -> None:
description=self.qdt_description_edit.toPlainText(),
email=self.qdt_email_edit.text(),
version=self.qdt_version_edit.text(),
qgis_min_version=self.qdt_qgis_min_version_edit.text(),
qgis_max_version=self.qdt_qgis_max_version_edit.text(),
)

def _set_qdt_profile_infos(self, qdt_profile_infos: QDTProfileInfos) -> None:
"""Set QDTProfileInfos in UI
Args:
Expand All @@ -128,9 +133,5 @@ def export_qdt_handler(self) -> None:
QMessageBox.information(
self,
self.tr("QDT profile export"),
self.tr(
"QDT profile have been successfully exported."
),
self.tr("QDT profile have been successfully exported."),
)


6 changes: 4 additions & 2 deletions profile_manager/profiles/profile_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def create_new_profile(self):
assert profile_name != "" # should be forced by the GUI
self.qgs_profile_manager.createUserProfile(profile_name)
try:
if platform is 'darwin':
profile_path = self.qgis_path + "/" + profile_name + "/qgis.org/"
if platform == "darwin":
profile_path = (
self.qgis_path + "/" + profile_name + "/qgis.org/"
)
else:
profile_path = self.qgis_path + "/" + profile_name + "/QGIS/"

Expand Down
8 changes: 3 additions & 5 deletions profile_manager/profiles/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from configparser import NoSectionError, RawConfigParser
from dataclasses import dataclass
from pathlib import Path
from sys import platform
from typing import Any, Dict, List, Optional
from configparser import NoSectionError, RawConfigParser


import pyplugin_installer
from qgis.core import QgsUserProfileManager
from qgis.utils import iface

import pyplugin_installer


def qgis_profiles_path() -> Path:
"""Get QGIS profiles paths from current QGIS application
Expand Down Expand Up @@ -105,7 +103,7 @@ def get_installed_plugin_metadata(


def get_plugin_info_from_qgis_manager(
plugin_slug_name: str, reload_manager : bool = False
plugin_slug_name: str, reload_manager: bool = False
) -> Optional[Dict[str, str]]:
"""Get plugin informations from QGIS plugin manager
Expand Down
13 changes: 6 additions & 7 deletions profile_manager/qdt_export/profile_export.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from dataclasses import dataclass
import dataclasses
import json
from dataclasses import dataclass
from pathlib import Path
from shutil import copytree, rmtree
from typing import Any, Dict

import json

import pyplugin_installer

from profile_manager.profiles.utils import (
qgis_profiles_path,
get_profile_plugin_list_information,
qgis_profiles_path,
)


QDT_PROFILE_SCHEMA = "https://raw.githubusercontent.com/Guts/qgis-deployment-cli/main/docs/schemas/profile/qgis_profile.json"


Expand All @@ -28,7 +26,7 @@ class QDTProfileInfos:
qgis_max_version: str = ""


def get_qdt_profile_infos_from_file(profile_file : Path) -> QDTProfileInfos:
def get_qdt_profile_infos_from_file(profile_file: Path) -> QDTProfileInfos:
"""Get QDT Profile informations from a profile.json file
File must exists
Expand All @@ -38,7 +36,7 @@ def get_qdt_profile_infos_from_file(profile_file : Path) -> QDTProfileInfos:
Returns:
QDTProfileInfos: QDT Profile informations
"""
with open(profile_file, 'r') as f:
with open(profile_file, "r") as f:
qdt_profile_data = json.load(f)
return QDTProfileInfos(
description=qdt_profile_data.get("description", ""),
Expand All @@ -48,6 +46,7 @@ def get_qdt_profile_infos_from_file(profile_file : Path) -> QDTProfileInfos:
qgis_max_version=qdt_profile_data.get("qgisMaximumVersion", ""),
)


def qdt_profile_dict(
profile_name: str,
qdt_profile_infos: QDTProfileInfos,
Expand Down

0 comments on commit 016484e

Please sign in to comment.