correctly parse output of new epopen command
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / DVDToolbox.py
index c766ad522ce3e656bdfd756fb197f04aabcdf95f..0c375129d71d57d0b46b9f40131f6e3ff529e03d 100644 (file)
@@ -7,6 +7,8 @@ from Components.Sources.StaticText import StaticText
 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
 
 class DVDToolbox(Screen):
        skin = """
@@ -25,9 +27,8 @@ class DVDToolbox(Screen):
                    <widget source="space_label" render="Label" position="20,414" size="520,22" zPosition="2" font="Regular;18" halign="center" transparent="1" foregroundColor="#000000" />
                </screen>"""
 
-       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"))
@@ -42,9 +43,9 @@ 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,
@@ -64,18 +65,28 @@ class DVDToolbox(Screen):
                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):
+               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 = ""
-               for line in self.mediuminfo:
+               for line in mediuminfo.splitlines():
                        if line.find("Mounted Media:") > -1:
-                               mediatype = line.rsplit(',',1)[1][1:-1]
+                               mediatype = line.rsplit(',',1)[1][1:]
                                if mediatype.find("RW") > 0:
                                        self.formattable = True
                                else:
@@ -95,13 +106,16 @@ class DVDToolbox(Screen):
                                        capacity = used
                                        used = 0
                        elif line.find("Free Blocks:") > -1:
-                               size = line[15:-3].split('*')
-                               size = int(size[0])*int(size[1])*1024
+                               try:
+                                       size = eval(line[14:].replace("KB","*1024"))
+                               except:
+                                       size = 0
                                if size > 0:
-                                       capacity = size
-                                       used = capacity-used                            
+                                       capacity = size / 1048576
+                                       if used:
+                                               used = capacity-used
                                        print "[free blocks] capacity=%d, used=%d" % (capacity, used)
-                       infotext += line
+                       infotext += line+'\n'
                self["details"].setText(infotext)
                if self.formattable:
                        self["key_yellow"].text = _("Format")
@@ -125,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)
 
-       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):
@@ -161,7 +172,7 @@ class DVDformatTask(Task):
                self.toolbox = job.toolbox
                self.postconditions.append(DVDformatTaskPostcondition())
                self.setTool("/bin/dvd+rw-format")
-               self.args += [ "/dev/cdroms/cdrom0" ]
+               self.args += [ "/dev/" + harddiskmanager.getCD() ]
                self.end = 1100
 
        def prepare(self):
@@ -181,39 +192,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/cdroms/cdrom0" ]
-
-       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()