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()
31 ("fp", _("Front Processor"))
35 "fp" : ["http://archive.vuplus.com/download/fp", "fp.files", "/dev/bcm_mu;"]
36 ,"fpga" : ["http://archive.vuplus.com/download/fpga", "fpga.files", "/dev/fpga_dp;/dev/misc/dp;"]
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:
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="180,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"))
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):
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)
254 f, h = urlretrieve(uri, tar, doHook)
256 self.session.open(MessageBox, _(str(msg)), MessageBox.TYPE_INFO, timeout = 10)
262 def runDownloading(self) :
263 self.timer_downloading.stop()
264 machine = str(open("/proc/stb/info/vumodel").read().strip())
266 def cbDownloadDone(tar):
268 if os.path.splitext(tar)[1] != ".files":
269 self["status"].setText("Downloaded : %s\nSelect to press OK, Exit to press Cancel."%(tar))
274 root_uri = fwdata[self.firmware][0]
275 root_file = fwdata[self.firmware][1]
276 if not self.doDownload("%s/%s"%(root_uri, root_file), root_file, cbfunc=cbDownloadDone):
278 self.downloadLock = False
282 for l in file("/tmp/"+root_file).readlines():
283 if l.startswith(machine):
285 target_path = l.split("=")[1].strip()
289 if target_path == "":
290 self.session.open(MessageBox, _("Firmware does not exist."), MessageBox.TYPE_INFO)
292 self.downloadLock = False
295 self.guri = "%s/vu%s/%s"%(root_uri, machine, target_path)
296 self.gbin = os.path.basename(target_path)
297 #print "[FirmwareUpgrade] - uri[%s], data[%s], data_path[%s]" % (self.gbin, self.guri, target_path)
298 os.system("rm -f /tmp/" + root_file)
301 if not self.doDownload(self.guri+".md5", self.gbin+".md5", cbfunc=cbDownloadDone):
303 self.downloadLock = False
306 if not self.doDownload(self.guri, self.gbin, cbfunc=cbDownloadDone):
308 self.downloadLock = False
312 self["file_list"].changeDir("/tmp/")
313 self["file_list"].moveToIndex(0)
314 while cmp(self["file_list"].getFilename(), self.gbin) != 0 :
315 self["file_list"].down()
316 if cmp(t, self["file_list"].getFilename()) == 0:
318 t = self["file_list"].getFilename()
320 del self.timer_downloading
321 self.timer_downloading = None
322 self.downloadLock = False
324 def onClickBlue(self):
325 if self.downloadLock:
327 self.downloadLock = True
328 if not os.path.exists("/proc/stb/info/vumodel"):
329 self.session.open(MessageBox, _("Can't found model name."), MessageBox.TYPE_INFO, timeout = 10)
330 self.downloadLock = False
332 self["status"].setText("Please wait during download.")
333 self.timer_downloading = eTimer()
334 self.timer_downloading.callback.append(self.runDownloading)
335 self.timer_downloading.start(1000)
338 if self.downloadLock:
341 self["file_list"].up()
343 def onClickDown(self):
344 if self.downloadLock:
347 self["file_list"].down()
349 def onClickLeft(self):
350 if self.downloadLock:
353 self["file_list"].pageUp()
355 def onClickRight(self):
356 if self.downloadLock:
359 self["file_list"].pageDown()
364 class FirmwareUpgrade(Screen, ConfigListScreen):
366 <screen position="center,center" size="560,175" title="Firmware Upgrade" >
367 <ePixmap pixmap="Vu_HD/buttons/red.png" position="125,7" size="80,40" alphatest="blend" />
368 <ePixmap pixmap="Vu_HD/buttons/green.png" position="330,7" size="80,40" alphatest="blend" />
370 <widget source="key_red" render="Label" position="160,0" zPosition="1" size="155,40" font="Regular;20" halign="left" valign="center" transparent="1" />
371 <widget source="key_green" render="Label" position="365,0" zPosition="1" size="155,40" font="Regular;20" halign="left" valign="center" transparent="1" />
373 <widget name="config" zPosition="2" position="0,50" itemHeight="36" size="540,40" scrollbarMode="showOnDemand" transparent="1" />
374 <widget source="status" render="Label" position="0,100" zPosition="1" size="540,75" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
378 def __init__(self, session):
379 Screen.__init__(self, session)
380 self.session = session
382 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
385 "cancel": self.keyRed,
387 "green": self.keyGreen,
388 "blue": self.keyBlue,
392 self.updateFilePath = ""
394 self.rebootLock = False
395 self.rebootMessage = ""
396 self.cbRebootCallCount = 0;
398 ConfigListScreen.__init__(self, self.list, session=self.session)
399 self["key_red"] = StaticText(_("Close"))
402 self.old_blue_clicked = 0
403 self.fileopenmode = False
404 self.upgrade_auto_run_timer = eTimer()
405 self.upgrade_auto_run_timer.callback.append(self.keyGreen)
409 self["key_green"] = StaticText(_(" "))
410 self["status"] = StaticText(_("This plugin is supported only the Ultimo/Uno."))
412 self["key_green"] = StaticText(_("Upgrade"))
413 self["status"] = StaticText(_(" "))
419 self._item_firmware = ConfigSelection(default=fwlist[0][0], choices=fwlist)
420 self._entry_firmware = getConfigListEntry(_("Firmware"), self._item_firmware)
421 self.list.append(self._entry_firmware)
422 self["config"].list = self.list
423 self["config"].l.setList(self.list)
426 def setupStatus(self,message=None,reboot=False):
427 self.updateFilePath = ""
428 if message is not None:
429 self.rebootLock = reboot
430 self["status"].setText(message)
432 self.rebootMessage = message
433 self.reboot_timer = eTimer()
434 self.reboot_timer.callback.append(self.cbReboot)
435 self.reboot_timer.start(500)
437 if not self.rebootLock:
438 self["status"].setText("Press the Green/OK button")
441 if self.cbRebootCallCount < 6:
442 self.cbRebootCallCount = self.cbRebootCallCount + 1
443 self["status"].setText("%s (%d)"%(self.rebootMessage, 6-self.cbRebootCallCount))
445 from Screens.Standby import TryQuitMainloop
446 self.session.open(TryQuitMainloop, 2)
448 # filebrowser window callback function
449 def cbSetStatus(self, data=None):
451 self["status"].setText("Press the Green/OK button, if you want to upgrade to this file:\n%s\n" % (data))
452 self.updateFilePath = data
453 if self.fileopenmode == False:
454 self.upgrade_auto_run_timer.start(1000)
456 # upgrade window callback function
457 def cbFinishedUpgrade(self,message=None,reboot=False):
458 self.setupStatus(message=message,reboot=reboot)
460 def cbRunUpgrade(self, ret):
464 if self.updateFilePath == "":
465 self.session.open(MessageBox, _("No selected binary data!!"), MessageBox.TYPE_INFO, timeout = 10)
468 for d in fwdata[self._item_firmware.value][2].split(';'):
469 if os.path.exists(d):
472 self.session.open(MessageBox, _("Can't found device file!!"), MessageBox.TYPE_INFO, timeout = 10)
474 fbs = self.session.open(UpgradeStatus, self, self._item_firmware.value, self.updateFilePath, device)
475 fbs.setCallback(self.cbFinishedUpgrade)
477 def doFileOpen(self):
478 fbs = self.session.open(Filebrowser, self, self._item_firmware.value)
479 fbs.setCallback(self.cbSetStatus)
487 ConfigListScreen.keyLeft(self)
494 ConfigListScreen.keyRight(self)
498 self.upgrade_auto_run_timer.stop()
504 if self.updateFilePath == "":
505 #self.session.open(MessageBox, _("No selected binary data!!"), MessageBox.TYPE_INFO)
508 msg = "You should not be stop during the upgrade.\nDo you want to upgrade?"
509 self.session.openWithCallback(self.cbRunUpgrade, MessageBox, _(msg), MessageBox.TYPE_YESNO, timeout = 15, default = True)
510 self.fileopenmode = False
518 self.fileopenmode = True
527 if self.old_blue_clicked:
530 if os.path.exists("/tmp/onlogmode"):
532 os.system("touch /tmp/onlogmode")
537 if self.logmode is not None and self.old_blue_clicked == 0:
539 if self.old_blue_clicked:
540 self.old_blue_clicked = 0
542 self.old_blue_clicked = 1
543 self.logmode = eTimer()
544 self.logmode.callback.append(self.cbLogMode)
545 self.logmode.start(1000)
550 def main(session, **kwargs):
551 session.open(FirmwareUpgrade)
553 def Plugins(**kwargs):
554 return PluginDescriptor(name=_("Firmware Upgrade"), description="Upgrade Firmware..", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)