--- mythburn.py 2012-04-10 09:44:10.000000000 +0200 +++ mythburn.py 2013-02-25 04:30:47.000000000 +0100 @@ -2252,24 +2252,52 @@ if mediatype == DVD_RW: write("Please insert a rewritable disc (DVD+RW or DVD-RW).") def tray(action): - runCommand("pumount " + quoteCmdArg(dvddrivepath)); waitForDrive() + res = False + f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) try: - f = os.open(drivepath, os.O_RDONLY | os.O_NONBLOCK) - r = ioctl(f,action, 0) - os.close(f) - return True + ioctl(f, CDROM.CDROM_LOCKDOOR, 0) except: - write("Failed to eject the disc!") - return False - finally: - os.close(f) + write("Unlocking drive failed for first time", False) + waitForDrive() + try: + ioctl(f,action, 0) + res = True + except: + write("Sending command to drive failed for first time", False) + waitForDrive() + try: + ioctl(f, CDROM.CDROM_LOCKDOOR, 0) + except: + write("Unlocking drive failed for second time", False) + waitForDrive() + try: + ioctl(f,action, 0) + res = True + except: + write("Sending command to drive failed for second time", False) + waitForDrive() + + if action == CDROM.CDROMEJECT and not res: + write('Trying "eject"', False) + runCommand("eject " + quoteCmdArg(dvddrivepath)) + waitForDrive() + # Run it twice. Sometimes the tray closes again immedeately after the first try + if runCommand("eject " + quoteCmdArg(dvddrivepath)) == 32512: + write('"eject" is probably not installed.', False) + res = True + if drivestatus() != CDROM.CDS_TRAY_OPEN: + res = False + write("Failed to eject the disc! Probably drive is blocked by another program.") + os.close(f) + return res def waitForDrive(): tries = 0 while drivestatus() == CDROM.CDS_DRIVE_NOT_READY: checkCancelFlag() write("Waiting for drive") time.sleep(5) + runCommand("pumount " + quoteCmdArg(dvddrivepath)) tries += 1 if tries > 10: # Try a hard reset if the device is still not ready @@ -2278,6 +2306,7 @@ tries = 0 + #################### # start working here @@ -2297,7 +2326,7 @@ runCommand("pumount " + quoteCmdArg(dvddrivepath)); - command = quoteCmdArg(path_growisofs[0]) + " -dvd-compat" + command = quoteCmdArg(path_growisofs[0]) + " -input-charset=UTF-8 -dvd-compat" if drivespeed != 0: command += " -speed=%d" % drivespeed if mediatype == DVD_RW and erasedvdrw == True: @@ -2309,6 +2338,21 @@ result = runCommand(command) if result == 0: finished = True + + # Wait till the drive is not busy any longer + f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) + busy = True + tries = 0 + while busy and tries < 10: + tries += 1 + try: + ioctl(f, CDROM.CDROM_LOCKDOOR, 0) + busy = False + except: + write("Drive is still busy") + time.sleep(5) + waitForDrive() + os.close(f) else: if result == 252: write("-"*60)