Ticket #10535: mythburn.py.patch_2

File mythburn.py.patch_2, 3.6 KB (added by t.brackertz@…, 11 years ago)

improved path

Line 
1--- mythburn.py 2012-04-10 09:44:10.000000000 +0200
2+++ mythburn.py 2013-02-25 04:30:47.000000000 +0100
3@@ -2252,24 +2252,52 @@
4         if mediatype == DVD_RW:
5           write("Please insert a rewritable disc (DVD+RW or DVD-RW).")
6     def tray(action):
7-        runCommand("pumount " + quoteCmdArg(dvddrivepath));
8         waitForDrive()
9+        res = False
10+        f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
11         try:
12-            f = os.open(drivepath, os.O_RDONLY | os.O_NONBLOCK)
13-            r = ioctl(f,action, 0)
14-            os.close(f)
15-            return True
16+          ioctl(f, CDROM.CDROM_LOCKDOOR, 0)
17         except:
18-            write("Failed to eject the disc!")
19-            return False
20-        finally:
21-            os.close(f)
22+          write("Unlocking drive failed for first time", False)
23+          waitForDrive()
24+        try:
25+          ioctl(f,action, 0)
26+          res = True
27+        except:
28+          write("Sending command to drive failed for first time", False)
29+          waitForDrive()
30+        try:
31+          ioctl(f, CDROM.CDROM_LOCKDOOR, 0)
32+        except:
33+          write("Unlocking drive failed for second time", False)
34+          waitForDrive()
35+        try:
36+          ioctl(f,action, 0)
37+          res = True
38+        except:
39+          write("Sending command to drive failed for second time", False)
40+          waitForDrive()
41+
42+        if action == CDROM.CDROMEJECT and not res:
43+          write('Trying "eject"', False)
44+          runCommand("eject " + quoteCmdArg(dvddrivepath))
45+          waitForDrive()
46+          # Run it twice. Sometimes the tray closes again immedeately after the first try
47+          if runCommand("eject " + quoteCmdArg(dvddrivepath)) == 32512:
48+            write('"eject" is probably not installed.', False)
49+            res = True
50+          if drivestatus() != CDROM.CDS_TRAY_OPEN:
51+            res = False
52+            write("Failed to eject the disc! Probably drive is blocked by another program.")
53+        os.close(f)
54+        return res
55     def waitForDrive():
56         tries = 0
57         while drivestatus() == CDROM.CDS_DRIVE_NOT_READY:
58            checkCancelFlag()
59             write("Waiting for drive")
60             time.sleep(5)
61+            runCommand("pumount " + quoteCmdArg(dvddrivepath))
62             tries += 1
63             if tries > 10:
64                 # Try a hard reset if the device is still not ready
65@@ -2278,6 +2306,7 @@
66                 tries = 0
67 
68 
69+
70     ####################
71     # start working here
72 
73@@ -2297,7 +2326,7 @@
74             runCommand("pumount " + quoteCmdArg(dvddrivepath));
75 
76 
77-            command = quoteCmdArg(path_growisofs[0]) + " -dvd-compat"
78+            command = quoteCmdArg(path_growisofs[0]) + " -input-charset=UTF-8 -dvd-compat"
79             if drivespeed != 0:
80                 command += " -speed=%d" % drivespeed
81             if mediatype == DVD_RW and erasedvdrw == True:
82@@ -2309,6 +2338,21 @@
83             result = runCommand(command)
84             if result == 0:
85                 finished = True
86+               
87+                # Wait till the drive is not busy any longer
88+                f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
89+                busy = True
90+                tries = 0
91+                while busy and tries < 10:
92+                  tries += 1
93+                  try:
94+                    ioctl(f, CDROM.CDROM_LOCKDOOR, 0)
95+                    busy = False
96+                  except:
97+                    write("Drive is still busy")
98+                    time.sleep(5)
99+                    waitForDrive()
100+                os.close(f)
101             else:
102                 if result == 252:
103                     write("-"*60)