From 053612db41a9135968b927ee34888299c48e737a Mon Sep 17 00:00:00 2001 From: Papoteur Date: Wed, 7 Feb 2024 23:12:57 +0100 Subject: Add dialog to confirm overwriting the file --- mga-advisor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mga-advisor.py b/mga-advisor.py index a8e01c5..8f30f0d 100644 --- a/mga-advisor.py +++ b/mga-advisor.py @@ -136,7 +136,7 @@ class Widget(QWidget): cve = cve.strip() if cve != "": self.ui.list_cve.addItem(cve) - self.ui.list_ref.addItem(f"https://bugs.mageia.org/show_bug.cgi?id={self.ui.bug_le.text()}") + self.ui.list_ref.addItem(os.path.join(BASE_URL, self.ui.bug_le.text()) ) for url in re.split(';|,| ', r.json()['bugs'][0]['url']): url = url.strip() if url != "": @@ -257,9 +257,15 @@ class Widget(QWidget): def export(self): if QDir().mkpath(QDir().homePath() + "/mageia-advisories/advisories"): if self.ui.bug_le.text() != "": - #TODO check that it exists - with open(f"{QDir().homePath()}/mageia-advisories/advisories/{self.ui.bug_le.text()}.adv", 'w') as f: + + filename = f"{QDir().homePath()}/mageia-advisories/advisories/{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: + return + with open(filename, 'w') as f: f.write(self.adv_text()) + QMessageBox.information(self, 'Success', f'The file {filename} has been written!') def cancel(self): self.close() -- cgit v1.2.1