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>
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 dvdrwmediainfo="@DVDRWMEDIAINFO@"
21 margin=10485760 # 10 mb security margin
24 # end of configurable values
32 print "Wrong number of arguments."
38 cmd=dvdrwmediainfo + " " + device
39 processi = popen2.Popen4(cmd)
40 status = processi.wait()
41 if not os.WIFEXITED(status):
43 print dvdrwmediainfo + " process did not exit correctly."
45 if os.WEXITSTATUS(status) != 0:
47 print "Cannot get media info from " + dvdrwmediainfo
50 result = processi.fromchild.readline()
51 if result.find("Track Size:") > -1:
52 index = result.find("*2KB")
54 return long(result[12:index]) * 2048
57 print "Invalid format in media info lead-out line from " + dvdrwmediainfo
59 if result.find("Legacy lead-out at:") > -1:
60 index = result.find("=")
62 res = result[index+1:-1]
65 print "Invalid format in media info lead-out line from " + dvdrwmediainfo
70 print "Invalid format in media info lead-out line from " + dvdrwmediainfo
74 print "Cannot get media lead-out index from " + dvdrwmediainfo
78 process = popen2.Popen4(cmd)
79 status = process.wait()
80 if not os.WIFEXITED(status):
82 print df + " process did not not exit correctly."
85 exitstat = os.WEXITSTATUS(status) & ~0x80
86 if exitstat == errno.ENOSPC:
88 print os.strerror(exitstat)
92 print os.strerror(exitstat)
96 result = process.fromchild.readline()
99 print "Cannot get output from " + df
101 index = result.find(device)
103 while result[index] != ' ':
105 while result[index] == ' ':
108 while result[eindex] != ' ':
110 res = result[index:eindex]
111 if not res.isdigit():
113 print "Could not find size in df output"
115 size = long(res)*1024
118 size = gettotalsize()-(size+margin)
122 print "No error occurred"