]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Support ARM in fireinfo.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Sep 2011 12:48:44 +0000 (12:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 4 Sep 2011 12:48:44 +0000 (12:48 +0000)
fireinfo/cpu.py
fireinfo/system.py
sendprofile
src/fireinfo.c

index 87193cf0418b49ea6f0207427715ce6a0926c40d..ed6317783d01de0046aa5e0a39df4a860e9e3b82 100644 (file)
@@ -21,6 +21,8 @@
 
 import os.path
 
+import system
+
 PROC_CPUINFO = "/proc/cpuinfo"
 SYS_CLASS_CPUID = "/sys/class/cpuid/cpu%d"
 
@@ -38,13 +40,20 @@ class CPU(object):
                """
                        Initialize this class by reading all data from /proc/cpuinfo.
                """
-               self.read_cpuinfo()
+               self.__cpuinfo = self.read_cpuinfo()
+
+       @property
+       def system(self):
+               return system.System()
 
-       def read_cpuinfo(self):
+       @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()
@@ -61,65 +70,105 @@ class CPU(object):
                        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):
@@ -129,7 +178,8 @@ class CPU(object):
                i = 0
                while (os.path.exists(SYS_CLASS_CPUID % i)):
                        i += 1
-               return i
+
+               return i or 1
 
 
 if __name__ == "__main__":
index bce87f14a31a79d1f5fd63785a9bd42ff82167aa..efd435231268e83ed0d8e0c5974e5ac43506c667 100644 (file)
@@ -83,6 +83,9 @@ class System(object):
                self.cpu = cpu.CPU()
                self.hypervisor = hypervisor.Hypervisor()
 
+               # Read /proc/cpuinfo for vendor information.
+               self.__cpuinfo = self.cpu.read_cpuinfo()
+
        def profile(self):
                p = {}
                p["system"] = {
@@ -273,7 +276,7 @@ class System(object):
                """
                        Return the system release string.
                """
-               return read_from_file("/etc/system-release")
+               return read_from_file("/etc/system-release") or "unknown"
 
        @property
        def bios_vendor(self):
@@ -282,6 +285,19 @@ class System(object):
                """
                return read_from_file("/sys/class/dmi/id/bios_vendor")
 
+       def vendor_model_tuple(self):
+               try:
+                       s = self.__cpuinfo["Hardware"]
+               except KeyError:
+                       return (None, None)
+
+               if s.startswith("ARM-Versatile"):
+                       return ("ARM", s)
+
+               v, m = s.split(maxsplit=1)
+
+               return v, m
+
        @property
        def vendor(self):
                """
@@ -293,6 +309,10 @@ class System(object):
                        if ret:
                                break
 
+               if ret is None:
+                       v, m = self.vendor_model_tuple()
+                       ret = v
+
                return ret
 
        @property
@@ -306,6 +326,10 @@ class System(object):
                        if ret:
                                break
 
+               if ret is None:
+                       v, m = self.vendor_model_tuple()
+                       ret = m
+
                return ret
 
        @property
index 55b02bae8651d7d27b11f68e2120afdc5f733948..da480ce95f8345dc3f6416b82eb2b9cfe9aa175d 100644 (file)
@@ -48,7 +48,7 @@ PROFILE_URL = "http://fireinfo.ipfire.org/send/%(public_id)s"
 
 def get_upstream_proxy():
        if not os.path.exists(PROXY_SETTINGS):
-               return
+               return {"host" : ""}
 
        proxy_settings = {}
        with open(PROXY_SETTINGS) as f:
index 5310c06b33e72b83f13b8344a42ad15e17cc4d21..25b5333651bbd49375d9f0285abd318d531a3560 100644 (file)
@@ -263,6 +263,7 @@ read_harddisk_serial(char *device, char *serial) {
        }
 }
 
+#if defined(__x86_64__) || defined(__i386__)
 static bool
 is_virtualized() {
        unsigned int eax, ebx, ecx, edx;
@@ -305,6 +306,22 @@ hypervisor_port(unsigned int cmd, unsigned int *eax, unsigned int *ebx,
                : "memory"
        );
 }
+#else
+static bool
+is_virtualized() {
+       /*
+               Always return false, because other architectures
+               do not support the virtualization bit.
+       */
+       return false;
+}
+
+void
+hypervisor_port(unsigned int cmd, unsigned int *eax, unsigned int *ebx,
+               unsigned int *ecx, unsigned int *edx)
+{
+}
+#endif
 
 int
 hypervisor_port_check(void) {