]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Add option to sort out invalid strings from the id.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Dec 2010 23:33:25 +0000 (00:33 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Dec 2010 23:33:25 +0000 (00:33 +0100)
fireinfo/system.py

index a4fff57e765e96f96ef88a003f308c4e2897ad8b..427386b980cead92a46a530d58391bc41a833a6a 100644 (file)
@@ -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