DVDBurn fix capacity report for full dual layer media in Media Toolbox
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / DVDToolbox.py
old mode 100644 (file)
new mode 100755 (executable)
index 32666af..53287a3
@@ -9,18 +9,17 @@ 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 = """
-               <screen position="90,83" size="560,445" title="DVD media toolbox" >
+               <screen name="DVDToolbox" position="center,center"  size="560,445" title="DVD media toolbox" >
                    <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
                    <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
                    <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
-                   <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
                    <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
                    <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
                    <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
-                   <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
                    <widget source="info" render="Label" position="20,60" size="520,100" font="Regular;20" />
                    <widget name="details" position="20,200" size="520,200" font="Regular;16" />
                    <widget source="space_bar" render="Progress" position="10,410" size="540,26" borderWidth="1" backgroundColor="#254f7497" />
@@ -33,7 +32,6 @@ class DVDToolbox(Screen):
                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()
@@ -48,20 +46,24 @@ class DVDToolbox(Screen):
                    "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("")
@@ -80,32 +82,30 @@ class DVDToolbox(Screen):
                self.update()
 
        def mediainfoCB(self, mediuminfo, retval, extra_args):
-               capacity = 1
+               formatted_capacity = 0
+               read_capacity = 0
+               capacity = 0
                used = 0
                infotext = ""
                mediatype = ""
                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:
@@ -114,8 +114,22 @@ class DVDToolbox(Screen):
                                        capacity = size / 1048576
                                        if used:
                                                used = capacity-used
-                                       print "[free blocks] capacity=%d, used=%d" % (capacity, used)
-                       infotext += line
+                                       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")
@@ -141,6 +155,7 @@ class DVDToolbox(Screen):
 
        def exit(self):
                del self.Console
+               hotplugNotifier.remove(self.update)
                self.close()
 
 class DVDformatJob(Job):
@@ -150,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):
@@ -174,6 +189,7 @@ class DVDformatTask(Task):
                self.setTool("/bin/dvd+rw-format")
                self.args += [ "/dev/" + harddiskmanager.getCD() ]
                self.end = 1100
+               self.retryargs = [ ]
 
        def prepare(self):
                self.error = None
@@ -181,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