3 # Check the free space available on a writable DVD
4 # Should always exit with 0 status, otherwise it indicates a serious error.
5 # (wrong number of arguments, Python exception...)
7 # called: dvd-freespace <dvd-device-name> <part-number>
11 # Prints on the first output line the free space available in bytes.
12 # If an error occurs, prints a negative number (-errno), followed,
13 # on the second line, by an error message.
17 # Configurable values:
19 growisofs="@GROWISOFS@"
20 dvdrwmediainfo="@DVDRWMEDIAINFO@"
22 margin=10485760 # 10 mb security margin
26 # Uncomment the following line if you have a Linux kernel >=2.6.8, and
27 # if you want to allow a session to start behind the 4gb boundary.
28 #growisofsparams = growisofsparams + " -use-the-force-luke=4gms"
30 # end of configurable values
38 if len(sys.argv) != 3:
39 print "Wrong number of argument."
43 part_num=int(sys.argv[2])
45 os.environ["MKISOFS"] = mkisofs
48 cmd=dvdrwmediainfo + " " + device
49 processi = popen2.Popen4(cmd)
50 status = processi.wait()
51 if not os.WIFEXITED(status):
53 print dvdrwmediainfo + " process did not exit correctly."
55 if os.WEXITSTATUS(status) != 0:
57 print 'Cannot get media info.'
60 result = processi.fromchild.readline()
61 if result.find("Legacy lead-out at:") > -1:
62 index = result.find("=")
64 res = result[index+1:-1]
67 print "Invalid format in media info lead-out line from " + dvdrwmediainfo
72 print "Invalid format in media info lead-out line from " + dvdrwmediainfo
76 print "Cannot get media lead-out index from " + dvdrwmediainfo
79 tmpfile = tempfile.NamedTemporaryFile()
84 cmd=growisofs + " " + growisofsparams + " -use-the-force-luke=tty -dry-run -quiet " + flag + " " + device + " -R " + tmpfile.name
85 process = popen2.Popen4(cmd)
86 status = process.wait()
87 if not os.WIFEXITED(status):
89 print growisofs + " process did not not exit correctly."
92 exitstat = os.WEXITSTATUS(status) & ~0x80
93 if exitstat == errno.ENOSPC:
95 print os.strerror(exitstat)
99 print os.strerror(exitstat)
102 result = process.fromchild.readline()
105 print "Cannot find the seek argument in the output from " + growisofs
107 index = result.find("seek=")
109 res = result[index+5:-2]
110 if not res.isdigit():
112 print "Wrong seek argument in the output from " + growisofs
114 size = int(res)*32*1024
115 size = gettotalsize()-(size+margin)
119 print "No error occured"