9df2a1f83f62032c1bf9806722184af6032ffb1e
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / About.py
1 import sys
2 import os
3 import time
4 from Tools.HardwareInfo import HardwareInfo
5
6 def getVersionString():
7         return getImageVersionString()
8
9 def getImageVersionString():
10         try:
11                 if os.path.isfile('/var/lib/opkg/status'):
12                         st = os.stat('/var/lib/opkg/status')
13                 else:
14                         st = os.stat('/usr/lib/ipkg/status')
15                 tm = time.localtime(st.st_mtime)
16                 if tm.tm_year >= 2011:
17                         return time.strftime("%Y-%m-%d %H:%M:%S", tm)
18         except:
19                 pass
20         return _("unavailable")
21
22 def getEnigmaVersionString():
23         import enigma
24         enigma_version = enigma.getEnigmaVersionString()
25         if '-(no branch)' in enigma_version:
26                 enigma_version = enigma_version [:-12]
27         return enigma_version
28
29 def getKernelVersionString():
30         try:
31                 return open("/proc/version","r").read().split(' ', 4)[2].split('-',2)[0]
32         except:
33                 return _("unknown")
34
35 def getHardwareTypeString():
36         return HardwareInfo().get_device_string()
37
38 def getImageTypeString():
39         try:
40                 return open("/etc/issue").readlines()[-2].capitalize().strip()[:-6]
41         except:
42                 return _("undefined")
43
44 def getCPUInfoString():
45         try:
46                 cpu_count = 0
47                 for line in open("/proc/cpuinfo").readlines():
48                         line = [x.strip() for x in line.strip().split(":")]
49                         if line[0] == "system type":
50                                 processor = line[1].split()[0]
51                         if line[0] == "cpu MHz":
52                                 cpu_speed = "%1.0f" % float(line[1])
53                                 cpu_count += 1
54                 return "%s %s MHz (%d %s)" % (processor, cpu_speed, cpu_count, cpu_count > 1 and "cores" or "core")
55         except:
56                 return _("undefined")
57
58 # For modules that do "from About import about"
59 about = sys.modules[__name__]