fix possible crash on mediainfo parsing
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / DVDToolbox.py
index 9d75621d07114c01d45f1c8cda7a11ff7c965c61..45a8edb607c8280c702e9cfcad2aaed1e49224e2 100644 (file)
@@ -7,6 +7,7 @@ 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
 
 class DVDToolbox(Screen):
        skin = """
@@ -94,21 +95,30 @@ class DVDToolbox(Screen):
                                        print "[Disc status] capacity=%d, used=0" % (capacity)
                                        capacity = used
                                        used = 0
+                       elif 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
                self["details"].setText(infotext)
                if self.formattable:
                        self["key_yellow"].text = _("Format")
                else:
                        self["key_yellow"].text = ""
-               percent = 100 * used / capacity
+               percent = 100 * used / (capacity or 1)
                if capacity > 4600:
-                       self["space_label"].text = "%d / %d MB" % (used, capacity) + " (%.2f%% " % percent + _("of a DUAL layer medium used.)")
+                       self["space_label"].text = "%d / %d MB" % (used, capacity) + " (%.2f%% " % percent + _("of a DUAL layer medium used.") + ")"
                        self["space_bar"].value = int(percent)
                elif capacity > 1:
-                       self["space_label"].text = "%d / %d MB" % (used, capacity) + " (%.2f%% " % percent + _("of a SINGLE layer medium used.)")
+                       self["space_label"].text = "%d / %d MB" % (used, capacity) + " (%.2f%% " % percent + _("of a SINGLE layer medium used.") + ")"
                        self["space_bar"].value = int(percent)
                elif capacity == 1 and used > 0:
-                       self["space_label"].text = "%d MB" % (used) + _(" on READ ONLY medium.")
+                       self["space_label"].text = "%d MB " % (used) + _("on READ ONLY medium.")
                        self["space_bar"].value = int(percent)
                else:
                        self["space_label"].text = _("Medium is not a writeable DVD!")
@@ -154,7 +164,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 += [ harddiskmanager.getCD() ]
                self.end = 1100
 
        def prepare(self):
@@ -198,7 +208,7 @@ class DVDinfoTask(Task):
                self.toolbox = job.toolbox
                self.postconditions.append(DVDinfoTaskPostcondition())
                self.setTool("/bin/dvd+rw-mediainfo")
-               self.args += [ "/dev/cdroms/cdrom0" ]
+               self.args += [ harddiskmanager.getCD() ]
 
        def prepare(self):
                self.error = None