summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageia.org>2023-11-05 16:18:52 +0100
committerPapoteur <papoteur@mageia.org>2023-11-05 16:18:52 +0100
commita8a283de5727b8551b0a29119052e9d5bf0d0ef6 (patch)
tree16c366488f9c905a68da3368bcd5e0c9f769fd83
parent9eec4fe9f1850fbb53749776c186af5698dc85f8 (diff)
downloadmga-advisor-a8a283de5727b8551b0a29119052e9d5bf0d0ef6.tar
mga-advisor-a8a283de5727b8551b0a29119052e9d5bf0d0ef6.tar.gz
mga-advisor-a8a283de5727b8551b0a29119052e9d5bf0d0ef6.tar.bz2
mga-advisor-a8a283de5727b8551b0a29119052e9d5bf0d0ef6.tar.xz
mga-advisor-a8a283de5727b8551b0a29119052e9d5bf0d0ef6.zip
Add retrieve info feature from bug report:
- retrieve URL references from url field - retrieve CVEs from cf_cve - retrieve source from Source RPM and from mgarepo rpmlog
-rw-r--r--form.ui5
-rw-r--r--mga-advisor.py84
2 files changed, 85 insertions, 4 deletions
diff --git a/form.ui b/form.ui
index 42e160b..8664085 100644
--- a/form.ui
+++ b/form.ui
@@ -94,7 +94,10 @@
<item>
<widget class="QPushButton" name="retrieve_pb">
<property name="enabled">
- <bool>false</bool>
+ <bool>true</bool>
+ </property>
+ <property name="toolTip">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Extract source package name from Source RPM field and CVEs from CVE field&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Retrieve info</string>
diff --git a/mga-advisor.py b/mga-advisor.py
index ec66dad..705cf89 100644
--- a/mga-advisor.py
+++ b/mga-advisor.py
@@ -5,10 +5,23 @@ import sys
import yaml
import re
from subprocess import run
+import requests
-from PySide6.QtWidgets import QApplication, QWidget, QDialog, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QComboBox, QTextEdit
+from PySide6.QtWidgets import (
+ QApplication,
+ QWidget,
+ QDialog,
+ QLineEdit,
+ QPushButton,
+ QVBoxLayout,
+ QMessageBox,
+ QHBoxLayout,
+ QComboBox,
+ QTextEdit,
+ )
from PySide6.QtCore import QFile, QDate, QDir
from PySide6.QtUiTools import QUiLoader
+BASE_URL = "https://bugs.mageia.org/rest/bug/"
class LineDialog(QDialog):
@@ -72,10 +85,47 @@ class Widget(QWidget):
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)
- # self.populate()
def retrieve(self):
- print("Action retrieve")
+ """
+ Retrieve CVEs, URLs and Source package name from the bug report given by its number
+ """
+ if self.ui.bug_le.text() == "":
+ mb = QMessageBox("Provide a bug number first")
+ mb.exec()
+ return
+ url = os.path.join(BASE_URL, self.ui.bug_le.text()) + "?include_fields=cf_rpmpkg,cf_cve,url"
+ headers = {'Accept': 'application/json'}
+ r = requests.get(url, headers=headers)
+ if r.json()["faults"] == []:
+ for pkg in re.split(';|,| ', r.json()['bugs'][0]['cf_rpmpkg']):
+ pkg = pkg.strip()
+ if pkg == "":
+ continue
+ analyze = re.search(r"(\w+)-\d", pkg)
+ if analyze is not None:
+ pkg = analyze.group(1)
+ sources = self.src_populate(pkg)
+ for source in sources:
+ suffix = ".src.mga" + source["mga_release"]
+ if source["repo"] in ("tainted", "nonfree"):
+ suffix += "." + repo
+ self.ui.list_src.addItem(
+ " ".join((source["mga_release"],
+ source["repo"],
+ source["package"] +
+ "-" + source["version"] +
+ "-" + source["release"] +
+ suffix,
+ )))
+ for cve in re.split(';|,| ', r.json()['bugs'][0]['cf_cve']):
+ cve = cve.strip()
+ if cve != "":
+ self.ui.list_cve.addItem(cve)
+ for url in re.split(';|,| ', r.json()['bugs'][0]['url']):
+ url = url.strip()
+ if url != "":
+ self.ui.list_ref.addItem(url)
def add_src(self):
dl = SrcDialog()
@@ -179,6 +229,34 @@ class Widget(QWidget):
def valid_number(self):
self.ui.bug_le.setText(re.sub('\D', '', self.ui.bug_le.text()))
+ def src_populate(self, package):
+ # retrieve information with repo, release from package name
+ cmd = ["mgarepo", "rpmlog"]
+ sources = []
+ for mga_release in range(8,10):
+ source = {}
+ repo = ""
+ p = run(cmd + [f"{mga_release}/{package}"], capture_output=True, text=True)
+ if p.returncode == 0:
+ line1 = p.stdout.split('\n')[0]
+ analyze = re.search(r"(\w*[\.\d]+)-([\.\d]+)", line1)
+ if analyze is not None:
+ version = analyze.group(1)
+ release = analyze.group(2)[:-1]
+ repo = "core"
+ if "tainted" in line1:
+ repo = "tainted"
+ elif "nonfree" in line1:
+ repo = "nonfree"
+ source["mga_release"] = str(mga_release)
+ source['package'] = package
+ source["repo"] = repo
+ source["version"] = version
+ source["release"] = release
+ sources.append(source)
+ return sources
+
+
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = Widget()