diff options
-rw-r--r-- | form.ui | 5 | ||||
-rw-r--r-- | mga-advisor.py | 84 |
2 files changed, 85 insertions, 4 deletions
@@ -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><html><head/><body><p>Extract source package name from Source RPM field and CVEs from CVE field</p></body></html></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() |