From 7eadbfba9b87562b56e8fa8e12e7951504966bac Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 11 Dec 2010 00:33:25 +0100 Subject: [PATCH] Add option to sort out invalid strings from the id. --- fireinfo/system.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/fireinfo/system.py b/fireinfo/system.py index a4fff57..427386b 100644 --- a/fireinfo/system.py +++ b/fireinfo/system.py @@ -16,6 +16,11 @@ PROFILE_VERSION = 0 SYS_CLASS_DMI = "/sys/class/dmi/id" SECRET_ID_FILE = "/etc/fireinfo-id" +INVALID_ID_STRINGS = ( + "OEM", "O.E.M.", "o.e.m.", + "N/A", "n/a", +) + class Singleton(type): def __init__(cls, name, bases, dict): super(Singleton, cls).__init__(name, bases, dict) @@ -180,8 +185,8 @@ class System(object): # Virtual machines (for example) and some boards have a UUID # which is globally unique. for file in ("product_uuid", "product_serial", "chassis_serial"): - id = read_from_file(os.path.join(SYS_CLASS_DMI, file)) or "" - ids.append(id) + id = read_from_file(os.path.join(SYS_CLASS_DMI, file)) + ids.append(self.__validate_string(id)) # Use serial number from root disk (if available) root_disk_serial = self.root_disk_serial @@ -190,9 +195,22 @@ class System(object): # As last resort, we use the UUID from pakfire. if not ids: - id = read_from_file("/opt/pakfire/db/uuid") or "" + id = read_from_file("/opt/pakfire/db/uuid") ids.append(id) + # Sort out all bogous or invalid strings from the list. + _ids = [] + for id in ids: + for i in INVALID_ID_STRINGS: + if i in s: + s = None + break + + if id: + _ids.append(id) + + ids = _ids + return "#".join(ids) @property -- 2.39.2