switch from job to epopen for the info part. (this crashes when exiting before cb...
authorAndreas Frisch <andreas.frisch@multimedia-labs.de>
Mon, 27 Oct 2008 09:45:04 +0000 (09:45 +0000)
committerAndreas Frisch <andreas.frisch@multimedia-labs.de>
Mon, 27 Oct 2008 09:45:04 +0000 (09:45 +0000)
lib/python/Plugins/Extensions/DVDBurn/DVDToolbox.py

index c0cec2197e936e3b306868b7cd4935f97983a5b2..32666af8e7ead348b0f231e628aa59844b8f4d7e 100644 (file)
@@ -8,6 +8,7 @@ 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.Task import Task, Job, job_manager, Condition
 from Components.ScrollLabel import ScrollLabel
 from Components.Harddisk import harddiskmanager
+from Components.Console import Console
 
 class DVDToolbox(Screen):
        skin = """
 
 class DVDToolbox(Screen):
        skin = """
@@ -44,7 +45,7 @@ class DVDToolbox(Screen):
 
                self["toolboxactions"] = ActionMap(["ColorActions", "DVDToolbox", "OkCancelActions"],
                {
 
                self["toolboxactions"] = ActionMap(["ColorActions", "DVDToolbox", "OkCancelActions"],
                {
-                   "red": self.close,
+                   "red": self.exit,
                    "green": self.update,
                    "yellow": self.format,
                    #"blue": self.eject,
                    "green": self.update,
                    "yellow": self.format,
                    #"blue": self.eject,
@@ -64,16 +65,26 @@ class DVDToolbox(Screen):
                self["space_label"].text = _("Please wait... Loading list...")
                self["info"].text = ""
                self["details"].setText("")
                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):
+               self.Console = Console()
+               cmd = "/bin/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):
                capacity = 1
                used = 0
                infotext = ""
                mediatype = ""
                capacity = 1
                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:
                        if line.find("Mounted Media:") > -1:
                                mediatype = line.rsplit(',',1)[1][1:-1]
                                if mediatype.find("RW") > 0:
@@ -128,12 +139,9 @@ class DVDToolbox(Screen):
                        free = 0
                self["info"].text = "Media-Type:\t\t%s\nFree capacity:\t\t%d MB" % (mediatype or "NO DVD", free)
 
                        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
+               self.close()
 
 class DVDformatJob(Job):
        def __init__(self, toolbox):
 
 class DVDformatJob(Job):
        def __init__(self, toolbox):
@@ -184,39 +192,3 @@ class DVDformatTask(Task):
                        self.progress = int(float(data[:-1])*10)
                else:
                        Task.processOutput(self, data)
                        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()