X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/fc1c1768923a6ec3c3439a851b616095d60d81b3..2c862a6323b51e446270ee3b6845ed234ed8771d:/lib/python/Plugins/Extensions/DVDBurn/DVDToolbox.py diff --git a/lib/python/Plugins/Extensions/DVDBurn/DVDToolbox.py b/lib/python/Plugins/Extensions/DVDBurn/DVDToolbox.py old mode 100644 new mode 100755 index 3ea48747..0b81cfdf --- a/lib/python/Plugins/Extensions/DVDBurn/DVDToolbox.py +++ b/lib/python/Plugins/Extensions/DVDBurn/DVDToolbox.py @@ -8,32 +8,30 @@ from Components.Sources.Progress import Progress from Components.Task import Task, Job, job_manager, Condition from Components.ScrollLabel import ScrollLabel from Components.Harddisk import harddiskmanager +from Components.Console import Console +from Plugins.SystemPlugins.Hotplug.plugin import hotplugNotifier class DVDToolbox(Screen): skin = """ - + - - """ - def __init__(self, session, project = None): + def __init__(self, session): Screen.__init__(self, session) - self.project = project self["key_red"] = StaticText(_("Exit")) self["key_green"] = StaticText(_("Update")) self["key_yellow"] = StaticText() - self["key_blue"] = StaticText() self["space_label"] = StaticText() self["space_bar"] = Progress() @@ -43,68 +41,95 @@ class DVDToolbox(Screen): self["details"] = ScrollLabel() self["info"] = StaticText() - self["toolboxactions"] = ActionMap(["ColorActions", "DVDToolbox"], + self["toolboxactions"] = ActionMap(["ColorActions", "DVDToolbox", "OkCancelActions"], { - "red": self.close, + "red": self.exit, "green": self.update, "yellow": self.format, - #"blue": self.eject, - "cancel": self.close, + "cancel": self.exit, "pageUp": self.pageUp, "pageDown": self.pageDown }) self.update() - + hotplugNotifier.append(self.update) + self.onLayoutFinish.append(self.layoutFinished) + + def layoutFinished(self): + self.setTitle(_("DVD media toolbox")) + def pageUp(self): self["details"].pageUp() def pageDown(self): self["details"].pageDown() - def update(self): + def update(self, dev="", action=""): self["space_label"].text = _("Please wait... Loading list...") self["info"].text = "" self["details"].setText("") - self.mediuminfo = [ ] - job = DVDinfoJob(self) - job_manager.AddJob(job) - - def infoJobCB(self, in_background=False): - capacity = 1 + self.Console = Console() + cmd = "dvd+rw-mediainfo /dev/" + harddiskmanager.getCD() + self.Console.ePopen(cmd, self.mediainfoCB) + + def format(self): + if self.formattable: + job = DVDformatJob(self) + job_manager.AddJob(job) + from Screens.TaskView import JobView + self.session.openWithCallback(self.formatCB, JobView, job) + + def formatCB(self, in_background): + self.update() + + def mediainfoCB(self, mediuminfo, retval, extra_args): + formatted_capacity = 0 + read_capacity = 0 + capacity = 0 used = 0 infotext = "" mediatype = "" - for line in self.mediuminfo: + for line in mediuminfo.splitlines(): if line.find("Mounted Media:") > -1: - mediatype = line.rsplit(',',1)[1][1:-1] - if mediatype.find("RW") > 0: + mediatype = line.rsplit(',',1)[1][1:] + if mediatype.find("RW") > 0 or mediatype.find("RAM") > 0: self.formattable = True else: self.formattable = False - if line.find("Legacy lead-out at:") > -1: + elif line.find("Legacy lead-out at:") > -1: used = int(line.rsplit('=',1)[1]) / 1048576.0 - print "[lead out] used =", used + print "[dvd+rw-mediainfo] lead out used =", used elif line.find("formatted:") > -1: - capacity = int(line.rsplit('=',1)[1]) / 1048576.0 - print "[formatted] capacity =", capacity - elif capacity == 1 and line.find("READ CAPACITY:") > -1: - capacity = int(line.rsplit('=',1)[1]) / 1048576.0 - print "[READ CAP] capacity =", capacity - elif line.find("Disc status:") > -1: - if line.find("blank") > -1: - print "[Disc status] capacity=%d, used=0" % (capacity) - capacity = used - used = 0 - elif line.find("Free Blocks:") > -1: + formatted_capacity = int(line.rsplit('=',1)[1]) / 1048576.0 + print "[dvd+rw-mediainfo] formatted capacity =", formatted_capacity + elif formatted_capacity == 0 and line.find("READ CAPACITY:") > -1: + read_capacity = int(line.rsplit('=',1)[1]) / 1048576.0 + print "[dvd+rw-mediainfo] READ CAPACITY =", read_capacity + for line in mediuminfo.splitlines(): + if line.find("Free Blocks:") > -1: try: size = eval(line[14:].replace("KB","*1024")) except: size = 0 if size > 0: - capacity = size - used = capacity-used - print "[free blocks] capacity=%d, used=%d" % (capacity, used) - infotext += line + capacity = size / 1048576 + if used: + used = capacity-used + print "[dvd+rw-mediainfo] free blocks capacity=%d, used=%d" % (capacity, used) + elif line.find("Disc status:") > -1: + if line.find("blank") > -1: + print "[dvd+rw-mediainfo] Disc status blank capacity=%d, used=0" % (capacity) + capacity = used + used = 0 + elif line.find("complete") > -1 and formatted_capacity == 0: + print "[dvd+rw-mediainfo] Disc status complete capacity=0, used=%d" % (capacity) + used = read_capacity + capacity = 1 + else: + capacity = formatted_capacity + infotext += line+'\n' + if capacity and used > capacity: + used = read_capacity or capacity + capacity = formatted_capacity or capacity self["details"].setText(infotext) if self.formattable: self["key_yellow"].text = _("Format") @@ -128,12 +153,10 @@ class DVDToolbox(Screen): free = 0 self["info"].text = "Media-Type:\t\t%s\nFree capacity:\t\t%d MB" % (mediatype or "NO DVD", free) - def format(self): - if self.formattable: - job = DVDformatJob(self) - job_manager.AddJob(job) - from Screens.TaskView import JobView - self.session.openWithCallback(self.infoJobCB, JobView, job) + def exit(self): + del self.Console + hotplugNotifier.remove(self.update) + self.close() class DVDformatJob(Job): def __init__(self, toolbox): @@ -142,7 +165,7 @@ class DVDformatJob(Job): DVDformatTask(self) def retry(self): - self.tasks[0].args += [ "-force" ] + self.tasks[0].args += self.tasks[0].retryargs Job.retry(self) class DVDformatTaskPostcondition(Condition): @@ -163,9 +186,10 @@ class DVDformatTask(Task): Task.__init__(self, job, ("RW medium format")) self.toolbox = job.toolbox self.postconditions.append(DVDformatTaskPostcondition()) - self.setTool("/bin/dvd+rw-format") + self.setTool("dvd+rw-format") self.args += [ "/dev/" + harddiskmanager.getCD() ] self.end = 1100 + self.retryargs = [ ] def prepare(self): self.error = None @@ -173,7 +197,10 @@ class DVDformatTask(Task): def processOutputLine(self, line): if line.startswith("- media is already formatted"): self.error = self.ERROR_ALREADYFORMATTED - self.force = True + self.retryargs = [ "-force" ] + if line.startswith("- media is not blank") or line.startswith(" -format=full to perform full (lengthy) reformat;"): + self.error = self.ERROR_ALREADYFORMATTED + self.retryargs = [ "-blank" ] if line.startswith(":-( mounted media doesn't appear to be"): self.error = self.ERROR_NOTWRITEABLE @@ -184,39 +211,3 @@ class DVDformatTask(Task): self.progress = int(float(data[:-1])*10) else: Task.processOutput(self, data) - -class DVDinfoJob(Job): - def __init__(self, toolbox): - Job.__init__(self, "DVD media toolbox") - self.toolbox = toolbox - DVDinfoTask(self) - -class DVDinfoTaskPostcondition(Condition): - RECOVERABLE = True - def check(self, task): - return task.error is None - - def getErrorMessage(self, task): - return { - task.ERROR_UNKNOWN: _("An unknown error occured!") - }[task.error] - -class DVDinfoTask(Task): - ERROR_UNKNOWN = range(1) - def __init__(self, job, extra_args=[]): - Task.__init__(self, job, ("mediainfo")) - self.toolbox = job.toolbox - self.postconditions.append(DVDinfoTaskPostcondition()) - self.setTool("/bin/dvd+rw-mediainfo") - self.args += [ "/dev/" + harddiskmanager.getCD() ] - - def prepare(self): - self.error = None - - def processOutputLine(self, line): - print "[DVDinfoTask]", line[:-1] - self.toolbox.mediuminfo.append(line) - - def processFinished(self, returncode): - Task.processFinished(self, returncode) - self.toolbox.infoJobCB()