From a92126942c7b68ce46cbba077a009ca48b1f5061 Mon Sep 17 00:00:00 2001 From: snennis Date: Thu, 27 Feb 2025 12:22:33 +0100 Subject: [PATCH 1/2] added optional backup feat for user --- profile_manager/profile_manager.py | 17 +- profile_manager/profile_manager_dialog.py | 6 +- .../profile_manager_dialog_base.ui | 146 ++++++++++-------- 3 files changed, 100 insertions(+), 69 deletions(-) diff --git a/profile_manager/profile_manager.py b/profile_manager/profile_manager.py index 9132c45..4bbcc8b 100644 --- a/profile_manager/profile_manager.py +++ b/profile_manager/profile_manager.py @@ -4,6 +4,7 @@ from shutil import copytree from typing import Optional + from qgis.core import Qgis, QgsMessageLog, QgsUserProfileManager from qgis.PyQt.QtCore import QCoreApplication, QLocale, QSettings, QTranslator from qgis.PyQt.QtGui import QIcon @@ -151,17 +152,29 @@ def change_target_profile(self, profile_name: str): self.target_data_sources = collect_data_sources(self.target_qgis_ini_file) self.target_plugins = collect_plugin_names(self.target_qgis_ini_file) - def make_backup(self, profile_name: str) -> Optional[str]: + def make_backup(self, profile_name: str, backup_dir: str) -> Optional[str]: """Creates a backup of the specified profile. Args: profile_name (str): Name of the profile to back up + backup_dir (str): Directory where backup should be stored Returns: str: A message if an error occured. """ + ###################################################################### + backup_path = Path(backup_dir) + + if not backup_path.exists(): + QgsMessageLog.logMessage( + f'invalid backup path: {backup_dir}', + "Profile Manager", + level=Qgis.MessageLevel.Info + ) + # return ? + ###################################################################### ts = int(time.time()) - target_path = self.backup_path / str(ts) + target_path = backup_path / str(ts) source_path = qgis_profiles_path() / profile_name QgsMessageLog.logMessage( f"Backing up profile {profile_name!r} to {target_path!r}", diff --git a/profile_manager/profile_manager_dialog.py b/profile_manager/profile_manager_dialog.py index a6fa0df..5ccc6d9 100644 --- a/profile_manager/profile_manager_dialog.py +++ b/profile_manager/profile_manager_dialog.py @@ -2,10 +2,12 @@ from pathlib import Path from typing import Literal, Optional +from PyQt5.QtWidgets import QFileDialog from qgis.core import QgsApplication from qgis.PyQt import QtWidgets, uic from qgis.PyQt.QtCore import QSize, Qt from qgis.PyQt.QtWidgets import QDialog, QListWidget, QMessageBox, QTreeWidget +from tenacity import sleep from profile_manager.gui.mdl_profiles import ProfileListModel from profile_manager.gui.name_profile_dialog import NameProfileDialog @@ -163,8 +165,10 @@ def _set_qdt_profile_infos(self, qdt_profile_infos: QDTProfileInfos) -> None: def export_qdt_handler(self) -> None: """Export selected profile as QDT profile""" profile_path = self.qdt_file_widget.filePath() - if profile_path: + backup_path = self.qdt_backup_file_widget.filePath() # NEW sets backup_path from Widget + if profile_path and backup_path: # NEW check for both source_profile_name = self.qdt_export_profile_cbx.currentText() + make = self.__profile_manager.make_backup(source_profile_name, backup_path) # NEW idk how to name it tbh export_profile_for_qdt( profile_name=source_profile_name, export_path=Path(profile_path), diff --git a/profile_manager/profile_manager_dialog_base.ui b/profile_manager/profile_manager_dialog_base.ui index c83e1a0..318c03e 100644 --- a/profile_manager/profile_manager_dialog_base.ui +++ b/profile_manager/profile_manager_dialog_base.ui @@ -6,8 +6,8 @@ 0 0 - 701 - 503 + 808 + 673 @@ -20,7 +20,7 @@ - 0 + 2 @@ -350,7 +350,56 @@ QDT Export - + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Export + + + + + + + + + + QgsFileWidget::GetDirectory + + + + + + + + + + + + + Export inactive plugins + + + + + + + @@ -363,107 +412,72 @@ - - + + - QGIS min. version + Export folder - - + + - Description + Clear export folder - - - - - + + - Email + QGIS min. version - - - - - - - - + + - Clear export folder + QGIS max. version - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + - Export inactive plugins + Email - + Version - - + + - Export + Description - - + + + + + - QGIS max. version + Backup folder - - - - - - - - + + QgsFileWidget::GetDirectory - - - - Export folder - - - From ccddd7a5262499bfa900f3232d941331ebfe597c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 27 Feb 2025 14:00:49 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- profile_manager/profile_manager.py | 5 ++--- profile_manager/profile_manager_dialog.py | 12 +++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/profile_manager/profile_manager.py b/profile_manager/profile_manager.py index 4bbcc8b..d747517 100644 --- a/profile_manager/profile_manager.py +++ b/profile_manager/profile_manager.py @@ -4,7 +4,6 @@ from shutil import copytree from typing import Optional - from qgis.core import Qgis, QgsMessageLog, QgsUserProfileManager from qgis.PyQt.QtCore import QCoreApplication, QLocale, QSettings, QTranslator from qgis.PyQt.QtGui import QIcon @@ -167,9 +166,9 @@ def make_backup(self, profile_name: str, backup_dir: str) -> Optional[str]: if not backup_path.exists(): QgsMessageLog.logMessage( - f'invalid backup path: {backup_dir}', + f"invalid backup path: {backup_dir}", "Profile Manager", - level=Qgis.MessageLevel.Info + level=Qgis.MessageLevel.Info, ) # return ? ###################################################################### diff --git a/profile_manager/profile_manager_dialog.py b/profile_manager/profile_manager_dialog.py index 5ccc6d9..7c980de 100644 --- a/profile_manager/profile_manager_dialog.py +++ b/profile_manager/profile_manager_dialog.py @@ -2,12 +2,10 @@ from pathlib import Path from typing import Literal, Optional -from PyQt5.QtWidgets import QFileDialog from qgis.core import QgsApplication from qgis.PyQt import QtWidgets, uic from qgis.PyQt.QtCore import QSize, Qt from qgis.PyQt.QtWidgets import QDialog, QListWidget, QMessageBox, QTreeWidget -from tenacity import sleep from profile_manager.gui.mdl_profiles import ProfileListModel from profile_manager.gui.name_profile_dialog import NameProfileDialog @@ -165,10 +163,14 @@ def _set_qdt_profile_infos(self, qdt_profile_infos: QDTProfileInfos) -> None: def export_qdt_handler(self) -> None: """Export selected profile as QDT profile""" profile_path = self.qdt_file_widget.filePath() - backup_path = self.qdt_backup_file_widget.filePath() # NEW sets backup_path from Widget - if profile_path and backup_path: # NEW check for both + backup_path = ( + self.qdt_backup_file_widget.filePath() + ) # NEW sets backup_path from Widget + if profile_path and backup_path: # NEW check for both source_profile_name = self.qdt_export_profile_cbx.currentText() - make = self.__profile_manager.make_backup(source_profile_name, backup_path) # NEW idk how to name it tbh + make = self.__profile_manager.make_backup( + source_profile_name, backup_path + ) # NEW idk how to name it tbh export_profile_for_qdt( profile_name=source_profile_name, export_path=Path(profile_path),