3 # Bacula interface to growisofs, used to write to DVD+/-R(W)
7 # If you set in your Device resource
9 # Write Part Command = "path-to-this-script/dvd-writepart %e %a %v"
10 # you will have the following input to this script:
12 # dvd-writepart "erase" "device" "part_filename"
17 # dvd-writepart 0 /dev/hda File-0001
20 growcmd = "@GROWISOFS@"
22 growcmd += " -use-the-force-luke=tty"
25 # Comment the following line if you want the tray to be reloaded
27 growcmd += " -use-the-force-luke=notray"
29 #### You should probably not modify anything below this line
40 processi = popen2.Popen4("uname -s -r")
41 status = processi.wait()
42 if not os.WIFEXITED(status):
43 print "dvd-writepart: Cannot execute uname, allowing to cross the 4gb boundary."
45 if os.WEXITSTATUS(status) != 0:
46 print "dvd-writepart: Cannot execute uname, allowing to cross the 4gb boundary."
48 strres = processi.fromchild.readline()[0:-1]
49 res = strres.split(" ")
51 print "dvd-writepart: Unable to parse uname (" + strres + "), allowing to cross the 4gb boundary."
54 print "dvd-writepart: The current OS is no Linux, allowing to cross the 4gb boundary."
56 ver = res[1].split(".")
58 print "dvd-writepart: Unable to parse version string (" + res[1] + "), allowing to cross the 4gb boundary."
60 subver = ver[2].split("-")
62 if ((not ver[0].isdigit()) or (not ver[1].isdigit()) or (not subver[0].isdigit())):
63 print "dvd-writepart: Unable to parse version string (" + res[1] + "), allowing to cross the 4gb boundary."
66 if (int(ver[0]) > 2) or (int(ver[1]) > 6) or ((int(ver[0]) == 2) and (int(ver[1]) == 6) and (int(subver[0]) >= 8)):
67 print "dvd-writepart: Kernel version >=2.6.8, allowing to cross the 4gb boundary."
70 print "dvd-writepart: Kernel version <2.6.8, not allowing to cross the 4gb boundary."
73 def term_handler(signum, frame):
74 print 'dvd-writepart: Signal term_handler called with signal', signum
76 print "dvd-writepart: Sending SIGTERM to pid", pid
77 os.kill(pid, signal.SIGTERM)
79 print "dvd-writepart: Sending SIGKILL to pid", pid
80 os.kill(pid, signal.SIGKILL)
83 if len(sys.argv) != 4:
84 print "dvd-writepart: Wrong number of arguments."
88 growcmd += " -use-the-force-luke=4gms"
90 if sys.argv[1] == "0":
95 growcmd += " " + sys.argv[2] # device
96 growcmd += " -R " + sys.argv[3] # filename
99 #growcmd = "bash -c \"while [ 1 ]; do echo \"G\"; sleep 5; done\""
101 print "dvd-writepart: executing: " + growcmd
103 signal.signal(signal.SIGTERM, term_handler)
105 processi = popen2.Popen4(growcmd)
107 status = processi.poll()
109 line = processi.fromchild.readline()
112 line = processi.fromchild.readline()
114 status = processi.poll()
116 if os.WEXITSTATUS(status) != 0:
117 print "dvd-writepart: Bad exit status " + str(os.WEXITSTATUS(status))
118 sys.exit(os.WEXITSTATUS(status))