diff --git a/hwcompatible/device.py b/hwcompatible/device.py index d854d3649357520790de8fc1d523348a667fc594..0322640fc32229f34206131d099be80593dcdc37 100755 --- a/hwcompatible/device.py +++ b/hwcompatible/device.py @@ -433,7 +433,10 @@ class Device: def get_cpu_vendor(self): cmd_result = self.command.run_cmd( "cat /proc/cpuinfo | grep vendor_id | head -1", log_print=False) - cpu_vendor_id = cmd_result[0].split(':')[1].strip() + if cmd_result[0] == "": + cpu_vendor_id = "Unknown Vendor" + else: + cpu_vendor_id = cmd_result[0].split(':')[1].strip() return cpu_vendor_id def _is_null(self): diff --git a/hwcompatible/document.py b/hwcompatible/document.py index 49d9874e7fd530e469573817594a9c4e4edefc04..85549d795abb483cda4c161b6f69d9961a45e6bd 100755 --- a/hwcompatible/document.py +++ b/hwcompatible/document.py @@ -75,14 +75,25 @@ class CertDocument(Document): """ try: cmd_result = getoutput("/usr/sbin/dmidecode -t 1") + defaults = { + "Manufacturer": "Unknown Vendor", + "Product Name": "Unknown Product", + "Version": "Unknown Version" + } for line in cmd_result.split("\n"): property_right = line.split(":", 1) if len(property_right) != 2: continue key = property_right[0].strip() value = property_right[1].strip() - if key in ("Manufacturer", "Product Name", "Version"): - self.document[key] = value + if key in defaults: + self.document[key] = value or defaults[key] + else: + self.logger.warning(f"Unknown key '{key}' encountered with \ + value '{value}' when parsing hardware info with dmidecode") + for key, default_value in defaults.items(): + if key not in self.document: + self.document[key] = default_value except Exception as concrete_error: self.logger.error( "Get hardware information failed. %s" % concrete_error)