1 # -*- coding: utf-8 -*-
2 from Components.MenuList import MenuList
3 from Screens.Screen import Screen
4 from Screens.MessageBox import MessageBox
5 from Screens.ChoiceBox import ChoiceBox
6 from Components.ActionMap import ActionMap
7 from Components.Sources.StaticText import StaticText
8 from Components.Sources.Progress import Progress
9 from Components.Label import Label
10 from Components.FileList import FileList
11 from Components.MultiContent import MultiContentEntryText
12 from Components.ScrollLabel import ScrollLabel
13 from Tools.Directories import fileExists
14 from Tools.HardwareInfo import HardwareInfo
15 from enigma import eConsoleAppContainer, eListbox, gFont, eListboxPythonMultiContent, \
16 RT_HALIGN_LEFT, RT_HALIGN_CENTER, RT_VALIGN_CENTER, RT_WRAP, eRect, eTimer
17 from os import system, remove
20 from Tools.Downloader import downloadWithProgress
21 from twisted.web import client
22 from twisted.internet import reactor, defer
23 from twisted.python import failure
24 from Plugins.SystemPlugins.Hotplug.plugin import hotplugNotifier
26 class UserRequestedCancel(Exception):
29 class Feedlist(MenuList):
30 def __init__(self, list=[], enableWrapAround = False):
31 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
32 self.l.setFont(0, gFont("Regular", 16))
33 self.l.setItemHeight(22)
37 self.l.setList(self.list)
40 l = self.l.getCurrentSelection()
44 l = self.l.getCurrentSelection()
48 l = self.l.getCurrentSelection()
49 return l and l[0][0][:-3]+"nfo"
52 l = self.l.getCurrentSelection()
53 return l and l[0][1][:-3]+"nfo"
56 l = self.l.getCurrentSelection()
57 if not l or l[0] == 0:
62 def moveSelection(self,idx=0):
63 if self.instance is not None:
64 self.instance.moveSelectionTo(idx)
66 class NFOViewer(Screen):
68 <screen name="NFOViewer" position="110,115" size="540,400" title="Changelog viewer" >
69 <widget name="changelog" position="10,10" size="520,380" font="Regular;16" />
72 def __init__(self, session, nfo):
73 Screen.__init__(self, session)
74 self["changelog"] = ScrollLabel(nfo)
76 self["ViewerActions"] = ActionMap(["SetupActions", "ColorActions", "DirectionActions"],
82 "down": self.pageDown,
86 self["changelog"].pageUp()
89 self["changelog"].pageDown()
94 class NFIDownload(Screen):
98 <screen name="NFIDownload" position="90,95" size="560,420" title="Image download utility">
99 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
100 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
101 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
102 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
103 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;19" valign="center" halign="center" backgroundColor="#9f1313" transparent="1" />
104 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;19" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
105 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;19" valign="center" halign="center" backgroundColor="#a08500" transparent="1" />
106 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;19" valign="center" halign="center" backgroundColor="#18188b" transparent="1" />
108 <widget source="label_top" render="Label" position="10,44" size="240,20" font="Regular;16" />
109 <widget name="feedlist" position="10,66" size="250,222" scrollbarMode="showOnDemand" />
110 <widget name="destlist" position="0,66" size="260,222" scrollbarMode="showOnDemand" />
112 <widget source="label_bottom" render="Label" position="10,312" size="240,18" font="Regular;16"/>
113 <widget source="path_bottom" render="Label" position="10,330" size="250,42" font="Regular;18" />
115 <widget source="infolabel" render="Label" position="270,44" size="280,284" font="Regular;16" />
116 <widget source="job_progressbar" render="Progress" position="10,374" size="540,26" borderWidth="1" backgroundColor="#254f7497" />
117 <widget source="job_progresslabel" render="Label" position="130,378" zPosition="2" font="Regular;18" halign="center" transparent="1" size="300,22" foregroundColor="#000000" />
118 <widget source="statusbar" render="Label" position="10,404" size="540,16" font="Regular;16" foregroundColor="#cccccc" />
121 def __init__(self, session, destdir="/tmp/"):
122 self.skin = NFIDownload.skin
123 Screen.__init__(self, session)
125 self["job_progressbar"] = Progress()
126 self["job_progresslabel"] = StaticText()
128 self["infolabel"] = StaticText()
129 self["statusbar"] = StaticText()
130 self["label_top"] = StaticText()
131 self["label_bottom"] = StaticText()
132 self["path_bottom"] = StaticText()
134 self["key_green"] = StaticText()
135 self["key_yellow"] = StaticText()
136 self["key_blue"] = StaticText()
138 self["key_red"] = StaticText()
140 self["feedlist"] = Feedlist([0,(eListboxPythonMultiContent.TYPE_TEXT, 0, 0,250, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, "feed not available")])
141 self["destlist"] = FileList(destdir, showDirectories = True, showFiles = False)
142 self["destlist"].hide()
144 self.download_container = eConsoleAppContainer()
150 self.box = HardwareInfo().get_device_name()
151 self.feed_base = "http://www.dreamboxupdate.com/opendreambox/1.5/%s/images/" % self.box
152 self.nfi_filter = "" # "release" # only show NFIs containing this string, or all if ""
153 self.wizard_mode = False
155 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "EPGSelectActions"],
157 "cancel": self.closeCB,
159 "green": self.nfi_download,
160 "yellow": self.switchList,
161 "blue": self.askCreateUSBstick,
162 "prevBouquet": self.switchList,
163 "nextBouquet": self.switchList,
168 "upRepeated": self.up,
169 "downRepeated": self.down,
175 def downloading(self, state=True):
177 self["key_red"].text = _("Cancel")
178 self["key_green"].text = ""
179 self["key_yellow"].text = ""
180 self["key_blue"].text = ""
183 self["key_red"].text = _("Exit")
184 if self["feedlist"].isValid():
185 self["key_green"].text = (_("Download"))
186 if self.focus is self.LIST_SOURCE:
187 self["key_yellow"].text = (_("Change dir."))
189 self["key_yellow"].text = (_("Select image"))
190 self["key_blue"].text = (_("USB stick wizard"))
192 def switchList(self,to_where=None):
193 if self.download or not self["feedlist"].isValid():
196 self["job_progressbar"].value = 0
197 self["job_progresslabel"].text = ""
200 if self.focus is self.LIST_SOURCE:
201 to_where = self.LIST_DEST
202 if self.focus is self.LIST_DEST:
203 to_where = self.LIST_SOURCE
205 if to_where is self.LIST_DEST:
206 self.focus = self.LIST_DEST
207 self["statusbar"].text = _("Please select target directory or medium")
208 self["label_top"].text = _("choose destination directory")+":"
209 self["feedlist"].hide()
210 self["destlist"].show()
211 self["label_bottom"].text = _("Selected source image")+":"
212 self["path_bottom"].text = str(self["feedlist"].getNFIname())
213 self["key_yellow"].text = (_("Select image"))
215 elif to_where is self.LIST_SOURCE:
216 self.focus = self.LIST_SOURCE
217 self["statusbar"].text = _("Please choose .NFI image file from feed server to download")
218 self["label_top"].text = _("select image from server")+":"
219 self["feedlist"].show()
220 self["destlist"].hide()
221 self["label_bottom"].text = _("Destination directory")+":"
222 self["path_bottom"].text = str(self["destlist"].getCurrentDirectory())
223 self["key_yellow"].text = (_("Change dir."))
228 if self.focus is self.LIST_SOURCE:
229 self["feedlist"].up()
231 if self.focus is self.LIST_DEST:
232 self["destlist"].up()
237 if self.focus is self.LIST_SOURCE:
238 self["feedlist"].down()
240 if self.focus is self.LIST_DEST:
241 self["destlist"].down()
246 if self.focus is self.LIST_SOURCE:
247 self["feedlist"].pageUp()
249 if self.focus is self.LIST_DEST:
250 self["destlist"].pageUp()
255 if self.focus is self.LIST_SOURCE:
256 self["feedlist"].pageDown()
258 if self.focus is self.LIST_DEST:
259 self["destlist"].pageDown()
262 if self.focus is self.LIST_SOURCE and self.nfo:
263 self.session.open(NFOViewer, self.nfo)
266 if self.focus is self.LIST_DEST:
267 if self["destlist"].canDescent():
268 self["destlist"].descent()
270 def feed_download(self):
271 self.downloading(True)
272 self.download = self.feed_download
273 client.getPage(self.feed_base).addCallback(self.feed_finished).addErrback(self.feed_failed)
275 def feed_failed(self, failure_instance):
276 print "[feed_failed] " + str(failure_instance)
277 self["infolabel"].text = _("Could not connect to Dreambox .NFI Image Feed Server:") + "\n" + failure_instance.getErrorMessage() + "\n\n" + _("Please check your network settings!")
278 self.downloading(False)
280 def feed_finished(self, feedhtml):
281 print "[feed_finished] " + str(feedhtml)
282 self.downloading(False)
283 fileresultmask = re.compile("<a class=[\'\"]nfi[\'\"] href=[\'\"](?P<url>.*?)[\'\"]>(?P<name>.*?.nfi)</a>", re.DOTALL)
284 searchresults = fileresultmask.finditer(feedhtml)
287 for x in searchresults:
289 if url[0:7] != "http://":
290 url = self.feed_base + x.group("url")
291 name = x.group("name")
292 if name.find(self.nfi_filter) > -1:
293 entry = [[name, url],(eListboxPythonMultiContent.TYPE_TEXT, 0, 0,250, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, name)]
294 print "adding to feedlist: " + str(entry)
295 fileresultlist.append(entry)
297 print "NOT adding to feedlist: " + name
298 self["feedlist"].l.setList(fileresultlist)
299 self["feedlist"].moveSelection(0)
301 if len(fileresultlist) > 0:
302 self.switchList(self.LIST_SOURCE)
305 self["infolabel"].text = _("Cannot parse feed directory")
307 def nfo_download(self):
308 print "[check_for_NFO]"
309 if self["feedlist"].isValid():
310 print "nfiname: " + self["feedlist"].getNFIname()
311 self["job_progressbar"].value = 0
312 self["job_progresslabel"].text = ""
313 if self["feedlist"].getNFIurl() is None:
314 self["key_green"].text = ""
316 self["key_green"].text = _("Download")
317 nfourl = self["feedlist"].getNFOurl()
318 print "downloading " + nfourl
319 self.download = self.nfo_download
320 self.downloading(True)
321 client.getPage(nfourl).addCallback(self.nfo_finished).addErrback(self.nfo_failed)
322 self["statusbar"].text = ("Downloading image description...")
324 def nfo_failed(self, failure_instance):
325 print "[nfo_failed] " + str(failure_instance)
326 self["infolabel"].text = _("No details for this image file") + "\n" + self["feedlist"].getNFIname()
327 self["statusbar"].text = ""
328 self.nfofilename = ""
330 self.downloading(False)
332 def nfo_finished(self,nfodata=""):
333 print "[nfo_finished] " + str(nfodata)
334 self.downloading(False)
337 self.nfofilename = self["destlist"].getCurrentDirectory() + '/' + self["feedlist"].getNFOname()
338 self["infolabel"].text = self.nfo
340 self.nfofilename = ""
341 self["infolabel"].text = _("No details for this image file")
342 self["statusbar"].text = _("Press OK to view full changelog")
344 def nfi_download(self):
345 if self["destlist"].getCurrentDirectory() is None:
346 self.switchList(self.LIST_TARGET)
347 if self["feedlist"].isValid():
348 url = self["feedlist"].getNFIurl()
349 self.nfilocal = self["destlist"].getCurrentDirectory()+'/'+self["feedlist"].getNFIname()
350 print "[nfi_download] downloading %s to %s" % (url, self.nfilocal)
351 self.download = downloadWithProgress(url,self.nfilocal)
352 self.download.addProgress(self.nfi_progress)
353 self["job_progressbar"].range = 1000
354 self.download.start().addCallback(self.nfi_finished).addErrback(self.nfi_failed)
355 self.downloading(True)
357 def nfi_progress(self, recvbytes, totalbytes):
358 #print "[update_progress] recvbytes=%d, totalbytes=%d" % (recvbytes, totalbytes)
359 self["job_progressbar"].value = int(1000*recvbytes/float(totalbytes))
360 self["job_progresslabel"].text = "%d of %d kBytes (%.2f%%)" % (recvbytes/1024, totalbytes/1024, 100*recvbytes/float(totalbytes))
362 def nfi_failed(self, failure_instance=None, error_message=""):
363 if error_message == "" and failure_instance is not None:
364 error_message = failure_instance.getErrorMessage()
365 print "[nfi_failed] " + error_message
366 if fileExists(self["destlist"].getCurrentDirectory()+'/'+self["feedlist"].getNFIname()):
367 message = "%s %s\n%s" % (_(".NFI Download failed:"), error_message, _("Remove the incomplete .NFI file?"))
368 self.session.openWithCallback(self.nfi_remove, MessageBox, message, MessageBox.TYPE_YESNO)
370 message = "%s %s" % (_(".NFI Download failed:"),error_message)
371 self.session.open(MessageBox, message, MessageBox.TYPE_ERROR)
372 self.downloading(False)
374 def nfi_finished(self, string=""):
375 print "[nfi_finished] " + str(string)
377 self.nfofilename = self["destlist"].getCurrentDirectory() + '/' + self["feedlist"].getNFOname()
378 nfofd = open(self.nfofilename, "w")
380 nfofd.write(self.nfo)
383 print "couldn't save nfo file " + self.nfofilename
385 pos = self.nfo.find("MD5:")
386 if pos > 0 and len(self.nfo) >= pos+5+32:
387 self["statusbar"].text = ("Please wait for md5 signature verification...")
389 md5 = self.nfo[pos+5:pos+5+32] + " " + self.nfilocal
391 self.download_container.setCWD(self["destlist"].getCurrentDirectory())
392 self.download_container.appClosed.append(self.md5finished)
393 self.download_container.execute(cmd)
394 self.download_container.write(md5)
395 self.download_container.dataSent.append(self.md5ready)
397 self["statusbar"].text = "Download completed."
398 self.downloading(False)
400 self["statusbar"].text = "Download completed."
401 self.downloading(False)
405 def md5ready(self, retval):
406 self.download_container.sendEOF()
408 def md5finished(self, retval):
409 print "[md5finished]: " + str(retval)
410 self.download_container.appClosed.remove(self.md5finished)
412 self.downloading(False)
416 self["statusbar"].text = _(".NFI file passed md5sum signature check. You can safely flash this image!")
417 self.switchList(self.LIST_SOURCE)
419 self.session.openWithCallback(self.nfi_remove, MessageBox, (_("The md5sum validation failed, the file may be downloaded incompletely or be corrupted!") + "\n" + _("Remove the broken .NFI file?")), MessageBox.TYPE_YESNO)
421 def nfi_remove(self, answer):
422 self.downloading(False)
424 nfifilename = self["destlist"].getCurrentDirectory()+'/'+self["feedlist"].getNFIname()
425 if fileExists(self.nfofilename):
426 remove(self.nfofilename)
427 if fileExists(nfifilename):
429 self.switchList(self.LIST_SOURCE)
431 def askCreateUSBstick(self):
433 self.imagefilename = "/tmp/nfiflash_" + self.box + ".img"
434 message = _("You have chosen to create a new .NFI flasher bootable USB stick. This will repartition the USB stick and therefore all data on it will be erased.")
435 self.session.openWithCallback(self.flasherdownload_query, MessageBox, (message + '\n' + _("First we need to download the latest boot environment for the USB flasher.")), MessageBox.TYPE_YESNO)
437 def flasherdownload_query(self, answer):
439 self.downloading(False)
440 self.switchList(self.LIST_SOURCE)
442 #url = self.feed_base + "/nfiflasher_" + self.box + ".tar.bz2"
443 url = "http://www.dreamboxupdate.com/download/opendreambox/dreambox-nfiflasher-%s.tar.bz2" % self.box
444 localfile = "/tmp/nfiflasher_image.tar.bz2"
445 print "[flasherdownload_query] downloading %s to %s" % (url, localfile)
446 self["statusbar"].text = ("Downloading %s..." % url)
447 self.download = downloadWithProgress(url,localfile)
448 self.download.addProgress(self.nfi_progress)
449 self["job_progressbar"].range = 1000
450 self.download.start().addCallback(self.flasherdownload_finished).addErrback(self.flasherdownload_failed)
452 def flasherdownload_failed(self, failure_instance=None, error_message=""):
453 if error_message == "" and failure_instance is not None:
454 error_message = failure_instance.getErrorMessage()
455 print "[flasherdownload_failed] " + error_message
456 message = "%s %s" % (_("Download of USB flasher boot image failed: "),error_message)
457 self.session.open(MessageBox, message, MessageBox.TYPE_ERROR)
458 self.remove_img(True)
460 def flasherdownload_finished(self, string=""):
461 print "[flasherdownload_finished] " + str(string)
462 self.container = eConsoleAppContainer()
463 self.container.appClosed.append(self.umount_finished)
464 self.container.dataAvail.append(self.tool_avail)
467 from os import listdir
468 for device in listdir("/dev"):
469 if device[:2] == "sd" and device[-1:].isdigit():
470 umountdevs += "/dev/"+device
471 self.cmd = "umount " + umountdevs
472 print "executing " + self.cmd
473 self.container.execute(self.cmd)
475 def tool_avail(self, string):
476 print "[tool_avail]" + string
477 self.taskstring += string
479 def umount_finished(self, retval):
480 self.container.appClosed.remove(self.umount_finished)
481 self.container.appClosed.append(self.dmesg_cleared)
483 self.cmd = "dmesg -c"
484 print "executing " + self.cmd
485 self.container.execute(self.cmd)
487 def dmesg_cleared(self, answer):
488 self.container.appClosed.remove(self.dmesg_cleared)
489 self.msgbox = self.session.open(MessageBox, _("Please disconnect all USB devices from your Dreambox and (re-)attach the target USB stick (minimum size is 64 MB) now!"), MessageBox.TYPE_INFO)
490 hotplugNotifier.append(self.hotplugCB)
492 def hotplugCB(self, dev, action):
493 print "[hotplugCB]", dev, action
494 if dev.startswith("sd") and action == "add":
496 hotplugNotifier.remove(self.hotplugCB)
497 self.container.appClosed.append(self.dmesg_scanned)
500 print "executing " + self.cmd
501 self.container.execute(self.cmd)
503 def dmesg_scanned(self, retval):
504 self.container.appClosed.remove(self.dmesg_scanned)
505 dmesg_lines = self.taskstring.splitlines()
506 self.devicetext = None
507 self.stickdevice = None
508 for i, line in enumerate(dmesg_lines):
509 if line.find("usb-storage: waiting for device") != -1 and len(dmesg_lines) > i+3:
510 self.devicetext = dmesg_lines[i+1].lstrip()+"\n"+dmesg_lines[i+3]
511 elif line.find("/dev/scsi/host") != -1:
512 self.stickdevice = line.split(":",1)[0].lstrip()
514 if retval != 0 or self.devicetext is None or self.stickdevice is None:
515 self.session.openWithCallback(self.remove_img, MessageBox, _("No useable USB stick found"), MessageBox.TYPE_ERROR)
517 self.session.openWithCallback(self.fdisk_query, MessageBox, (_("The following device was found:\n\n%s\n\nDo you want to write the USB flasher to this stick?") % self.devicetext), MessageBox.TYPE_YESNO)
519 def fdisk_query(self, answer):
520 if answer == True and self.stickdevice:
521 self["statusbar"].text = ("Partitioning USB stick...")
522 self["job_progressbar"].range = 1000
523 self["job_progressbar"].value = 100
524 self["job_progresslabel"].text = "5.00%"
526 self.container.appClosed.append(self.fdisk_finished)
527 self.container.execute("fdisk " + self.stickdevice + "/disc")
528 self.container.write("d\n4\nd\n3\nd\n2\nd\nn\np\n1\n\n\nt\n6\nw\n")
529 self.delayTimer = eTimer()
530 self.delayTimer.callback.append(self.progress_increment)
531 self.delayTimer.start(105, False)
533 self.remove_img(True)
535 def fdisk_finished(self, retval):
536 self.container.appClosed.remove(self.fdisk_finished)
537 self.delayTimer.stop()
539 if fileExists(self.imagefilename):
541 self["job_progressbar"].value = 700
543 self["statusbar"].text = ("Decompressing USB stick flasher boot image...")
545 self.container.appClosed.append(self.tar_finished)
546 self.container.setCWD("/tmp")
547 self.cmd = "tar -xjvf nfiflasher_image.tar.bz2"
548 self.container.execute(self.cmd)
549 print "executing " + self.cmd
550 self.delayTimer = eTimer()
551 self.delayTimer.callback.append(self.progress_increment)
552 self.delayTimer.start(105, False)
554 print "fdisk failed: " + str(retval)
555 self.session.openWithCallback(self.remove_img, MessageBox, ("fdisk " + _("failed") + ":\n" + str(self.taskstring)), MessageBox.TYPE_ERROR)
557 def progress_increment(self):
558 newval = int(self["job_progressbar"].value) + 1
560 self["job_progressbar"].value = newval
561 self["job_progresslabel"].text = "%.2f%%" % (newval/10.0)
563 def tar_finished(self, retval):
564 self.delayTimer.stop()
565 if len(self.container.appClosed) > 0:
566 self.container.appClosed.remove(self.tar_finished)
568 self.imagefilename = "/tmp/nfiflash_" + self.box + ".img"
569 self["statusbar"].text = ("Copying USB flasher boot image to stick...")
571 self.container.appClosed.append(self.dd_finished)
572 self.cmd = "dd if=%s of=%s" % (self.imagefilename,self.stickdevice+"/part1")
573 self.container.execute(self.cmd)
574 print "executing " + self.cmd
575 self.delayTimer = eTimer()
576 self.delayTimer.callback.append(self.progress_increment)
577 self.delayTimer.start(105, False)
579 self.session.openWithCallback(self.remove_img, MessageBox, (self.cmd + " " + _("failed") + ":\n" + str(self.taskstring)), MessageBox.TYPE_ERROR)
581 def dd_finished(self, retval):
582 self.delayTimer.stop()
583 self.container.appClosed.remove(self.dd_finished)
584 self.downloading(False)
586 self["job_progressbar"].value = 950
587 self["job_progresslabel"].text = "95.00%"
588 self["statusbar"].text = ("Remounting stick partition...")
590 self.container.appClosed.append(self.mount_finished)
591 self.cmd = "mount %s /mnt/usb -o rw,sync" % (self.stickdevice+"/part1")
592 self.container.execute(self.cmd)
593 print "executing " + self.cmd
595 self.session.openWithCallback(self.remove_img, MessageBox, (self.cmd + " " + _("failed") + ":\n" + str(self.taskstring)), MessageBox.TYPE_ERROR)
597 def mount_finished(self, retval):
598 self.container.dataAvail.remove(self.tool_avail)
599 self.container.appClosed.remove(self.mount_finished)
601 self["job_progressbar"].value = 1000
602 self["job_progresslabel"].text = "100.00%"
603 self["statusbar"].text = (".NFI Flasher bootable USB stick successfully created.")
604 self.session.openWithCallback(self.flasherFinishedCB, MessageBox, _("The USB stick is now bootable. Do you want to download the latest image from the feed server and save it on the stick?"), type = MessageBox.TYPE_YESNO)
605 self["destlist"].changeDir("/mnt/usb")
607 self.session.openWithCallback(self.flasherFinishedCB, MessageBox, (self.cmd + " " + _("failed") + ":\n" + str(self.taskstring)), MessageBox.TYPE_ERROR)
608 self.remove_img(True)
610 def remove_img(self, answer):
611 if fileExists("/tmp/nfiflasher_image.tar.bz2"):
612 remove("/tmp/nfiflasher_image.tar.bz2")
613 if fileExists(self.imagefilename):
614 remove(self.imagefilename)
615 self.downloading(False)
616 self.switchList(self.LIST_SOURCE)
618 def flasherFinishedCB(self, answer):
620 self.wizard_mode = True
621 self["feedlist"].moveSelection(0)
622 self["path_bottom"].text = str(self["destlist"].getCurrentDirectory())
626 def configBackup(self):
627 self.session.openWithCallback(self.runBackup, MessageBox, _("The wizard can backup your current settings. Do you want to do a backup now?"))
629 def runBackup(self, result=None):
630 from Tools.Directories import createDir, isMount, pathExists
631 from time import localtime
632 from datetime import date
633 from Screens.Console import Console
635 if isMount("/mnt/usb/"):
636 if (pathExists("/mnt/usb/backup") == False):
637 createDir("/mnt/usb/backup", True)
639 dt = date(d.tm_year, d.tm_mon, d.tm_mday)
640 self.backup_file = "backup/" + str(dt) + "_settings_backup.tar.gz"
641 self.session.open(Console, title = "Backup running", cmdlist = ["tar -czvf " + "/mnt/usb/" + self.backup_file + " /etc/enigma2/ /etc/network/interfaces /etc/wpa_supplicant.conf"], finishedCallback = self.backup_finished, closeOnSuccess = True)
643 self.backup_file = None
644 self.backup_finished(skipped=True)
646 def backup_finished(self, skipped=False):
648 wizardfd = open("/mnt/usb/wizard.nfo", "w")
650 wizardfd.write("image: "+self["feedlist"].getNFIname()+'\n')
651 wizardfd.write("configuration: "+self.backup_file+'\n')
653 self.session.open(MessageBox, _("To update your Dreambox firmware, please follow these steps:\n1) Turn off your box with the rear power switch and plug in the bootable USB stick.\n2) Turn mains back on and hold the DOWN button on the front panel pressed for 10 seconds.\n3) Wait for bootup and follow instructions of the wizard."), type = MessageBox.TYPE_INFO)
658 #self.nfi_failed(None, "Cancelled by user request")
659 self.downloading(False)
660 except AttributeError:
663 def main(session, **kwargs):
664 session.open(NFIDownload,"/home/root")
666 def filescan_open(list, session, **kwargs):
667 dev = "/dev/" + (list[0].path).rsplit('/',1)[0][7:]
668 print "mounting device " + dev + " to /mnt/usb..."
669 system("mount "+dev+" /mnt/usb/ -o rw,sync")
670 session.open(NFIDownload,"/mnt/usb/")
672 def filescan(**kwargs):
673 from Components.Scanner import Scanner, ScanPath
675 Scanner(mimetypes = ["application/x-dream-image"],
678 ScanPath(path = "", with_subdirs = False),
681 description = (_("Download .NFI-Files for USB-Flasher")+"..."),
682 openfnc = filescan_open, )