From: Michael Tremer Date: Tue, 23 Nov 2010 21:45:33 +0000 (+0100) Subject: New function to read from /proc/cpuinfo. X-Git-Tag: v0.2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ef0b2a953bda9cb8ca79b6df5d915832b9445c4;p=oddments%2Ffireinfo.git New function to read from /proc/cpuinfo. --- diff --git a/fireinfo/cpu.py b/fireinfo/cpu.py index 267f634..66eaff6 100644 --- a/fireinfo/cpu.py +++ b/fireinfo/cpu.py @@ -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