HardwareInfo: refactor and enrich
authorMirakels <mirakels@openpli.org>
Sat, 1 Mar 2014 13:33:13 +0000 (14:33 +0100)
committerMirakels <mirakels@openpli.org>
Sat, 1 Mar 2014 16:54:04 +0000 (17:54 +0100)
Besides device_name and device_version also determine
device_model and device_revision, and add retrieval functions
get_device_model() and ger_device_revision() for this data.
Another new fcuntion is get_device_string() that returns a
verbose string with most of the hw info.

Caching check did not work in the previous version but works
fine now.

Determining device model name uses a config file
(normally in /usr/share/enigma2/hw_info/hw_info.cfg) to define
how to scan the files in /proc/stb/info and if the data in that
file must be ammended.
So if a new box adds a new filename in /proc/stb/info to list the
receiver model name, this filename must be added to the config file.

configure.ac
data/Makefile.am
data/hw_info/Makefile.am [new file with mode: 0644]
data/hw_info/hw_info.cfg [new file with mode: 0644]
lib/python/Tools/HardwareInfo.py

index b7b728c..c7e163d 100644 (file)
@@ -163,6 +163,7 @@ data/fonts/Makefile
 data/countries/Makefile
 data/extensions/Makefile
 data/keymaps/Makefile
+data/hw_info/Makefile
 data/rc_models/Makefile
 data/rc_models/et4x00/Makefile
 data/rc_models/et6x00/Makefile
index 3b7a3cb..f772f3f 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = countries fonts extensions keymaps skin_default rc_models
+SUBDIRS = countries fonts extensions keymaps skin_default rc_models hw_info
 
 dist_pkgdata_DATA = \
        encoding.conf \
diff --git a/data/hw_info/Makefile.am b/data/hw_info/Makefile.am
new file mode 100644 (file)
index 0000000..60daec4
--- /dev/null
@@ -0,0 +1,5 @@
+installdir = $(pkgdatadir)/hw_info
+
+dist_install_DATA = \
+        hw_info.cfg
+
diff --git a/data/hw_info/hw_info.cfg b/data/hw_info/hw_info.cfg
new file mode 100644 (file)
index 0000000..a863aa5
--- /dev/null
@@ -0,0 +1,8 @@
+# This config file determines the order of files in /proc/stb/info to
+# scan for receiver model names. For boxes with a stripped model name
+# the second column can be used define a prefix (e.g. Vu+ boxen)
+# Lines starting with a # or only containing whitespace are skipped
+
+boxtype
+vumodel    vu
+azmodel
index d364475..3455e16 100644 (file)
@@ -1,24 +1,35 @@
+import os
+from Tools.Directories import SCOPE_SKIN, resolveFilename
+
+hw_info = None
+
 class HardwareInfo:
-       device_name = None
-       device_version = None
+       device_name = _("unavailable")
+       device_model = None
+       device_version = ""
+       device_revision = ""
+       device_hdmi = False
 
        def __init__(self):
-               if HardwareInfo.device_name is not None:
+                global hw_info
+               if hw_info is not None:
 #                      print "using cached result"
                        return
+               hw_info = self
 
-               HardwareInfo.device_name = "unknown"
-               try:
-                       file = open("/proc/stb/info/model", "r")
-                       HardwareInfo.device_name = file.readline().strip()
-                       file.close()
-                       try:
-                               file = open("/proc/stb/info/version", "r")
-                               HardwareInfo.device_version = file.readline().strip()
-                               file.close()
-                       except:
-                               pass
-               except:
+               print "Scanning hardware info"
+               # Version
+               if os.path.exists("/proc/stb/info/version"):
+                       self.device_version = open("/proc/stb/info/version").read().strip()
+
+               # Revision
+               if os.path.exists("/proc/stb/info/board_revision"):
+                       self.device_revision = open("/proc/stb/info/board_revision").read().strip()
+
+               # Name ... bit odd, but history prevails
+               if os.path.exists("/proc/stb/info/model"):
+                       self.device_name = open("/proc/stb/info/model").read().strip()
+               else:
                        print "----------------"
                        print "you should upgrade to new drivers for the hardware detection to work properly"
                        print "----------------"
@@ -26,22 +37,59 @@ class HardwareInfo:
                        try:
                                rd = open("/proc/cpuinfo", "r").read()
                                if "Brcm4380 V4.2" in rd:
-                                       HardwareInfo.device_name = "dm8000"
-                                       print "dm8000 detected!"
+                                       self.device_name = "dm8000"
                                elif "Brcm7401 V0.0" in rd:
-                                       HardwareInfo.device_name = "dm800"
-                                       print "dm800 detected!"
+                                       self.device_name = "dm800"
                                elif "MIPS 4KEc V4.8" in rd:
-                                       HardwareInfo.device_name = "dm7025"
-                                       print "dm7025 detected!"
+                                       self.device_name = "dm7025"
+                               rd.close();
                        except:
                                pass
 
+               # Model
+               for line in open((resolveFilename(SCOPE_SKIN, 'hw_info/hw_info.cfg')), 'r'):
+                       if not line.startswith('#') and not line.isspace():
+                               l = line.strip().replace('\t', ' ')
+                               if l.find(' ') != -1:
+                                       infoFname, prefix = l.split()
+                               else:
+                                       infoFname = l
+                                       prefix = ""
+                               if os.path.exists("/proc/stb/info/" + infoFname):
+                                       self.device_model = prefix + open("/proc/stb/info/" + infoFname).read().strip()
+                                       break
+
+               if self.device_model is None:
+                       self.device_model = self.device_name
+
+               # HDMI capbility
+               self.device_hdmi = (    self.device_name == 'dm7020hd' or
+                                       self.device_name == 'dm800se' or
+                                       self.device_name == 'dm500hd' or
+                                       (self.device_name == 'dm8000' and self.device_version != None))
+
+               print "Detected: " + self.get_device_string()
+
+
        def get_device_name(self):
-               return HardwareInfo.device_name
+               return hw_info.device_name
+
+       def get_device_model(self):
+               return hw_info.device_model
 
        def get_device_version(self):
-               return HardwareInfo.device_version
+               return hw_info.device_version
+
+       def get_device_revision(self):
+               return hw_info.device_revision
+
+       def get_device_string(self):
+               s = hw_info.device_model
+               if hw_info.device_revision != "":
+                       s += " (" + hw_info.device_revision + "-" + hw_info.device_version + ")"
+               elif hw_info.device_version != "":
+                       s += " (" + hw_info.device_version + ")"
+               return s
 
        def has_hdmi(self):
-               return (HardwareInfo.device_name == 'dm7020hd' or HardwareInfo.device_name == 'dm800se' or HardwareInfo.device_name == 'dm500hd' or (HardwareInfo.device_name == 'dm8000' and HardwareInfo.device_version != None))
+               return hw_info.device_hdmi