- self["key_green"] = StaticText()
- self["key_yellow"] = StaticText()
- self["key_blue"] = StaticText()
-
- self["key_red"] = StaticText()
-
- self["feedlist"] = Feedlist([0,(eListboxPythonMultiContent.TYPE_TEXT, 0, 0,250, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, "feed not available")])
- self["destlist"] = FileList(destdir, showDirectories = True, showFiles = False)
- self["destlist"].hide()
-
- self.download_container = eConsoleAppContainer()
- self.nfo = ""
- self.nfofile = ""
- self.feedhtml = ""
- self.focus = None
- self.download = None
- self.box = HardwareInfo().get_device_name()
- self.feed_base = "http://www.dreamboxupdate.com/opendreambox/1.5/%s/images/" % self.box
- self.nfi_filter = "" # "release" # only show NFIs containing this string, or all if ""
- self.wizard_mode = False
-
- self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "EPGSelectActions"],
- {
- "cancel": self.closeCB,
- "red": self.closeCB,
- "green": self.nfi_download,
- "yellow": self.switchList,
- "blue": self.askCreateUSBstick,
- "prevBouquet": self.switchList,
- "nextBouquet": self.switchList,
- "ok": self.ok,
- "left": self.left,
- "right": self.right,
- "up": self.up,
- "upRepeated": self.up,
- "downRepeated": self.down,
- "down": self.down
- }, -1)
+ def download_failed(self, failure_instance=None, error_message=""):
+ self.error_message = error_message
+ if error_message == "" and failure_instance is not None:
+ self.error_message = failure_instance.getErrorMessage()
+ print "[download_failed]", self.error_message
+ Task.processFinished(self, 1)
+
+ def download_finished(self, string=""):
+ print "[download_finished]", string
+ Task.processFinished(self, 0)
+
+class StickWizardJob(Job):
+ def __init__(self, path):
+ Job.__init__(self, _("USB stick wizard"))
+ self.path = path
+ self.device = path
+ while self.device[-1:] == "/" or self.device[-1:].isdigit():
+ self.device = self.device[:-1]
+
+ box = HardwareInfo().get_device_name()
+ url = "http://www.dreamboxupdate.com/download/opendreambox/dreambox-nfiflasher-%s.tar.bz2" % box
+ self.downloadfilename = "/tmp/dreambox-nfiflasher-%s.tar.bz2" % box
+ self.imagefilename = "/tmp/nfiflash_%s.img" % box
+ #UmountTask(self, device)
+ PartitionTask(self)
+ ImageDownloadTask(self, url, self.downloadfilename)
+ UnpackTask(self)
+ CopyTask(self)
+
+class PartitionTaskPostcondition(Condition):
+ def check(self, task):
+ return task.returncode == 0
+
+ def getErrorMessage(self, task):
+ return {
+ task.ERROR_BLKRRPART: ("Device or resource busy"),
+ task.ERROR_UNKNOWN: (task.errormsg)
+ }[task.error]
+
+class PartitionTask(Task):
+ ERROR_UNKNOWN, ERROR_BLKRRPART = range(2)
+ def __init__(self, job):
+ Task.__init__(self, job, ("partitioning"))
+ self.postconditions.append(PartitionTaskPostcondition())
+ self.job = job
+ self.setTool("sfdisk")
+ self.args += [self.job.device]
+ self.weighting = 10
+ self.initial_input = "0 - 0x6 *\n;\n;\n;\ny"
+ self.errormsg = ""
+
+ def run(self, callback):
+ Task.run(self, callback)
+
+ def processOutput(self, data):
+ print "[PartitionTask] output:", data
+ if data.startswith("BLKRRPART:"):
+ self.error = self.ERROR_BLKRRPART
+ else:
+ self.error = self.ERROR_UNKNOWN
+ self.errormsg = data
+
+class UnpackTask(Task):
+ def __init__(self, job):
+ Task.__init__(self, job, ("Unpacking USB flasher image..."))
+ self.job = job
+ self.setTool("tar")
+ self.args += ["-xjvf", self.job.downloadfilename]
+ self.weighting = 80
+ self.end = 80
+ self.delayTimer = eTimer()
+ self.delayTimer.callback.append(self.progress_increment)
+
+ def run(self, callback):
+ Task.run(self, callback)
+ self.delayTimer.start(950, False)
+
+ def progress_increment(self):
+ self.progress += 1
+
+ def processOutput(self, data):
+ print "[UnpackTask] output: \'%s\'" % data
+ self.job.imagefilename = data
+
+ def afterRun(self):
+ self.delayTimer.callback.remove(self.progress_increment)
+
+class CopyTask(Task):
+ def __init__(self, job):
+ Task.__init__(self, job, ("Copying USB flasher boot image to stick..."))
+ self.job = job
+ self.setTool("dd")
+ self.args += ["if=%s" % self.job.imagefilename, "of=%s1" % self.job.device]
+ self.weighting = 20
+ self.end = 20
+ self.delayTimer = eTimer()
+ self.delayTimer.callback.append(self.progress_increment)
+
+ def run(self, callback):
+ Task.run(self, callback)
+ self.delayTimer.start(100, False)
+
+ def progress_increment(self):
+ self.progress += 1