import os.path
-import _fireinfo
+import system
PROC_CPUINFO = "/proc/cpuinfo"
SYS_CLASS_CPUID = "/sys/class/cpuid/cpu%d"
"""
Initialize this class by reading all data from /proc/cpuinfo.
"""
- self.read_cpuinfo()
+ self.__cpuinfo = self.read_cpuinfo()
- def read_cpuinfo(self):
+ @property
+ def system(self):
+ return system.System()
+
+ @staticmethod
+ def read_cpuinfo():
"""
Read information from PROC_CPUINFO and store
- it into a dictionary self.__cpuinfo.
+ it into a dictionary cpuinfo.
"""
+ cpuinfo = {}
+
f = open(PROC_CPUINFO)
while True:
line = f.readline()
key = key.strip().replace(" ", "_")
val = val.strip()
- self.__cpuinfo[key] = val
+ cpuinfo[key] = val
f.close()
+ return cpuinfo
+
@property
def bogomips(self):
"""
Return the bogomips of this CPU.
"""
- return float(self.__cpuinfo["bogomips"])
+ try:
+ bogomips = self.__cpuinfo["bogomips"]
+ except KeyError:
+ bogomips = self.__cpuinfo["BogoMIPS"]
+
+ return float(bogomips)
@property
def model(self):
"""
Return the model id of this CPU.
"""
- return int(self.__cpuinfo["model"])
+ try:
+ model = int(self.__cpuinfo["model"])
+ except KeyError:
+ model = None
+
+ return model
@property
def model_string(self):
"""
Return the model string of this CPU.
"""
- return self.__cpuinfo["model_name"]
+ return self.__cpuinfo["Processor"]
@property
def vendor(self):
"""
Return the vendor string of this CPU.
"""
- return self.__cpuinfo["vendor_id"]
+ try:
+ vendor = self.__cpuinfo["vendor_id"]
+ except KeyError:
+ if self.system.arch.startswith("arm"):
+ vendor = "ARM"
+ else:
+ vendor = ""
+
+ return vendor
@property
def stepping(self):
"""
Return the stepping id of this CPU.
"""
- return int(self.__cpuinfo["stepping"])
+ try:
+ stepping = int(self.__cpuinfo["stepping"])
+ except KeyError:
+ stepping = None
+
+ return stepping
@property
def flags(self):
"""
Return all flags of this CPU.
"""
- return self.__cpuinfo["flags"].split()
+ try:
+ flags = self.__cpuinfo["flags"]
+ except KeyError:
+ flags = self.__cpuinfo["Features"]
+
+ return flags.split()
@property
def speed(self):
"""
Return the speed (in MHz) of this CPU.
"""
- return float(self.__cpuinfo["cpu_MHz"])
+ try:
+ speed = float(self.__cpuinfo["cpu_MHz"])
+ except KeyError:
+ speed = 0
+
+ return speed
@property
def family(self):
"""
Return the family id of this CPU.
"""
- return int(self.__cpuinfo["cpu_family"])
+ try:
+ family = int(self.__cpuinfo["cpu_family"])
+ except KeyError:
+ family = None
+
+ return family
@property
def count(self):
i = 0
while (os.path.exists(SYS_CLASS_CPUID % i)):
i += 1
- return i
+
+ return i or 1
if __name__ == "__main__":