+ def keyOk(self):
+ print "[keyOk]", self["menu"].getCurrent()
+ current = self["menu"].getCurrent()
+ if current:
+ if self.branch == START:
+ currentEntry = current[0]
+ if currentEntry == RELEASE:
+ self.image_idx = 0
+ self.branch = RELEASE
+ self.askDestination()
+ elif currentEntry == EXPERIMENTAL:
+ self.image_idx = 0
+ self.branch = EXPERIMENTAL
+ self.askDestination()
+ elif currentEntry == ALLIMAGES:
+ self.branch = ALLIMAGES
+ self.listImages()
+ elif currentEntry == STICK_WIZARD:
+ self.askStartWizard()
+ elif self.branch == ALLIMAGES:
+ self.image_idx = self["menu"].getIndex()
+ self.askDestination()
+ self.updateButtons()
+
+ def keyUp(self):
+ self["menu"].selectPrevious()
+ self.updateButtons()
+
+ def keyDown(self):
+ self["menu"].selectNext()
+ self.updateButtons()
+
+ def updateButtons(self):
+ current = self["menu"].getCurrent()
+ if current:
+ if self.branch == START:
+ self["key_red"].text = _("Close")
+ currentEntry = current[0]
+ if currentEntry in (RELEASE, EXPERIMENTAL):
+ self.nfo_download(currentEntry, 0)
+ self["key_green"].text = _("Download")
+ else:
+ self.nfofilename = ""
+ self.nfo = ""
+ self["key_blue"].text = ""
+ self["key_green"].text = _("continue")
+
+ elif self.branch == ALLIMAGES:
+ self["key_red"].text = _("Back")
+ self["key_green"].text = _("Download")
+ self.nfo_download(ALLIMAGES, self["menu"].getIndex())
+
+ def listImages(self):
+ print "[listImages]"
+ imagelist = []
+ mask = re.compile("%s/(?P<OE_vers>1\.\d)/%s/images/(?P<branch>.*?)-%s_(?P<version>.*?).nfi" % (self.feed_base, self.box, self.box), re.DOTALL)
+ for name, url in self.feedlists[ALLIMAGES]:
+ result = mask.match(url)
+ if result:
+ if result.group("version").startswith("20"):
+ version = ( result.group("version")[:4]+'-'+result.group("version")[4:6]+'-'+result.group("version")[6:8] )
+ else:
+ version = result.group("version")
+ description = "\nOpendreambox %s\n%s image\n%s\n" % (result.group("OE_vers"), result.group("branch"), version)
+ imagelist.append((url, name, _("Download %s from Server" ) % description, None))
+ self["menu"].setList(imagelist)
+
+ def getUSBPartitions(self):
+ allpartitions = [ (r.description, r.mountpoint) for r in harddiskmanager.getMountedPartitions(onlyhotplug = True)]
+ print "[getUSBPartitions]", allpartitions
+ usbpartition = []
+ for x in allpartitions:
+ print x, x[1] == '/', x[0].find("USB"), access(x[1], R_OK)
+ if x[1] != '/' and x[0].find("USB") > -1: # and access(x[1], R_OK) is True:
+ usbpartition.append(x)
+ return usbpartition
+
+ def askDestination(self):
+ usbpartition = self.getUSBPartitions()
+ if len(usbpartition) == 1:
+ self.target_dir = usbpartition[0][1]
+ self.ackDestinationDevice(device_description=usbpartition[0][0])
+ else:
+ 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)
+ self.target_dir = path
+ if path:
+ self.ackDestinationDevice()
+ else:
+ self.keyRed()
+
+ def ackDestinationDevice(self, device_description=None):
+ if device_description == None:
+ dev = self.target_dir
+ else:
+ dev = device_description
+ message = _("Do you want to download the image to %s ?") % (dev)
+ 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):
+ print "[ackDestination_query]", choice
+ if isinstance(choice, tuple):
+ choice[1]()
+ else:
+ self.keyRed()
+
+ def ackedDestination(self):
+ print "[ackedDestination]", self.branch, self.target_dir
+ self.container.setCWD(resolveFilename(SCOPE_MEDIA)+"usb/")
+ 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.target_dir.startswith("/dev/"):
+ job = ImageDownloadJob(url, filename, self.target_dir, self.usbmountpoint)
+ 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
+# 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, _("The USB stick was prepared to be bootable.\nNow you can download an NFI image file!"), type = MessageBox.TYPE_INFO)
+ if len(self.feedlists[ALLIMAGES]) == 0:
+ self.getFeed()
+ else:
+ self.setMenu()
+ else:
+ self.umountCallback = self.checkUSBStick
+ self.umount()
+
+ def ImageDownloadCB(self, ret):
+ 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.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()