diff options
author | Papoteur <papoteur@mageia.org> | 2024-02-08 19:19:48 +0100 |
---|---|---|
committer | Papoteur <papoteur@mageia.org> | 2024-02-08 19:19:48 +0100 |
commit | c4c331684bfdcf845b3031626d345d3043a261ce (patch) | |
tree | 0790ecc4d2550e5d4a203fa2ab92e132c6e4a566 | |
parent | 053612db41a9135968b927ee34888299c48e737a (diff) | |
download | mga-advisor-c4c331684bfdcf845b3031626d345d3043a261ce.tar mga-advisor-c4c331684bfdcf845b3031626d345d3043a261ce.tar.gz mga-advisor-c4c331684bfdcf845b3031626d345d3043a261ce.tar.bz2 mga-advisor-c4c331684bfdcf845b3031626d345d3043a261ce.tar.xz mga-advisor-c4c331684bfdcf845b3031626d345d3043a261ce.zip |
Add configuration file, with path for advisories
-rw-r--r-- | mga-advisor.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/mga-advisor.py b/mga-advisor.py index 8f30f0d..c552fb0 100644 --- a/mga-advisor.py +++ b/mga-advisor.py @@ -13,6 +13,7 @@ from PySide6.QtWidgets import ( QApplication, QWidget, QDialog, + QFileDialog, QLineEdit, QPushButton, QVBoxLayout, @@ -22,7 +23,7 @@ from PySide6.QtWidgets import ( QTextEdit, ) from PySide6.QtGui import QCursor -from PySide6.QtCore import QFile, QDate, QDir, Qt, QTimer +from PySide6.QtCore import QFile, QDate, QDir, Qt, QTimer, QSettings from PySide6.QtUiTools import QUiLoader BASE_URL = "https://bugs.mageia.org/rest/bug/" @@ -72,6 +73,7 @@ class Widget(QWidget): super().__init__(parent) self.load_ui() self.setWindowTitle("Mageia advisor") + self.settings = QSettings("Mageia","advisor") def load_ui(self): loader = QUiLoader() @@ -88,6 +90,7 @@ class Widget(QWidget): self.ui.add_ref_pb.clicked.connect(self.add_reference) self.ui.remove_ref_pb.clicked.connect(self.remove_reference) self.ui.export_pb.clicked.connect(self.export) + self.ui.configuration_pb.clicked.connect(self.select_path) self.ui.cancel_pb.clicked.connect(self.cancel) self.ui.preview_pb.clicked.connect(self.preview) self.ui.bug_le.editingFinished.connect(self.valid_number) @@ -97,11 +100,8 @@ class Widget(QWidget): """ Retrieve CVEs, URLs and Source package name from the bug report given by its number """ - if self.ui.bug_le.text() == "": - mb = QMessageBox(QMessageBox.Warning, "Retrieve info", "Provide a bug number first", QMessageBox.Ok) - mb.exec() + if not self.valid_number(): return - self.valid_number() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) self.clean() self.ui.status.setText("Loading...") @@ -255,10 +255,12 @@ class Widget(QWidget): return yaml.dump(data, default_flow_style=False, sort_keys=False, width=75, allow_unicode=True) def export(self): - if QDir().mkpath(QDir().homePath() + "/mageia-advisories/advisories"): + if not self.valid_number(): + return + default_path = self.settings.value("Default/path", "/mageia-advisories/advisories") + if QDir().mkpath(QDir().homePath() + default_path): if self.ui.bug_le.text() != "": - - filename = f"{QDir().homePath()}/mageia-advisories/advisories/{self.ui.bug_le.text()}.adv" + filename = os.path.join(QDir().homePath(), default_path, f"{self.ui.bug_le.text()}.adv") if os.path.exists(filename): response = QMessageBox.question(self, 'File exists', f'The file {filename} already exists. Do you want to override it ?', QMessageBox.Yes | QMessageBox.No) if response == QMessageBox.No: @@ -267,6 +269,11 @@ class Widget(QWidget): f.write(self.adv_text()) QMessageBox.information(self, 'Success', f'The file {filename} has been written!') + def select_path(self): + filepath = QFileDialog.getExistingDirectory(self, "Select default directory for advisories repository", self.settings.value("Default/path")) + if filepath: + self.settings.setValue('Default/path', filepath) + def cancel(self): self.close() @@ -292,7 +299,12 @@ class Widget(QWidget): return "" def valid_number(self): + if self.ui.bug_le.text() == "": + mb = QMessageBox(QMessageBox.Warning, "Retrieve info", "Provide a bug number first", QMessageBox.Ok) + mb.exec() + return False self.ui.bug_le.setText(re.sub(r'\D', '', self.ui.bug_le.text())) + return True def src_populate(self, package): # retrieve information with repo, release from package name |