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