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 # Prints on the first output line the free space available in bytes.
8 # If an error occurs, prints a negative number (-errno), followed,
9 # on the second line, by an error message.
13 # Configurable values:
15 growisofs="@GROWISOFS@"
16 dvdrwmediainfo="@DVDRWMEDIAINFO@"
18 margin=10485760 # 10 mb security margin
22 # Uncomment the following line if you have a Linux kernel >=2.6.8, and
23 # if you want to allow a session to start behind the 4gb boundary.
24 #growisofsparams = growisofsparams + " -use-the-force-luke=4gms"
26 # end of configurable values
34 if len(sys.argv) != 3:
35 print "Wrong number of argument."
39 part_num=int(sys.argv[2])
41 os.environ["MKISOFS"] = mkisofs
44 cmd=dvdrwmediainfo + " " + device
45 processi = popen2.Popen4(cmd)
46 status = processi.wait()
47 if not os.WIFEXITED(status):
49 print "Process has not exited correctly."
51 if os.WEXITSTATUS(status) != 0:
53 print 'Cannot get media info.'
56 result = processi.fromchild.readline()
57 if result.find("Legacy lead-out at:") > -1:
58 index = result.find("=")
60 res = result[index+1:-1]
63 print 'Invalid format in media info lead-out line.'
68 print 'Invalid format in media info lead-out line.'
72 print 'Cannot get media lead-out index.'
75 tmpfile = tempfile.NamedTemporaryFile()
80 cmd=growisofs + " " + growisofsparams + " -use-the-force-luke=tty -dry-run -quiet " + flag + " " + device + " -R " + tmpfile.name
81 process = popen2.Popen4(cmd)
82 status = process.wait()
83 if not os.WIFEXITED(status):
85 print "Process has not exited correctly."
88 exitstat = os.WEXITSTATUS(status) & ~0x80
89 if exitstat == errno.ENOSPC:
91 print os.strerror(exitstat)
95 print os.strerror(exitstat)
98 result = process.fromchild.readline()
101 print 'Cannot find the seek argument in the output.'
103 index = result.find("seek=")
105 res = result[index+5:-2]
106 if not res.isdigit():
108 print 'Wrong seek argument in the output.'
110 size = int(res)*32*1024
111 size = gettotalsize()-(size+margin)
115 print "No error occured"