About: Remove the old sourceforge latest commit parser
[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
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                 hddsplit, = skin.parameters.get("AboutHddSplit", (0,))
25
26                 AboutText = _("Hardware: ") + about.getHardwareTypeString() + "\n"
27                 AboutText += _("CPU: ") + about.getCPUInfoString() + "\n"
28                 AboutText += _("Image: ") + about.getImageTypeString() + "\n"
29                 AboutText += _("Installed: ") + about.getFlashDateString() + "\n"
30                 AboutText += _("Kernel version: ") + about.getKernelVersionString() + "\n"
31
32                 EnigmaVersion = "Enigma: " + about.getEnigmaVersionString()
33                 self["EnigmaVersion"] = StaticText(EnigmaVersion)
34                 AboutText += EnigmaVersion + "\n"
35                 AboutText += _("Enigma (re)starts: %d\n") % config.misc.startCounter.value
36
37                 GStreamerVersion = "GStreamer: " + about.getGStreamerVersionString().replace("GStreamer","")
38                 self["GStreamerVersion"] = StaticText(GStreamerVersion)
39                 AboutText += GStreamerVersion + "\n"
40
41                 ImageVersion = _("Last upgrade: ") + about.getImageVersionString()
42                 self["ImageVersion"] = StaticText(ImageVersion)
43                 AboutText += ImageVersion + "\n"
44
45                 AboutText += _("DVB drivers: ") + about.getDriverInstalledDate() + "\n"
46
47                 AboutText += _("Python version: ") + about.getPythonVersionString() + "\n"
48
49                 fp_version = getFPVersion()
50                 if fp_version is None:
51                         fp_version = ""
52                 else:
53                         fp_version = _("Frontprocessor version: %d") % fp_version
54                         AboutText += fp_version + "\n"
55
56                 self["FPVersion"] = StaticText(fp_version)
57
58                 self["TunerHeader"] = StaticText(_("Detected NIMs:"))
59                 AboutText += "\n" + _("Detected NIMs:") + "\n"
60
61                 nims = nimmanager.nimList()
62                 for count in range(len(nims)):
63                         if count < 4:
64                                 self["Tuner" + str(count)] = StaticText(nims[count])
65                         else:
66                                 self["Tuner" + str(count)] = StaticText("")
67                         AboutText += nims[count] + "\n"
68
69                 self["HDDHeader"] = StaticText(_("Detected HDD:"))
70                 AboutText += "\n" + _("Detected HDD:") + "\n"
71
72                 hddlist = harddiskmanager.HDDList()
73                 hddinfo = ""
74                 if hddlist:
75                         formatstring = hddsplit and "%s:%s, %.1f %sB %s" or "%s\n(%s, %.1f %sB %s)"
76                         for count in range(len(hddlist)):
77                                 if hddinfo:
78                                         hddinfo += "\n"
79                                 hdd = hddlist[count][1]
80                                 if int(hdd.free()) > 1024:
81                                         hddinfo += formatstring % (hdd.model(), hdd.capacity(), hdd.free()/1024, "G", _("free"))
82                                 else:
83                                         hddinfo += formatstring % (hdd.model(), hdd.capacity(), hdd.free()/1024, "M", _("free"))
84                 else:
85                         hddinfo = _("none")
86                 self["hddA"] = StaticText(hddinfo)
87                 AboutText += hddinfo
88                 self["AboutScrollLabel"] = ScrollLabel(AboutText)
89                 self["key_green"] = Button(_("Translations"))
90                 self["key_red"] = Button(_("Latest Commits"))
91                 self["key_blue"] = Button(_("Memory Info"))
92
93                 self["actions"] = ActionMap(["ColorActions", "SetupActions", "DirectionActions"],
94                         {
95                                 "cancel": self.close,
96                                 "ok": self.close,
97                                 "red": self.showCommits,
98                                 "green": self.showTranslationInfo,
99                                 "blue": self.showMemoryInfo,
100                                 "up": self["AboutScrollLabel"].pageUp,
101                                 "down": self["AboutScrollLabel"].pageDown
102                         })
103
104         def showTranslationInfo(self):
105                 self.session.open(TranslationInfo)
106
107         def showCommits(self):
108                 self.session.open(CommitInfo)
109
110         def showMemoryInfo(self):
111                 self.session.open(MemoryInfo)
112
113 class TranslationInfo(Screen):
114         def __init__(self, session):
115                 Screen.__init__(self, session)
116                 # don't remove the string out of the _(), or it can't be "translated" anymore.
117
118                 # TRANSLATORS: Add here whatever should be shown in the "translator" about screen, up to 6 lines (use \n for newline)
119                 info = _("TRANSLATOR_INFO")
120
121                 if info == "TRANSLATOR_INFO":
122                         info = "(N/A)"
123
124                 infolines = _("").split("\n")
125                 infomap = {}
126                 for x in infolines:
127                         l = x.split(': ')
128                         if len(l) != 2:
129                                 continue
130                         (type, value) = l
131                         infomap[type] = value
132                 print infomap
133
134                 self["key_red"] = Button(_("Cancel"))
135                 self["TranslationInfo"] = StaticText(info)
136
137                 translator_name = infomap.get("Language-Team", "none")
138                 if translator_name == "none":
139                         translator_name = infomap.get("Last-Translator", "")
140
141                 self["TranslatorName"] = StaticText(translator_name)
142
143                 self["actions"] = ActionMap(["SetupActions"],
144                         {
145                                 "cancel": self.close,
146                                 "ok": self.close,
147                         })
148
149 class CommitInfo(Screen):
150         def __init__(self, session):
151                 Screen.__init__(self, session)
152                 self.skinName = ["CommitInfo", "About"]
153                 self["AboutScrollLabel"] = ScrollLabel(_("Please wait"))
154
155                 self["actions"] = ActionMap(["SetupActions", "DirectionActions"],
156                         {
157                                 "cancel": self.close,
158                                 "ok": self.close,
159                                 "up": self["AboutScrollLabel"].pageUp,
160                                 "down": self["AboutScrollLabel"].pageDown,
161                                 "left": self.left,
162                                 "right": self.right
163                         })
164
165                 self["key_red"] = Button(_("Cancel"))
166
167                 self.project = 0
168                 self.projects = [
169                         ("enigma2", "Enigma2"),
170                         ("openpli-oe-core", "Openpli Oe Core"),
171                         ("enigma2-plugins", "Enigma2 Plugins"),
172                         ("aio-grab", "Aio Grab"),
173                         ("gst-plugin-dvbmediasink", "Gst Plugin Dvbmediasink"),
174                         ("openembedded", "Openembedded"),
175                         ("plugin-xmltvimport", "Plugin Xmltvimport"),
176                         ("plugins-enigma2", "Plugins Enigma2"),
177                         ("skin-magic", "Skin Magic"),
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                         i = 0
261                         for line in open('/proc/meminfo','r'):
262                                 ( name, size, units ) = line.strip().split()
263                                 if "MemTotal" in name:
264                                         mem = int(size)
265                                 if "MemFree" in name:
266                                         free = int(size)
267                                 if i < self["params"].rows_in_column:
268                                         ltext += "".join((name,"\n"))
269                                         lvalue += "".join((size," ",units,"\n"))
270                                 else:
271                                         rtext += "".join((name,"\n"))
272                                         rvalue += "".join((size," ",units,"\n"))
273                                 i += 1
274                         self['lmemtext'].setText(ltext)
275                         self['lmemvalue'].setText(lvalue)
276                         self['rmemtext'].setText(rtext)
277                         self['rmemvalue'].setText(rvalue)
278
279                         self["slide"].setValue(int(100.0*(mem-free)/mem+0.25))
280                         self['pfree'].setText("%.1f %s" % (100.*free/mem,'%'))
281                         self['pused'].setText("%.1f %s" % (100.*(mem-free)/mem,'%'))
282
283                 except Exception, e:
284                         print "[About] getMemoryInfo FAIL:", e
285
286         def clearMemory(self):
287                 from os import system
288                 system("sync")
289                 system("echo 3 > /proc/sys/vm/drop_caches")
290                 self.getMemoryInfo()
291
292 class MemoryInfoSkinParams(HTMLComponent, GUIComponent):
293         def __init__(self):
294                 GUIComponent.__init__(self)
295                 self.rows_in_column = 25
296
297         def applySkin(self, desktop, screen):
298                 if self.skinAttributes is not None:
299                         attribs = [ ]
300                         for (attrib, value) in self.skinAttributes:
301                                 if attrib == "rowsincolumn":
302                                         self.rows_in_column = int(value)
303                         self.skinAttributes = attribs
304                 return GUIComponent.applySkin(self, desktop, screen)
305
306         GUI_WIDGET = eLabel