From 445db52ed90fc300052a7d1efdede13d1af365d8 Mon Sep 17 00:00:00 2001 From: Thomas Castleman Date: Sun, 15 Jan 2023 21:49:44 -0500 Subject: [PATCH] improve formatting of installation reports --- DEBIAN/control | 2 +- usr/bin/system-installer.cxx | 2 +- usr/share/system-installer/UI/report.py | 59 ++++++++++++++++--------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/DEBIAN/control b/DEBIAN/control index 691556c..92f91f8 100644 --- a/DEBIAN/control +++ b/DEBIAN/control @@ -1,5 +1,5 @@ Package: system-installer -Version: 2.4.8 +Version: 2.5.0 Maintainer: Thomas Castleman Homepage: https://github.com/drauger-os-development/system-installer Section: admin diff --git a/usr/bin/system-installer.cxx b/usr/bin/system-installer.cxx index ef4ba48..2fe84f9 100644 --- a/usr/bin/system-installer.cxx +++ b/usr/bin/system-installer.cxx @@ -46,7 +46,7 @@ using namespace std; -str VERSION = "2.4.8"; +str VERSION = "2.5.0"; str R = "\033[0;31m"; str G = "\033[0;32m"; str Y = "\033[1;33m"; diff --git a/usr/share/system-installer/UI/report.py b/usr/share/system-installer/UI/report.py index f9608ba..6e48c7f 100755 --- a/usr/share/system-installer/UI/report.py +++ b/usr/share/system-installer/UI/report.py @@ -422,7 +422,9 @@ def generate_message(self): self.path = "/var/log/installation_report-%s.dosir" % (report_code) output['Installation Report Code'] = report_code try: - output['system-installer Version'] = check_output(["system-installer", "-v"]).decode() + ver = check_output(["system-installer", "-v"]).decode().split("\n") + ver = [each for each in ver if each != ""][0] + output['system-installer Version'] = ver except (FileNotFoundError, CalledProcessError): output['system-installer Version'] = "VERSION UNKNOWN. LIKELY TESTING OR MAJOR ERROR." output['OS'] = get_info(["lsb_release", "-ds"])[0] @@ -597,54 +599,72 @@ def cpu_info(): # We need to create a more intelligent parser for this data as positions can # change depending on the system that is being used. sentenal = 0 - output = [] + output = {} backup_speed = None count = 0 while sentenal < 7: for each in info: if sentenal == 0: if "Model name:" in each: - output.append(each) + add = [each1 for each1 in each.split(" ") if each1 != ""] + if add[0][-1] == ":": + add[0] = add[0][:-1] + output[add[0]] = add[1] sentenal += 1 elif sentenal == 1: if "Thread(s) per core:" in each: - output.append(each) + add = [each1 for each1 in each.split(" ") if each1 != ""] + if add[0][-1] == ":": + add[0] = add[0][:-1] + output[add[0]] = int(add[1]) sentenal += 1 elif sentenal == 2: if "Core(s) per socket:" in each: - output.append(each) + add = [each1 for each1 in each.split(" ") if each1 != ""] + if add[0][-1] == ":": + add[0] = add[0][:-1] + output[add[0]] = int(add[1]) sentenal += 1 elif sentenal == 3: if "CPU max MHz:" in each: - output.append(each) + add = [each1 for each1 in each.split(" ") if each1 != ""] + if add[0][-1] == ":": + add[0] = add[0][:-1] + output[add[0]] = float(add[1]) sentenal += 1 count = 0 elif count == len(info): count = 0 sentenal += 1 - output.append("CPU max MHz:\t\t\tUnknown") + output["CPU max MHz"] = "Unknown" else: count += 1 elif sentenal == 4: if "L2 cache:" in each: - output.append(each) + add = [each1 for each1 in each.split(" ") if each1 != ""] + if add[0][-1] == ":": + add[0] = add[0][:-1] + output[add[0]] = add[1] sentenal += 1 count = 0 elif count == len(info): count = 0 sentenal += 1 - output.append("L2 cache:\t\t\tUnknown") + output["L2 cache"] = "Unknown" else: count += 1 elif sentenal == 5: if "L3 cache:" in each: - output.append(each) + add = [each1 for each1 in each.split(" ") if each1 != ""] + if add[0][-1] == ":": + add[0] = add[0][:-1] + output[add[0]] = add[1] sentenal += 1 count = 0 elif count == len(info): count = 0 sentenal += 1 - output.append("L3 cache:\t\t\tUnknown") + output["L3 cache"] = "Unknown" else: count += 1 elif sentenal == 6: @@ -668,14 +688,19 @@ def cpu_info(): speed = int(file.read()) / 1000 else: speed = backup_speed - speed = f"CPU base MHz { speed }" - output.insert(3, speed) - return "\n".join(output) + # speed = float(speed) + output["CPU base MHz"] = speed + return output def ram_info(): """Get RAM info""" ram_capacity = check_output(["lsmem", "--summary=only"]).decode().split("\n") + for each in enumerate(ram_capacity): + ram_capacity[each[0]] = [each1 for each1 in each[1].split(" ") if each1 != ""] + for each in range(len(ram_capacity) - 1, -1, -1): + if ram_capacity[each] == []: + del ram_capacity[each] swap_capacity = check_output(["swapon", "--show"]).decode().split("\n") return {"RAM": ram_capacity, "SWAP": swap_capacity} @@ -700,9 +725,3 @@ def get_info(cmd): info = info.split("\n") return info - -def send_to(): - try: - return json.loads("/etc/system-installer/settings.json")["report_to"] - except (FileNotFoundError, PermissionError, KeyError): - return "installation-reports@draugeros.org"