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
37 if len(sys.argv) != 3:
38 print "Wrong number of argument."
42 part_num=int(sys.argv[2])
44 os.environ["MKISOFS"] = mkisofs
47 cmd=dvdrwmediainfo + " " + device
48 processi = popen2.Popen4(cmd)
49 status = processi.wait()
50 if not os.WIFEXITED(status):
52 print dvdrwmediainfo + " process did not exit correctly."
54 if os.WEXITSTATUS(status) != 0:
56 print "Cannot get media info from " + dvdrwmediainfo
59 result = processi.fromchild.readline()
60 if result.find("Track Size:") > -1:
61 index = result.find("*2KB")
63 return long(result[12:index]) * 2048
66 print "Invalid format in media info lead-out line from " + dvdrwmediainfo
68 if result.find("Legacy lead-out at:") > -1:
69 index = result.find("=")
71 res = result[index+1:-1]
74 print "Invalid format in media info lead-out line from " + dvdrwmediainfo
79 print "Invalid format in media info lead-out line from " + dvdrwmediainfo
83 print "Cannot get media lead-out index from " + dvdrwmediainfo
90 # the growisofs at the end is a dummy
91 cmd=growisofs + " " + growisofsparams + " -use-the-force-luke=tty -dry-run -quiet " + flag + " " + device + " -R " + growisofs
92 process = popen2.Popen4(cmd)
93 status = process.wait()
94 if not os.WIFEXITED(status):
96 print growisofs + " process did not not exit correctly."
99 exitstat = os.WEXITSTATUS(status) & ~0x80
100 if exitstat == errno.ENOSPC:
102 print os.strerror(exitstat)
106 print os.strerror(exitstat)
109 result = process.fromchild.readline()
112 print "Cannot find the seek argument in the output from " + growisofs
114 index = result.find("seek=")
116 res = result[index+5:-2]
117 if not res.isdigit():
119 print "Wrong seek argument in the output from " + growisofs
121 size = long(res)*32*1024
122 size = gettotalsize()-(size+margin)
126 print "No error occurred"