2 from urllib import urlretrieve
4 from Plugins.Plugin import PluginDescriptor
6 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigText, ConfigSelection, ConfigYesNo,ConfigText
7 from Components.ConfigList import ConfigListScreen
8 from Components.ActionMap import ActionMap
9 from Components.Sources.StaticText import StaticText
10 from Components.Pixmap import Pixmap
11 from Components.Label import Label
13 from Components.FileList import FileList
14 from Components.Slider import Slider
16 from Screens.Screen import Screen
17 from Screens.MessageBox import MessageBox
19 from enigma import ePoint, eConsoleAppContainer, eTimer
20 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
24 if os.path.exists("/proc/stb/info/vumodel"):
25 vumodel = open("/proc/stb/info/vumodel")
26 info = vumodel.read().strip()
32 ,("fp", _("Front Processor"))
35 "fpga" : ["http://archive.vuplus.com/download/fpga", "fpga.files", "/dev/fpga_dp;/dev/misc/dp;"]
36 ,"fp" : ["http://archive.vuplus.com/download/fp", "fp.files", "/dev/bcm_mu;"]
43 "fpga" : ["http://archive.vuplus.com/download/fpga", "fpga.file", "/dev/fpga_dp;/dev/misc/dp;"]
46 class UpgradeStatus(Screen):
48 <screen position="center,center" size="450,100" title=" ">
49 <widget name="name" position="10,0" size="430,20" font="Regular;18" halign="left" valign="bottom"/>
50 <widget name="slider" position="10,25" size="430,30" backgroundColor="white"/>
51 <widget name="status" position="10,25" zPosition="1" size="430,30" font="Regular;18" halign="center" valign="center" foregroundColor="black" backgroundColor="black" transparent="1"/>
52 <widget source="info" render="Label" position="10,70" zPosition="1" size="430,30" font="Regular;22" halign="center" valign="center" backgroundColor="#a08500" transparent="1"/>
56 def __init__(self, session, parent, firmware, datafile, device):
57 Screen.__init__(self,session)
58 self.session = session
60 self["actions"] = ActionMap(["OkCancelActions"],
65 self.firmware = firmware
66 self.datafile = datafile
67 #print "[FirmwareUpgrade] - [%s][%s][%s]" % (self.datafile, firmware, device)
69 self["name"] = Label(_(" "))
70 self["info"] = StaticText(_("Can't cancel during upgrade!!"))
72 self["status"] = Label(_("Status : 0%"))
74 self.slider = Slider(0, 100)
75 self["slider"] = self.slider
79 self.setTitle(firmware.upper() + " Upgrade Status")
85 self.status_exit = None
86 self.check_status = eTimer()
87 self.check_status.callback.append(self.cbCheckStatus)
88 self.check_status.start(self.FU.getInterval())
90 self.exitTimerCallCount = 0;
91 self.upgradeLock = True
92 self.FU.startUpgrade(self.datafile, device, firmware)
94 def cbCheckStatus(self):
96 errno = self.FU.checkError()
98 self.check_status.stop()
99 errmsg = self.FU.getErrorMessage(errno, errmsg)
100 print "[FirmwareUpgrade] - ERROR : [%d][%s]" % (errno, errmsg)
101 self.session.open(MessageBox, _(errmsg), MessageBox.TYPE_INFO, timeout = 10)
102 self.cbConfirmExit(False)
104 status = self.FU.getStatus()
105 if self.old_status > status and status != -1:
106 self.session.open(MessageBox, _("Fail to upgrade!! Retry!!"), MessageBox.TYPE_INFO, timeout = 10)
107 self.slider.setValue(status)
108 self["status"].setText(_("%d / 100" % (status)))
110 self.check_status.stop()
111 self["status"].setText(_("Success. Press OK to exit."))
112 self.status_exit = eTimer()
113 self.status_exit.callback.append(self.cbTimerExit)
114 self.status_exit.start(1000)
115 self.upgradeLock = False
116 self.old_status = status
118 def setCallback(self, cb):
121 def cbTimerExit(self):
122 if self.exitTimerCallCount < 10: # exit after 10 sec.
123 self.exitTimerCallCount = self.exitTimerCallCount + 1
124 self.setTitle("%s Upgrade Status (%d)" % (self.firmware.upper(), 10-self.exitTimerCallCount))
126 if self.status_exit is not None:
127 self.status_exit.stop()
130 def cbConfirmExit(self, ret):
132 os.system("rm -f %s %s.md5" % (self.datafile, self.datafile))
138 if self.callback is not None:
139 self.callback("Reboot now for a successful upgrade.", True)
140 self.session.openWithCallback(self.cbConfirmExit, MessageBox, _("Do you want to remove binary data?"), MessageBox.TYPE_YESNO, timeout = 10, default = False)
142 class Filebrowser(Screen):
144 <screen position="center,center" size="500,260" title="File Browser" >
145 <ePixmap pixmap="Vu_HD/buttons/blue.png" position="5,7" size="80,40" alphatest="blend" />
146 <widget source="key_blue" render="Label" position="40,0" zPosition="1" size="300,40" font="Regular;20" halign="left" valign="center" transparent="1"/>
147 <widget name="file_list" position="0,50" size="500,160" scrollbarMode="showOnDemand" />
149 <widget source="status" render="Label" position="0,220" zPosition="1" size="500,40" font="Regular;18" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
153 def __init__(self, session, parent, firmware):
154 Screen.__init__(self, session)
155 self.session = session
157 self["key_blue"] = StaticText(_("Download the firmware (latest)"))
159 self["status"] = StaticText(_(" "))
160 self["file_list"] = FileList("/", matchingPattern = "^.*")
162 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", ],
164 "ok": self.onClickOk,
165 "cancel": self.onClickCancel,
166 "blue": self.onClickBlue,
167 "up": self.onClickUp,
168 "down": self.onClickDown,
169 "left": self.onClickLeft,
170 "right": self.onClickRight,
174 self.firmware = firmware
177 self.timer_downloading = None
179 self.downloadLock = False
180 self.setTitle(firmware.upper() + " File Browser")
183 self["status"].setText("Select to press OK, Exit to press Cancel.")
185 def setCallback(self, func):
189 if self.downloadLock:
192 if self["file_list"].canDescent() : # isDir
193 self["file_list"].descent()
197 self.gbin = self["file_list"].getCurrentDirectory() + self["file_list"].getFilename()
198 if not os.path.exists(self.gbin):
199 self.session.open(MessageBox, _("Can't found binary file."), MessageBox.TYPE_INFO, timeout = 10)
201 if not os.path.exists(self.gbin+".md5"):
202 self.session.open(MessageBox, _("Can't found MD5 file."), MessageBox.TYPE_INFO, timeout = 10)
206 name_ext = os.path.splitext(self["file_list"].getFilename())
207 return len(name_ext)==2 and ext.startswith(name_ext[1])
208 self.check_ext = False
209 if (self.firmware == "fp" and checkExt(".bin")) or (self.firmware == "fpga" and checkExt(".dat")):
210 self.check_ext = True
211 if self.check_ext == False:
212 self.session.open(MessageBox, _("You chose the incorrect file."), MessageBox.TYPE_INFO)
215 self.session.open(MessageBox, _("You chose the incorrect file."), MessageBox.TYPE_INFO)
218 if os.path.exists("/usr/bin/md5sum") == False:
219 self.session.open(MessageBox, _("Can't find /usr/bin/md5sum"), MessageBox.TYPE_INFO, timeout = 10)
221 md5sum_A = os.popen("md5sum %s | awk \'{print $1}\'"%(self.gbin)).readline().strip()
222 md5sum_B = os.popen("cat %s.md5 | awk \'{print $1}\'"%(self.gbin)).readline().strip()
223 #print "[FirmwareUpgrade] - Verify : file[%s], md5[%s]"%(md5sum_A,md5sum_B)
225 if md5sum_A != md5sum_B:
226 self.session.open(MessageBox, _("Fail to verify data file. \nfile[%s]\nmd5[%s]"%(md5sum_A,md5sum_B)), MessageBox.TYPE_INFO, timeout = 10)
229 if self.callback is not None:
230 self.callback(_(self.gbin))
233 def onClickCancel(self):
236 # uri : source file url(string)
237 # tf : target file name(string)
238 # bd : target base directory(string)
239 # cbfunc(string) : callback function(function)
240 def doDownload(self, uri, tf, bd='/tmp', cbfunc=None, errmsg="Fail to download."):
242 #print "[FirmwareUpgrade] - Download Info : [%s][%s]" % (uri, tar)
243 def doHook(blockNumber, blockSize, totalSize) :
244 if blockNumber*blockSize > totalSize and cbfunc is not None:
246 opener = urllib.URLopener()
250 #self.session.open(MessageBox, _("File not found in this URL:\n%s"%(uri)), MessageBox.TYPE_INFO, timeout = 10)
251 print "[FirmwareUpgrade] - Fail to download. URL :",uri
252 self.session.open(MessageBox, _(errmsg), MessageBox.TYPE_INFO, timeout = 10)
256 f, h = urlretrieve(uri, tar, doHook)
258 #self.session.open(MessageBox, _(str(msg)), MessageBox.TYPE_INFO, timeout = 10)
259 print "[FirmwareUpgrade] - Fail to download. ERR_MSG :",str(msg)
260 self.session.open(MessageBox, _(errmsg), MessageBox.TYPE_INFO, timeout = 10)
266 def runDownloading(self) :
267 self.timer_downloading.stop()
268 machine = str(open("/proc/stb/info/vumodel").read().strip())
270 def cbDownloadDone(tar):
272 if os.path.splitext(tar)[1] != ".files":
273 self["status"].setText("Downloaded : %s\nSelect to press OK, Exit to press Cancel."%(tar))
278 root_uri = fwdata[self.firmware][0]
279 root_file = fwdata[self.firmware][1]
280 if not self.doDownload("%s/%s"%(root_uri, root_file), root_file, cbfunc=cbDownloadDone):
282 self.downloadLock = False
286 for l in file("/tmp/"+root_file).readlines():
287 if l.startswith(machine):
289 target_path = l.split("=")[1].strip()
293 if target_path == "":
294 self.session.open(MessageBox, _("Firmware does not exist."), MessageBox.TYPE_INFO)
296 self.downloadLock = False
299 self.guri = "%s/vu%s/%s"%(root_uri, machine, target_path)
300 self.gbin = os.path.basename(target_path)
301 #print "[FirmwareUpgrade] - uri[%s], data[%s], data_path[%s]" % (self.gbin, self.guri, target_path)
302 os.system("rm -f /tmp/" + root_file)
305 if not self.doDownload(self.guri+".md5", self.gbin+".md5", cbfunc=cbDownloadDone, errmsg="Can't download the checksum file."):
307 self.downloadLock = False
310 if not self.doDownload(self.guri, self.gbin, cbfunc=cbDownloadDone, errmsg="Can't download the firmware file."):
312 self.downloadLock = False
316 self["file_list"].changeDir("/tmp/")
317 self["file_list"].moveToIndex(0)
318 while cmp(self["file_list"].getFilename(), self.gbin) != 0 :
319 self["file_list"].down()
320 if cmp(t, self["file_list"].getFilename()) == 0:
322 t = self["file_list"].getFilename()
324 del self.timer_downloading
325 self.timer_downloading = None
326 self.downloadLock = False
328 def onClickBlue(self):
329 if self.downloadLock:
331 self.downloadLock = True
332 if not os.path.exists("/proc/stb/info/vumodel"):
333 self.session.open(MessageBox, _("Can't found model name."), MessageBox.TYPE_INFO, timeout = 10)
334 self.downloadLock = False
336 self["status"].setText("Please wait during download.")
337 self.timer_downloading = eTimer()
338 self.timer_downloading.callback.append(self.runDownloading)
339 self.timer_downloading.start(1000)
342 if self.downloadLock:
345 self["file_list"].up()
347 def onClickDown(self):
348 if self.downloadLock:
351 self["file_list"].down()
353 def onClickLeft(self):
354 if self.downloadLock:
357 self["file_list"].pageUp()
359 def onClickRight(self):
360 if self.downloadLock:
363 self["file_list"].pageDown()
368 class FirmwareUpgrade(Screen, ConfigListScreen):
370 <screen position="center,center" size="560,175" title="Firmware Upgrade" >
371 <ePixmap pixmap="Vu_HD/buttons/red.png" position="125,7" size="80,40" alphatest="blend" />
372 <ePixmap pixmap="Vu_HD/buttons/green.png" position="330,7" size="80,40" alphatest="blend" />
374 <widget source="key_red" render="Label" position="160,0" zPosition="1" size="155,40" font="Regular;20" halign="left" valign="center" transparent="1" />
375 <widget source="key_green" render="Label" position="365,0" zPosition="1" size="155,40" font="Regular;20" halign="left" valign="center" transparent="1" />
377 <widget name="config" zPosition="2" position="0,50" itemHeight="36" size="540,40" scrollbarMode="showOnDemand" transparent="1" />
378 <widget source="status" render="Label" position="0,100" zPosition="1" size="540,75" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
382 def __init__(self, session):
383 Screen.__init__(self, session)
384 self.session = session
386 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
389 "cancel": self.keyRed,
391 "green": self.keyGreen,
392 "blue": self.keyBlue,
396 self.updateFilePath = ""
398 self.finishedExit = False
400 self.rebootLock = False
401 self.rebootMessage = ""
402 self.cbRebootCallCount = 0;
404 ConfigListScreen.__init__(self, self.list, session=self.session)
405 self["key_red"] = StaticText(_("Close"))
408 self.old_blue_clicked = 0
409 self.fileopenmode = False
410 self.upgrade_auto_run_timer = eTimer()
411 self.upgrade_auto_run_timer.callback.append(self.keyGreen)
415 self["key_green"] = StaticText(_(" "))
416 self["status"] = StaticText(_("This plugin is supported only the Ultimo/Uno."))
418 self["key_green"] = StaticText(_("Upgrade"))
419 self["status"] = StaticText(_(" "))
425 self._item_firmware = ConfigSelection(default=fwlist[0][0], choices=fwlist)
426 self._entry_firmware = getConfigListEntry(_("Firmware"), self._item_firmware)
427 self.list.append(self._entry_firmware)
428 self["config"].list = self.list
429 self["config"].l.setList(self.list)
432 def setupStatus(self,message=None,reboot=False):
433 self.updateFilePath = ""
434 if message is not None:
435 self.rebootLock = reboot
436 self["status"].setText(message)
438 self.rebootMessage = message
439 self.reboot_timer = eTimer()
440 self.reboot_timer.callback.append(self.cbReboot)
441 self.reboot_timer.start(1000)
443 if not self.rebootLock:
444 self["status"].setText("Press the Green/OK button")
447 from Screens.Standby import TryQuitMainloop
448 self.session.open(TryQuitMainloop, 2)
452 self.finishedExit = True
453 if self.cbRebootCallCount < max_call_count:
454 self.cbRebootCallCount = self.cbRebootCallCount + 1
455 #self["status"].setText("%s (%d)"%(self.rebootMessage, max_call_count-self.cbRebootCallCount))
456 self["status"].setText("Reboot after %d seconds. Press the OK to reboot now."%(max_call_count-self.cbRebootCallCount))
460 # filebrowser window callback function
461 def cbSetStatus(self, data=None):
463 self["status"].setText("Press the Green/OK button, if you want to upgrade to this file:\n%s\n" % (data))
464 self.updateFilePath = data
465 if self.fileopenmode == False:
466 self.upgrade_auto_run_timer.start(1000)
468 # upgrade window callback function
469 def cbFinishedUpgrade(self,message=None,reboot=False):
470 self.setupStatus(message=message,reboot=reboot)
472 def cbRunUpgrade(self, ret):
476 if self.updateFilePath == "":
477 self.session.open(MessageBox, _("No selected binary data!!"), MessageBox.TYPE_INFO, timeout = 10)
480 for d in fwdata[self._item_firmware.value][2].split(';'):
481 if os.path.exists(d):
484 self.session.open(MessageBox, _("Can't found device file!!"), MessageBox.TYPE_INFO, timeout = 10)
486 fbs = self.session.open(UpgradeStatus, self, self._item_firmware.value, self.updateFilePath, device)
487 fbs.setCallback(self.cbFinishedUpgrade)
489 def doFileOpen(self):
490 fbs = self.session.open(Filebrowser, self, self._item_firmware.value)
491 fbs.setCallback(self.cbSetStatus)
499 ConfigListScreen.keyLeft(self)
506 ConfigListScreen.keyRight(self)
510 if self.finishedExit:
513 self.upgrade_auto_run_timer.stop()
519 if self.updateFilePath == "":
520 #self.session.open(MessageBox, _("No selected binary data!!"), MessageBox.TYPE_INFO)
523 msg = "You should not be stop during the upgrade.\nDo you want to upgrade?"
524 self.session.openWithCallback(self.cbRunUpgrade, MessageBox, _(msg), MessageBox.TYPE_YESNO, timeout = 15, default = True)
525 self.fileopenmode = False
533 self.fileopenmode = True
542 if self.old_blue_clicked:
545 if os.path.exists("/tmp/onlogmode"):
547 os.system("touch /tmp/onlogmode")
552 if self.logmode is not None and self.old_blue_clicked == 0:
554 if self.old_blue_clicked:
555 self.old_blue_clicked = 0
557 self.old_blue_clicked = 1
558 self.logmode = eTimer()
559 self.logmode.callback.append(self.cbLogMode)
560 self.logmode.start(1000)
565 def main(session, **kwargs):
566 session.open(FirmwareUpgrade)
568 def Plugins(**kwargs):
569 return PluginDescriptor(name=_("Firmware Upgrade"), description="Upgrade Firmware..", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)