[NFIFlash] ask whether to run configuration backup after image download (add #480)
[enigma2.git] / lib / python / Plugins / SystemPlugins / NFIFlash / downloader.py
index 8768021cd43122101bb5dc1127819da11671932d..27038e67fed45d773ba0d344803023f1b49290f5 100644 (file)
@@ -35,8 +35,8 @@ class ImageDownloadJob(Job):
                        MountTask(self, device, mountpoint)
                ImageDownloadTask(self, url, mountpoint+filename)
                ImageDownloadTask(self, url[:-4]+".nfo", mountpoint+filename[:-4]+".nfo")
-               if device:
-                       UmountTask(self, mountpoint)
+               #if device:
+                       #UmountTask(self, mountpoint)
 
        def retry(self):
                self.tasks[0].args += self.tasks[0].retryargs
@@ -539,7 +539,10 @@ class NFIDownload(Screen):
                        self.target_dir = usbpartition[0][1]
                        self.ackDestinationDevice(device_description=usbpartition[0][0])
                else:
-                       self.session.openWithCallback(self.DeviceBrowserClosed, DeviceBrowser, None, showDirectories=True, showMountpoints=True, inhibitMounts=["/autofs/sr0/"])
+                       self.openDeviceBrowser()
+       
+       def openDeviceBrowser(self):
+               self.session.openWithCallback(self.DeviceBrowserClosed, DeviceBrowser, None, showDirectories=True, showMountpoints=True, inhibitMounts=["/autofs/sr0/"])
 
        def DeviceBrowserClosed(self, path):
                print "[DeviceBrowserClosed]", str(path)
@@ -555,7 +558,7 @@ class NFIDownload(Screen):
                else:
                        dev = device_description
                message = _("Do you want to download the image to %s ?") % (dev)
-               choices = [(_("Yes"), self.ackedDestination), (_("List of Storage Devices"),self.askDestination), (_("Cancel"),self.keyRed)]
+               choices = [(_("Yes"), self.ackedDestination), (_("List of Storage Devices"),self.openDeviceBrowser), (_("Cancel"),self.keyRed)]
                self.session.openWithCallback(self.ackDestination_query, ChoiceBox, title=message, list=choices)
 
        def ackDestination_query(self, choice):
@@ -566,27 +569,30 @@ class NFIDownload(Screen):
                        self.keyRed()
 
        def ackedDestination(self):
-               print "[ackedDestination]", self.branch, self.target_dir, self.target_dir[8:]
+               print "[ackedDestination]", self.branch, self.target_dir
                self.container.setCWD("/mnt")
                if self.target_dir[:8] == "/autofs/":
                        self.target_dir = "/dev/" + self.target_dir[8:-1]
 
-                       if self.branch == STICK_WIZARD:
-                               job = StickWizardJob(self.target_dir)
-                               job.afterEvent = "close"
-                               job_manager.AddJob(job)
-                               job_manager.failed_jobs = []
-                               self.session.openWithCallback(self.StickWizardCB, JobView, job, afterEventChangeable = False)
-
-                       elif self.branch != STICK_WIZARD:
-                               url = self.feedlists[self.branch][self.image_idx][1]
-                               filename = self.feedlists[self.branch][self.image_idx][0]
-                               print "[getImage] start downloading %s to %s" % (url, filename)
+               if self.branch == STICK_WIZARD:
+                       job = StickWizardJob(self.target_dir)
+                       job.afterEvent = "close"
+                       job_manager.AddJob(job)
+                       job_manager.failed_jobs = []
+                       self.session.openWithCallback(self.StickWizardCB, JobView, job, afterEventChangeable = False)
+
+               elif self.branch != STICK_WIZARD:
+                       url = self.feedlists[self.branch][self.image_idx][1]
+                       filename = self.feedlists[self.branch][self.image_idx][0]
+                       print "[getImage] start downloading %s to %s" % (url, filename)
+                       if self.target_dir.startswith("/dev/"):
                                job = ImageDownloadJob(url, filename, self.target_dir, self.usbmountpoint)
-                               job.afterEvent = "close"
-                               job_manager.AddJob(job)
-                               job_manager.failed_jobs = []
-                               self.session.openWithCallback(self.ImageDownloadCB, JobView, job, afterEventChangeable = False)
+                       else:
+                               job = ImageDownloadJob(url, filename, None, self.target_dir)
+                       job.afterEvent = "close"
+                       job_manager.AddJob(job)
+                       job_manager.failed_jobs = []
+                       self.session.openWithCallback(self.ImageDownloadCB, JobView, job, afterEventChangeable = False)
 
        def StickWizardCB(self, ret=None):
                print "[StickWizardCB]", ret
@@ -605,11 +611,30 @@ class NFIDownload(Screen):
                print "[ImageDownloadCB]", ret
 #              print job_manager.active_jobs, job_manager.failed_jobs, job_manager.job_classes, job_manager.in_background, job_manager.active_job
                if len(job_manager.failed_jobs) == 0:
-                       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)
+                       self.session.openWithCallback(self.askBackupCB, MessageBox, _("The wizard can backup your current settings. Do you want to do a backup now?"), MessageBox.TYPE_YESNO)
                else:
                        self.umountCallback = self.keyRed
                        self.umount()
 
+       def askBackupCB(self, ret):
+               if ret:
+                       from Plugins.SystemPlugins.SoftwareManager.BackupRestore import BackupScreen
+
+                       class USBBackupScreen(BackupScreen):
+                               def __init__(self, session, usbmountpoint):
+                                       BackupScreen.__init__(self, session, runBackup = True)
+                                       self.backuppath = usbmountpoint
+                                       self.fullbackupfilename = self.backuppath + "/" + self.backupfile
+
+                       self.session.openWithCallback(self.showHint, USBBackupScreen, self.usbmountpoint)
+               else:
+                       self.showHint()
+
+       def showHint(self, ret=None):
+               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)
+               self.umountCallback = self.keyRed
+               self.umount()
+
        def getFeed(self):
                self.feedDownloader15 = feedDownloader(self.feed_base, self.box, OE_vers="1.5")
                self.feedDownloader16 = feedDownloader(self.feed_base, self.box, OE_vers="1.6")