]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
New function to read from /proc/cpuinfo.
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Nov 2010 21:45:33 +0000 (22:45 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Nov 2010 21:45:33 +0000 (22:45 +0100)
fireinfo/cpu.py

index 267f63450718305a1ebec9ae1d5a68931fabde29..66eaff6610dd1e38e7c126c775065a4d1c23c1be 100644 (file)
@@ -5,6 +5,35 @@ import _fireinfo
 
 class CPU(object):
        __info = _fireinfo.cpuinfo()
+       __cpuinfo = {}
+
+       def __init__(self):
+               self.read_cpuinfo()
+
+       def read_cpuinfo(self):
+               """
+                       Read information from /proc/cpuinfo and store
+                       it into a dictionary self.__cpuinfo.
+               """
+               f = open("/proc/cpuinfo")
+               while True:
+                       line = f.readline()
+
+                       if not line:
+                               break
+
+                       try:
+                               key, val = line.split(":", 1)
+                       except ValueError:
+                               # We got a line without key, pass that.
+                               pass
+
+                       key = key.strip().replace(" ", "_")
+                       val = val.strip()
+
+                       self.__cpuinfo[key] = val
+
+               f.close()
 
        @property
        def bogomips(self):
@@ -54,7 +83,7 @@ class CPU(object):
 
 
 if __name__ == "__main__":
-       c = CPU(0)
+       c = CPU()
 
        print "Vendor:", c.vendor
        print "Model:", c.model