Merge pull request #156 from Dima73/pull1
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / About.py
1 from Screen import Screen
2 from Components.config import config
3 from Components.ActionMap import ActionMap
4 from Components.Sources.StaticText import StaticText
5 from Components.Harddisk import harddiskmanager
6 from Components.NimManager import nimmanager
7 from Components.About import about
8 from Components.ScrollLabel import ScrollLabel
9 from Components.Button import Button
10
11 from Components.Label import Label
12 from Components.ProgressBar import ProgressBar
13
14 from Tools.StbHardware import getFPVersion
15 from enigma import eTimer, eLabel, eConsoleAppContainer
16
17 from Components.HTMLComponent import HTMLComponent
18 from Components.GUIComponent import GUIComponent
19 import skin
20
21 class About(Screen):
22         def __init__(self, session):
23                 Screen.__init__(self, session)
24                 self.setTitle(_("About"))
25                 hddsplit, = skin.parameters.get("AboutHddSplit", (0,))
26
27                 AboutText = _("Hardware: ") + about.getHardwareTypeString() + "\n"
28                 AboutText += _("CPU: ") + about.getCPUInfoString() + "\n"
29                 AboutText += _("Image: ") + about.getImageTypeString() + "\n"
30                 AboutText += _("Installed: ") + about.getFlashDateString() + "\n"
31                 AboutText += _("Kernel version: ") + about.getKernelVersionString() + "\n"
32
33                 EnigmaVersion = "Enigma: " + about.getEnigmaVersionString()
34                 self["EnigmaVersion"] = StaticText(EnigmaVersion)
35                 AboutText += EnigmaVersion + "\n"
36                 AboutText += _("Enigma (re)starts: %d\n") % config.misc.startCounter.value
37
38                 GStreamerVersion = "GStreamer: " + about.getGStreamerVersionString().replace("GStreamer","")
39                 self["GStreamerVersion"] = StaticText(GStreamerVersion)
40                 AboutText += GStreamerVersion + "\n"
41
42                 ImageVersion = _("Last upgrade: ") + about.getImageVersionString()
43                 self["ImageVersion"] = StaticText(ImageVersion)
44                 AboutText += ImageVersion + "\n"
45
46                 AboutText += _("DVB drivers: ") + about.getDriverInstalledDate() + "\n"
47
48                 AboutText += _("Python version: ") + about.getPythonVersionString() + "\n"
49
50                 fp_version = getFPVersion()
51                 if fp_version is None:
52                         fp_version = ""
53                 else:
54                         fp_version = _("Frontprocessor version: %d") % fp_version
55                         AboutText += fp_version + "\n"
56
57                 self["FPVersion"] = StaticText(fp_version)
58
59                 self["TunerHeader"] = StaticText(_("Detected NIMs:"))
60                 AboutText += "\n" + _("Detected NIMs:") + "\n"
61
62                 nims = nimmanager.nimList()
63                 for count in range(len(nims)):
64                         if count < 4:
65                                 self["Tuner" + str(count)] = StaticText(nims[count])
66                         else:
67                                 self["Tuner" + str(count)] = StaticText("")
68                         AboutText += nims[count] + "\n"
69
70                 self["HDDHeader"] = StaticText(_("Detected HDD:"))
71                 AboutText += "\n" + _("Detected HDD:") + "\n"
72
73                 hddlist = harddiskmanager.HDDList()
74                 hddinfo = ""
75                 if hddlist:
76                         formatstring = hddsplit and "%s:%s, %.1f %sB %s" or "%s\n(%s, %.1f %sB %s)"
77                         for count in range(len(hddlist)):
78                                 if hddinfo:
79                                         hddinfo += "\n"
80                                 hdd = hddlist[count][1]
81                                 if int(hdd.free()) > 1024:
82                                         hddinfo += formatstring % (hdd.model(), hdd.capacity(), hdd.free()/1024.0, "G", _("free"))
83                                 else:
84                                         hddinfo += formatstring % (hdd.model(), hdd.capacity(), hdd.free(), "M", _("free"))
85                 else:
86                         hddinfo = _("none")
87                 self["hddA"] = StaticText(hddinfo)
88                 AboutText += hddinfo
89                 self["AboutScrollLabel"] = ScrollLabel(AboutText)
90                 self["key_green"] = Button(_("Translations"))
91                 self["key_red"] = Button(_("Latest Commits"))
92                 self["key_blue"] = Button(_("Memory Info"))
93
94                 self["actions"] = ActionMap(["ColorActions", "SetupActions", "DirectionActions"],
95                         {
96                                 "cancel": self.close,
97                                 "ok": self.close,
98                                 "red": self.showCommits,
99                                 "green": self.showTranslationInfo,
100                                 "blue": self.showMemoryInfo,
101                                 "up": self["AboutScrollLabel"].pageUp,
102                                 "down": self["AboutScrollLabel"].pageDown
103                         })
104
105         def showTranslationInfo(self):
106                 self.session.open(TranslationInfo)
107
108         def showCommits(self):
109                 self.session.open(CommitInfo)
110
111         def showMemoryInfo(self):
112                 self.session.open(MemoryInfo)
113
114 class TranslationInfo(Screen):
115         def __init__(self, session):
116                 Screen.__init__(self, session)
117                 # don't remove the string out of the _(), or it can't be "translated" anymore.
118
119                 # TRANSLATORS: Add here whatever should be shown in the "translator" about screen, up to 6 lines (use \n for newline)
120                 info = _("TRANSLATOR_INFO")
121
122                 if info == "TRANSLATOR_INFO":
123                         info = "(N/A)"
124
125                 infolines = _("").split("\n")
126                 infomap = {}
127                 for x in infolines:
128                         l = x.split(': ')
129                         if len(l) != 2:
130                                 continue
131                         (type, value) = l
132                         infomap[type] = value
133                 print infomap
134
135                 self["key_red"] = Button(_("Cancel"))
136                 self["TranslationInfo"] = StaticText(info)
137
138                 translator_name = infomap.get("Language-Team", "none")
139                 if translator_name == "none":
140                         translator_name = infomap.get("Last-Translator", "")
141
142                 self["TranslatorName"] = StaticText(translator_name)
143
144                 self["actions"] = ActionMap(["SetupActions"],
145                         {
146                                 "cancel": self.close,
147                                 "ok": self.close,
148                         })
149
150 class CommitInfo(Screen):
151         def __init__(self, session):
152                 Screen.__init__(self, session)
153                 self.skinName = ["CommitInfo", "About"]
154                 self["AboutScrollLabel"] = ScrollLabel(_("Please wait"))
155
156                 self["actions"] = ActionMap(["SetupActions", "DirectionActions"],
157                         {
158                                 "cancel": self.close,
159                                 "ok": self.close,
160                                 "up": self["AboutScrollLabel"].pageUp,
161                                 "down": self["AboutScrollLabel"].pageDown,
162                                 "left": self.left,
163                                 "right": self.right
164                         })
165
166                 self["key_red"] = Button(_("Cancel"))
167
168                 self.project = 0
169                 self.projects = [
170                         ("enigma2", "Enigma2"),
171                         ("openpli-oe-core", "Openpli Oe Core"),
172                         ("enigma2-plugins", "Enigma2 Plugins"),
173                         ("aio-grab", "Aio Grab"),
174                         ("gst-plugin-dvbmediasink", "Gst Plugin Dvbmediasink"),
175                         ("HenksatSettings", "Henksat Settings"),
176                         ("enigma2-plugin-extensions-xmltvimport", "Plugin Xmltvimport"),
177                         ("enigma2-plugin-skins-magic", "Skin Magic SD"),
178                         ("tuxtxt", "Tuxtxt")
179                 ]
180                 self.cachedProjects = {}
181                 self.Timer = eTimer()
182                 self.Timer.callback.append(self.readGithubCommitLogs)
183                 self.Timer.start(50, True)
184
185         def readGithubCommitLogs(self):
186                 url = 'https://api.github.com/repos/openpli/%s/commits' % self.projects[self.project][0]
187                 commitlog = ""
188                 from datetime import datetime
189                 from json import loads
190                 from urllib2 import urlopen
191                 try:
192                         commitlog += 80 * '-' + '\n'
193                         commitlog += url.split('/')[-2] + '\n'
194                         commitlog += 80 * '-' + '\n'
195                         for c in loads(urlopen(url, timeout=5).read()):
196                                 creator = c['commit']['author']['name']
197                                 title = c['commit']['message']
198                                 date = datetime.strptime(c['commit']['committer']['date'], '%Y-%m-%dT%H:%M:%SZ').strftime('%x %X')
199                                 commitlog += date + ' ' + creator + '\n' + title + 2 * '\n'
200                         commitlog = commitlog.encode('utf-8')
201                         self.cachedProjects[self.projects[self.project][1]] = commitlog
202                 except:
203                         commitlog += _("Currently the commit log cannot be retrieved - please try later again")
204                 self["AboutScrollLabel"].setText(commitlog)
205
206         def updateCommitLogs(self):
207                 if self.cachedProjects.has_key(self.projects[self.project][1]):
208                         self["AboutScrollLabel"].setText(self.cachedProjects[self.projects[self.project][1]])
209                 else:
210                         self["AboutScrollLabel"].setText(_("Please wait"))
211                         self.Timer.start(50, True)
212
213         def left(self):
214                 self.project = self.project == 0 and len(self.projects) - 1 or self.project - 1
215                 self.updateCommitLogs()
216
217         def right(self):
218                 self.project = self.project != len(self.projects) - 1 and self.project + 1 or 0
219                 self.updateCommitLogs()
220
221 class MemoryInfo(Screen):
222         def __init__(self, session):
223                 Screen.__init__(self, session)
224
225                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
226                         {
227                                 "cancel": self.close,
228                                 "ok": self.getMemoryInfo,
229                                 "green": self.getMemoryInfo,
230                                 "blue": self.clearMemory,
231                         })
232
233                 self["key_red"] = Label(_("Cancel"))
234                 self["key_green"] = Label(_("Refresh"))
235                 self["key_blue"] = Label(_("Clear"))
236
237                 self['lmemtext'] = Label()
238                 self['lmemvalue'] = Label()
239                 self['rmemtext'] = Label()
240                 self['rmemvalue'] = Label()
241
242                 self['pfree'] = Label()
243                 self['pused'] = Label()
244                 self["slide"] = ProgressBar()
245                 self["slide"].setValue(100)
246
247                 self["params"] = MemoryInfoSkinParams()
248
249                 self['info'] = Label(_("This info is for developers only.\nFor a normal users it is not important.\nDon't panic, please, when here will be displayed any suspicious informations!"))
250
251                 self.setTitle(_("Memory Info"))
252                 self.onLayoutFinish.append(self.getMemoryInfo)
253
254         def getMemoryInfo(self):
255                 try:
256                         ltext = rtext = ""
257                         lvalue = rvalue = ""
258                         mem = 1
259                         free = 0
260                         rows_in_column = self["params"].rows_in_column
261                         for i, line in enumerate(open('/proc/meminfo','r')):
262                                 s = line.strip().split(None, 2)
263                                 if len(s) == 3:
264                                         name, size, units = s
265                                 elif len(s) == 2:
266                                         name, size = s
267                                         units = ""
268                                 else:
269                                         continue
270                                 if name.startswith("MemTotal"):
271                                         mem = int(size)
272                                 if name.startswith("MemFree") or name.startswith("Buffers") or name.startswith("Cached"):
273                                         free += int(size)
274                                 if i < rows_in_column:
275                                         ltext += "".join((name,"\n"))
276                                         lvalue += "".join((size," ",units,"\n"))
277                                 else:
278                                         rtext += "".join((name,"\n"))
279                                         rvalue += "".join((size," ",units,"\n"))
280                         self['lmemtext'].setText(ltext)
281                         self['lmemvalue'].setText(lvalue)
282                         self['rmemtext'].setText(rtext)
283                         self['rmemvalue'].setText(rvalue)
284                         self["slide"].setValue(int(100.0*(mem-free)/mem+0.25))
285                         self['pfree'].setText("%.1f %s" % (100.*free/mem,'%'))
286                         self['pused'].setText("%.1f %s" % (100.*(mem-free)/mem,'%'))
287                 except Exception, e:
288                         print "[About] getMemoryInfo FAIL:", e
289
290         def clearMemory(self):
291                 eConsoleAppContainer().execute("sync")
292                 open("/proc/sys/vm/drop_caches", "w").write("3")
293                 self.getMemoryInfo()
294
295 class MemoryInfoSkinParams(HTMLComponent, GUIComponent):
296         def __init__(self):
297                 GUIComponent.__init__(self)
298                 self.rows_in_column = 25
299
300         def applySkin(self, desktop, screen):
301                 if self.skinAttributes is not None:
302                         attribs = [ ]
303                         for (attrib, value) in self.skinAttributes:
304                                 if attrib == "rowsincolumn":
305                                         self.rows_in_column = int(value)
306                         self.skinAttributes = attribs
307                 return GUIComponent.applySkin(self, desktop, screen)
308
309         GUI_WIDGET = eLabel