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.rebootLock = False
399 self.rebootMessage = ""
400 self.cbRebootCallCount = 0;
402 ConfigListScreen.__init__(self, self.list, session=self.session)
403 self["key_red"] = StaticText(_("Close"))
406 self.old_blue_clicked = 0
407 self.fileopenmode = False
408 self.upgrade_auto_run_timer = eTimer()
409 self.upgrade_auto_run_timer.callback.append(self.keyGreen)
413 self["key_green"] = StaticText(_(" "))
414 self["status"] = StaticText(_("This plugin is supported only the Ultimo/Uno."))
416 self["key_green"] = StaticText(_("Upgrade"))
417 self["status"] = StaticText(_(" "))
423 self._item_firmware = ConfigSelection(default=fwlist[0][0], choices=fwlist)
424 self._entry_firmware = getConfigListEntry(_("Firmware"), self._item_firmware)
425 self.list.append(self._entry_firmware)
426 self["config"].list = self.list
427 self["config"].l.setList(self.list)
430 def setupStatus(self,message=None,reboot=False):
431 self.updateFilePath = ""
432 if message is not None:
433 self.rebootLock = reboot
434 self["status"].setText(message)
436 self.rebootMessage = message
437 self.reboot_timer = eTimer()
438 self.reboot_timer.callback.append(self.cbReboot)
439 self.reboot_timer.start(500)
441 if not self.rebootLock:
442 self["status"].setText("Press the Green/OK button")
445 if self.cbRebootCallCount < 6:
446 self.cbRebootCallCount = self.cbRebootCallCount + 1
447 self["status"].setText("%s (%d)"%(self.rebootMessage, 6-self.cbRebootCallCount))
449 from Screens.Standby import TryQuitMainloop
450 self.session.open(TryQuitMainloop, 2)
452 # filebrowser window callback function
453 def cbSetStatus(self, data=None):
455 self["status"].setText("Press the Green/OK button, if you want to upgrade to this file:\n%s\n" % (data))
456 self.updateFilePath = data
457 if self.fileopenmode == False:
458 self.upgrade_auto_run_timer.start(1000)
460 # upgrade window callback function
461 def cbFinishedUpgrade(self,message=None,reboot=False):
462 self.setupStatus(message=message,reboot=reboot)
464 def cbRunUpgrade(self, ret):
468 if self.updateFilePath == "":
469 self.session.open(MessageBox, _("No selected binary data!!"), MessageBox.TYPE_INFO, timeout = 10)
472 for d in fwdata[self._item_firmware.value][2].split(';'):
473 if os.path.exists(d):
476 self.session.open(MessageBox, _("Can't found device file!!"), MessageBox.TYPE_INFO, timeout = 10)
478 fbs = self.session.open(UpgradeStatus, self, self._item_firmware.value, self.updateFilePath, device)
479 fbs.setCallback(self.cbFinishedUpgrade)
481 def doFileOpen(self):
482 fbs = self.session.open(Filebrowser, self, self._item_firmware.value)
483 fbs.setCallback(self.cbSetStatus)
491 ConfigListScreen.keyLeft(self)
498 ConfigListScreen.keyRight(self)
502 self.upgrade_auto_run_timer.stop()
508 if self.updateFilePath == "":
509 #self.session.open(MessageBox, _("No selected binary data!!"), MessageBox.TYPE_INFO)
512 msg = "You should not be stop during the upgrade.\nDo you want to upgrade?"
513 self.session.openWithCallback(self.cbRunUpgrade, MessageBox, _(msg), MessageBox.TYPE_YESNO, timeout = 15, default = True)
514 self.fileopenmode = False
522 self.fileopenmode = True
531 if self.old_blue_clicked:
534 if os.path.exists("/tmp/onlogmode"):
536 os.system("touch /tmp/onlogmode")
541 if self.logmode is not None and self.old_blue_clicked == 0:
543 if self.old_blue_clicked:
544 self.old_blue_clicked = 0
546 self.old_blue_clicked = 1
547 self.logmode = eTimer()
548 self.logmode.callback.append(self.cbLogMode)
549 self.logmode.start(1000)
554 def main(session, **kwargs):
555 session.open(FirmwareUpgrade)
557 def Plugins(**kwargs):
558 return PluginDescriptor(name=_("Firmware Upgrade"), description="Upgrade Firmware..", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)