I've reworked dvd-handler, and it now works without any patch. It uses
dvd+rw-mediainfo to grab information about the space left on a DVD
device.

As someone already pointed, there is no error handling when there is
*no* media in the drive.

See the modified dvd-handler attached (from version 2.0.2).


It might need some testing, but it works here.

thanks for the software,

Alexandre Bourget


Le jeudi 14 juin 2007 à 11:22 -0400, Alexandre Bourget a écrit :
> I was wondering if it was possible to rewrite a part of dvd-handler to
> use dvd+rw-mediainfo instead of growisofs to grab the freespace on a DVD
> media.
> 
> That is, because I didn't find a patch for dvd+rw-tools 7.0 (which I
> have installed), and also, if we can use dvd+rw-mediainfo, we would need
> no patch!
> 
> Is the information here good to extract the 'appendableness' and
> free-space of a DVD medium ?
> 
> Also, mediainfo is called already by dvd-handler (although perhaps not
> at the same moment ?)
> 
> 
> thanks
> 
> Alexandre Bourget
> 
> dvd+rw-mediainfo outputs follow
> 
> 
> 
> 
> 
> ####
> #### That's the output I get on a full disk (with DVD video on it):
> ####
> INQUIRY:                [TSSTcorp][CD/DVDW SH-S162L][LC02]
> GET [CURRENT] CONFIGURATION:
>  Mounted Media:         11h, DVD-R Sequential
>  Media ID:              MCC 03RG20
>  Current Write Speed:   16.0x1385=22160KB/s
>  Write Speed #0:        16.0x1385=22160KB/s
>  Write Speed #1:        12.0x1385=16620KB/s
>  Write Speed #2:        8.0x1385=11080KB/s
>  Write Speed #3:        4.0x1385=5540KB/s
> GET [CURRENT] PERFORMANCE:
>  Write Performance:     16.0x1385=22160KB/[EMAIL PROTECTED] -> 2298496]
>  Speed Descriptor#0:    08/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#1:    08/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#2:    08/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#3:    00/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
> READ DVD STRUCTURE[#10h]:
>  Media Book Type:       00h, DVD-ROM book [revision 0]
>  Legacy lead-out at:    2298496*2KB=4707319808
> READ DVD STRUCTURE[#0h]:
>  Media Book Type:       25h, DVD-R book [revision 5]
>  Last border-out at:    2045*2KB=4188160
> READ DISC INFORMATION:
>  Disc status:           complete
>  Number of Sessions:    1
>  State of Last Session: complete
>  Number of Tracks:      1
> READ TRACK INFORMATION[#1]:
>  Track State:           complete incremental
>  Track Start Address:   0*2KB
>  Free Blocks:           0*2KB
>  Track Size:            1398048*2KB
>  Last Recorded Address: 1398047*2KB
> FABRICATED TOC:
>  Track#1  :             [EMAIL PROTECTED]
>  Track#AA :             [EMAIL PROTECTED]
>  Multi-session Info:    [EMAIL PROTECTED]
> READ CAPACITY:          1398048*2048=2863202304
> 
> 
> 
> 
> 
> ####
> #### On a blank disk
> ####
> INQUIRY:                [TSSTcorp][CD/DVDW SH-S162L][LC02]
> GET [CURRENT] CONFIGURATION:
>  Mounted Media:         11h, DVD-R Sequential
>  Media ID:              MCC 03RG20
>  Current Write Speed:   16.0x1385=22160KB/s
>  Write Speed #0:        16.0x1385=22160KB/s
>  Write Speed #1:        12.0x1385=16620KB/s
>  Write Speed #2:        8.0x1385=11080KB/s
>  Write Speed #3:        4.0x1385=5540KB/s
> GET [CURRENT] PERFORMANCE:
>  Write Performance:     16.0x1385=22160KB/[EMAIL PROTECTED] -> 2298496]
>  Speed Descriptor#0:    08/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#1:    08/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#2:    08/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#3:    00/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
> READ DVD STRUCTURE[#10h]:
>  Media Book Type:       00h, DVD-ROM book [revision 0]
>  Legacy lead-out at:    2298496*2KB=4707319808
> READ DVD STRUCTURE[#0h]:
>  Media Book Type:       25h, DVD-R book [revision 5]
>  Last border-out at:    2045*2KB=4188160
> READ DISC INFORMATION:
>  Disc status:           blank
>  Number of Sessions:    1
>  State of Last Session: empty
>  "Next" Track:          1
>  Number of Tracks:      1
> READ TRACK INFORMATION[#1]:
>  Track State:           blank
>  Track Start Address:   0*2KB
>  Next Writable Address: 0*2KB
>  Free Blocks:           2298496*2KB
>  Track Size:            2298496*2KB
> READ CAPACITY:          0*2048=0
> 
> 
> 
> 
> ####
> #### Output of an already Bacula-written disk:
> ####
> INQUIRY:                [TSSTcorp][CD/DVDW TS-H552U][US03]
> GET [CURRENT] CONFIGURATION:
>  Mounted Media:         11h, DVD-R Sequential
>  Media ID:              PRINCO8X02
>  Current Write Speed:   8.0x1385=11080KB/s
>  Write Speed #0:        8.0x1385=11080KB/s
>  Write Speed #1:        6.0x1385=8310KB/s
>  Write Speed #2:        4.0x1385=5540KB/s
>  Write Speed #3:        2.0x1385=2770KB/s
>  Speed Descriptor#0:    08/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#1:    08/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#2:    00/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
>  Speed Descriptor#3:    00/2297887 [EMAIL PROTECTED]/s
> [EMAIL PROTECTED]/s
> READ DVD STRUCTURE[#10h]:
>  Media Book Type:       25h, DVD-R book [revision 5]
>  Legacy lead-out at:    2298496*2KB=4707319808
> READ DVD STRUCTURE[#0h]:
>  Media Book Type:       25h, DVD-R book [revision 5]
>  Last border-out at:    2176176*2KB=4456808448
> READ DISC INFORMATION:
>  Disc status:           appendable
>  Number of Sessions:    7
>  State of Last Session: empty
>  "Next" Track:          7
>  Number of Tracks:      7
> READ TRACK INFORMATION[#1]:
>  Track State:           complete incremental
>  Track Start Address:   0*2KB
>  Free Blocks:           0*2KB
>  Track Size:            65264*2KB
>  Last Recorded Address: 175*2KB
> READ TRACK INFORMATION[#2]:
>  Track State:           complete incremental
>  Track Start Address:   93952*2KB
>  Free Blocks:           0*2KB
>  Track Size:            409776*2KB
>  Last Recorded Address: 503727*2KB
> READ TRACK INFORMATION[#3]:
>  Track State:           complete incremental
>  Track Start Address:   509888*2KB
>  Free Blocks:           0*2KB
>  Track Size:            409776*2KB
>  Last Recorded Address: 919663*2KB
> READ TRACK INFORMATION[#4]:
>  Track State:           complete incremental
>  Track Start Address:   927360*2KB
>  Free Blocks:           0*2KB
>  Track Size:            409776*2KB
>  Last Recorded Address: 1337135*2KB
> READ TRACK INFORMATION[#5]:
>  Track State:           complete incremental
>  Track Start Address:   1346880*2KB
>  Free Blocks:           0*2KB
>  Track Size:            409776*2KB
>  Last Recorded Address: 1756655*2KB
> READ TRACK INFORMATION[#6]:
>  Track State:           complete incremental
>  Track Start Address:   1766400*2KB
>  Free Blocks:           0*2KB
>  Track Size:            409776*2KB
>  Last Recorded Address: 2176175*2KB
> READ TRACK INFORMATION[#7]:
>  Track State:           invisible incremental
>  Track Start Address:   2185920*2KB
>  Next Writable Address: 2185920*2KB
>  Free Blocks:           111968*2KB
>  Track Size:            111968*2KB
> READ CAPACITY:          2176176*2048=4456808448
> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Bacula-users mailing list
> Bacula-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bacula-users
> 
> 
#!/usr/bin/python
#
# Check the free space available on a writable DVD
# Should always exit with 0 status, otherwise it indicates a serious error.
# (wrong number of arguments, Python exception...)
#
#  called:  dvd-handler <dvd-device-name> operation args
#
#  operations used by Bacula:
#
#   free  (no arguments)
#	      Scan the device and report the available space. It returns:
#	      Prints on the first output line the free space available in bytes.
#	      If an error occurs, prints a negative number (-errno), followed,
#	      on the second line, by an error message.
#
#   write  op filename
#	       Write a part file to disk.
#	       This operation needs two additional arguments.
#	       The first (op) indicates to
#		   0 -- append
#		   1 -- first write to a blank disk
#		   2 -- blank or truncate a disk
#
#		The second is the filename to write
#
#   operations available but not used by Bacula:
#
#   test      Scan the device and report the information found.
#	       This operation needs no further arguments.
#   prepare   Prepare a DVD+/-RW for being used by Bacula.
#	       Note: This is only useful if you already have some
#	       non-Bacula data on a medium, and you want to use
#	       it with Bacula. Don't run this on blank media, it
#	       is useless.
#
# 
# $Id: dvd-handler.in,v 1.14 2006/12/22 15:01:04 kerns Exp $
#

import popen2
import os
import os.path
import errno
import sys
import re
import signal
import time
import array

class disk:
# Configurable values:
   
   dvdrwmediainfo = "/usr/bin/dvd+rw-mediainfo"
   growcmd = "/usr/bin/growisofs"
   dvdrwformat = "/usr/bin/dvd+rw-format"
   dd = "/bin/dd"
   margin = 10485760 # 10 mb security margin

   # Comment the following line if you want the tray to be reloaded
   # when writing ends.
   growcmd += " -use-the-force-luke=notray"

# end of configurable values

###############################################################################
#
# This class represents DVD disk informations.
# When instantiated, it needs a device name.
# Status information about the device and the disk loaded is collected only when
# asked for (for example dvd-freespace doesn't need to know the media type, and
# dvd-writepart doesn't not always need to know the free space).
#
# The following methods are implemented:
# __init__	 we need that...
# __repr__	 this seems to be a good idea to have.
#		 Quite minimalistic implementation, though.
# __str__	 For casts to string. Return the current disk information
# is_empty	 Returns TRUE if the disk is empty, blank... this needs more
#		 work, especially concerning non-RW media and blank vs. no
#		 filesystem considerations. Here, we should also look for
#		 other filesystems - probably we don't want to silently
#		 overwrite UDF or ext2 or anything not mentioned in fstab...
#		 (NB: I don't think it is a problem)
# free		 Returns the available free space.
# write 	 Writes one part file to disk, either starting a new file
#		 system on disk, or appending to it.
#		 This method should also prepare a blank disk so that a
#		 certain part of the disk is used to allow detection of a
#		 used disk by all / more disk drives.
# prepare 	 Blank the device
#
###############################################################################
   def __init__(self, devicename):
      self.device = devicename
      self.disktype = "none"
      self.diskmode = "none"
      self.diskstatus = "none"
      self.hardwaredevice = "none"
      self.pid = 0
      self._is_blank = False
      self.free_space = -1

      self.info_collected = 0

      self.growcmd += " -quiet"

      if self.is4gbsupported():
	 self.growcmd += " -use-the-force-luke=4gms"

      self.growparams = " -A 'Bacula Data' -input-charset=default -iso-level 3 -pad " + \
			"-p 'dvd-handler / growisofs' -sysid 'BACULADATA' -R"

      return

   def __repr__(self):
      return "disk(" + self.device + ") # This is an instance of class disk"

   def __str__(self):
      if not self.info_collected:
	 self.collect_info();
      
      self.me  = "Class disk, initialized with device '" + self.device + "'\n"
      self.me += "type = '" + self.disktype + "' mode='" + self.diskmode + "' status = '" + self.diskstatus + "'\n"
      self.me += " _is_blank = " + str(self.is_blank()) + " free_space = " + str(self.free_space) + "\n"
      self.me += "Hardware device is '" + self.hardwaredevice + "'\n"
      self.me += "growcmd = '" + self.growcmd + "'\ngrowparams = '" + self.growparams + "'\n"
      return self.me

   ## Check if we want to allow growisofs to cross the 4gb boundary
   def is4gbsupported(self):
      processi = popen2.Popen4("uname -s -r")
      status = processi.wait()
      if not os.WIFEXITED(status):
	 return 1
      if os.WEXITSTATUS(status) != 0:
	 return 1
      strres = processi.fromchild.readline()[0:-1]
      version = re.search(r"Linux (\d+)\.(\d+)\.(\d+)", strres)
      if not version: # Non-Linux: allow
	 return 1
      
      if (int(version.group(1)) > 2) or (int(version.group(2)) > 6) or ((int(version.group(1)) == 2) and (int(version.group(2)) == 6) and (int(version.group(3)) >= 8)):
	 return 1
      else:
	 return 0

   #def collect_freespace(self): # Collects current free space
   #   self.cmd = self.dvdrwmediainfo + ' ' + self.device
   #   processi = popen2.Popen4(self.cmd)
   #   status = processi.wait()
   #   if not os.WIFEXITED(status):
   #	 raise DVDError(0, "dvd+rw-mediainfo process did not exit correctly.\nCommand was: "+self.cmd)
   #   result = processi.fromchild.read()
   #
   #   if os.WEXITSTATUS(status) != 0:
   #      if (os.WEXITSTATUS(status) & 0x7F) == errno.ENOSPC:
   #         # Kludge to force dvd-handler to return a free space of 0
   #         self._is_blank = False
   #         self.free_space = 0
   #	    self.freespace_collected = 1
   #	    return
   #	 else:
   #	    raise DVDError(os.WEXITSTATUS(status), "dvd+rw-mediainfo returned with an error:\n" + result)
   #
   #   #if self.next_session > 100000000:
   #   #   self.capacity = self.next_session
   #   
   #   self.freespace_collected = 1
   #   return
   
   def collect_info(self): # Collects current medium type and space information.
      self.lasterror = ""
      cmd = self.dvdrwmediainfo + " " + self.device
      processi = popen2.Popen4(cmd)
      status = processi.wait()
      if not os.WIFEXITED(status):
	 raise DVDError(0, self.dvdrwmediainfo + " process did not exit correctly.")
      if os.WEXITSTATUS(status) != 0:
	 raise DVDError(0, "Cannot get media info from " + self.dvdrwmediainfo)
	 return
      result = processi.fromchild.read()
      
      hardware = re.search(r"INQUIRY:\s+(.*)\n", result, re.MULTILINE)
      mediatype = re.search(r"\sMounted Media:\s+([0-9A-F]{2})h, (\S*)\s", result, re.MULTILINE)
      mediamode = re.search(r"\sMounted Media:\s+[0-9A-F]{2}h, \S* (.*)\n", result, re.MULTILINE)
      status = re.search(r"\sDisc status:\s+(.*)\n", result, re.MULTILINE)

      free_blocks = re.findall(r'Free.Blocks:\s*(\d*)', result)
      track_state = re.findall(r'Track.State:\s*(.*)', result)
      
      if status:
	 self.diskstatus = status.group(1)
      else:
	 raise DVDError(0, "Disc status not found in " + self.dvdrwmediainfo + " output")

      # complete, appendable, blank, other ? (from v7.0's dvd+rw-mediainfo.cpp:873)
      if status.group(1) == 'complete':
         self.free_space = 0
      elif (status.group(1) == 'appendable' or
            status.group(1) == 'blank'):
         self.free_space = 0
         for x in range(0, len(free_blocks)):
            # Not sure if the 'partial incremental' should be there. Is it something appendable ?
            if track_state[x] in ['invisible incremental', 'blank', 'partial incremental']:
               self.free_space += (int(free_blocks[x]) * 2048)
      else:
         raise DVDError(0, "Can't find the status of the inserted disk, thus can't determine available space. Or is there an inserted disk ?\nReturned:"+result)

      if hardware:
	 self.hardwaredevice = hardware.group(1)
      
      if mediatype:
	 self.disktype = mediatype.group(2)
      else:
	 raise DVDError(0, "Media type not found in " + self.dvdrwmediainfo + " output")
      
      if self.disktype == "DVD-RW":
	 if mediamode:
	    self.diskmode = mediamode.group(1)
	 else:
	    raise DVDError(0, "Media mode not found for DVD-RW in " + self.dvdrwmediainfo + " output")
      
      self.info_collected = 1
      return

   def is_empty(self):
      if not self.info_collected:
	 self.collect_info();
      
      return self.is_blank()

   def is_RW(self):
      if not self.info_collected:
	 self.collect_info();
      return "DVD-RW" == self.disktype or "DVD+RW" == self.disktype or "DVD-RAM" == self.disktype

   def is_plus_RW(self):
      if not self.info_collected:
	 self.collect_info();
      return "DVD+RW" == self.disktype

   def is_minus_RW(self):
      if not self.info_collected:
	 self.collect_info();
      return "DVD-RW" == self.disktype
      
   def is_restricted_overwrite(self):
      if not self.info_collected:
	 self.collect_info();
      return self.diskmode == "Restricted Overwrite"

   def is_blank(self):
      if not self.info_collected:
	 self.collect_info();
      
      return self.diskstatus == "blank"

   def free(self):
      if not self.info_collected:
	 self.collect_info();

      # Keep a safe margin...
      fr = self.free_space - self.margin
      if fr < 0:
	 return 0
      else:
	 return fr

   def term_handler(self, signum, frame):
      print 'dvd-handler: Signal term_handler called with signal', signum
      if self.pid != 0:
	 print "dvd-handler: Sending SIGTERM to pid", self.pid
	 os.kill(self.pid, signal.SIGTERM)
	 time.sleep(10)
	 print "dvd-handler: Sending SIGKILL to pid", self.pid
	 os.kill(self.pid, signal.SIGKILL)
	 sys.exit(1)

   def write(self, newvol, partfile):
      # Blank DVD+RW when there is no data on it
      if newvol and self.is_plus_RW() and self.is_blank():
	 print "DVD+RW looks brand-new, blank it to fix some DVD-writers bugs."
	 self.blank()
	 print "Done, now writing the part file."
      
      if newvol and self.is_minus_RW() and (not self.is_restricted_overwrite()):
	 print "DVD-RW is in " + self.diskmode + " mode, reformating it to Restricted Overwrite"
	 self.reformat_minus_RW()
	 print "Done, now writing the part file."
      
      cmd = self.growcmd + self.growparams
      if newvol:
	 # Ignore any existing iso9660 filesystem - used for truncate
	 if newvol == 2:
	     cmd += " -use-the-force-luke=tty"
	 cmd += " -Z "
      else:
	 cmd += " -M "
      cmd += self.device + " " + str(partfile)
      print "Running " + cmd
      oldsig = signal.signal(signal.SIGTERM, self.term_handler)
      proc = popen2.Popen4(cmd)
      self.pid = proc.pid
      status = proc.poll()
      while status == -1:
	 line = proc.fromchild.readline()
	 while len(line) > 0:
	    print line,
	    line = proc.fromchild.readline()
	 time.sleep(1)
	 status = proc.poll()
      self.pid = 0
      print
      signal.signal(signal.SIGTERM, oldsig)
      if not os.WIFEXITED(status):
	 raise DVDError(0, cmd + " process did not exit correctly, signal/status " + str(status))
      if os.WEXITSTATUS(status) != 0:
	 raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status))

   def prepare(self):
      if not self.is_RW():
	 raise DVDError(0, "I won't prepare a non-rewritable medium")
      
      # Blank DVD+RW when there is no data on it
      if self.is_plus_RW() and self.is_blank():
	 print "DVD+RW looks brand-new, blank it to fix some DVD-writers bugs."
	 self.blank()
	 return # It has been completely blanked: Medium is ready to be used by Bacula
      
      if self.is_minus_RW() and (not self.is_restricted_overwrite()):
	 print "DVD-RW is in " + self.diskmode + " mode, reformating it to Restricted Overwrite"
	 self.reformat_minus_RW()
	 return # Reformated: Medium is ready to be used by Bacula
      
      # TODO: Check if /dev/fd/0 and /dev/zero exists, otherwise, run self.blank()
      if not os.path.exists("/dev/fd/0") or not os.path.exists("/dev/zero"):
	 print "/dev/fd/0 or /dev/zero doesn't exist, blank the medium completely."
	 self.blank()
	 return
      
      cmd = self.dd + " if=/dev/zero bs=1024 count=512 | " + self.growcmd + " -Z " + self.device + "=/dev/fd/0"
      print "Running " + cmd
      oldsig = signal.signal(signal.SIGTERM, self.term_handler)
      proc = popen2.Popen4(cmd)
      self.pid = proc.pid
      status = proc.poll() 
      while status == -1:
	 line = proc.fromchild.readline()
	 while len(line) > 0:
	    print line,
	    line = proc.fromchild.readline()
	 time.sleep(1)
	 status = proc.poll()
      self.pid = 0
      print
      signal.signal(signal.SIGTERM, oldsig)
      if os.WEXITSTATUS(status) != 0:
	 raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status))

   def blank(self):
      cmd = self.growcmd + " -Z " + self.device + "=/dev/zero"
      print "Running " + cmd
      oldsig = signal.signal(signal.SIGTERM, self.term_handler)
      proc = popen2.Popen4(cmd)
      self.pid = proc.pid
      status = proc.poll()
      while status == -1:
	 line = proc.fromchild.readline()
	 while len(line) > 0:
	    print line,
	    line = proc.fromchild.readline()
	 time.sleep(1)
	 status = proc.poll()
      self.pid = 0
      print
      signal.signal(signal.SIGTERM, oldsig)
      if os.WEXITSTATUS(status) != 0:
	 raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status))

   def reformat_minus_RW(self):
      cmd = self.dvdrwformat + " -force " + self.device
      print "Running " + cmd
      oldsig = signal.signal(signal.SIGTERM, self.term_handler)
      proc = popen2.Popen4(cmd)
      self.pid = proc.pid
      status = proc.poll()
      while status == -1:
	 line = proc.fromchild.readline()
	 while len(line) > 0:
	    print line,
	    line = proc.fromchild.readline()
	 time.sleep(1)
	 status = proc.poll()
      self.pid = 0
      print
      signal.signal(signal.SIGTERM, oldsig)
      if os.WEXITSTATUS(status) != 0:
	 raise DVDError(os.WEXITSTATUS(status), cmd + " exited with status " + str(os.WEXITSTATUS(status)) + ", signal/status " + str(status))

# class disk ends here.

class DVDError(Exception):
   def __init__(self, errno, value):
      self.errno = errno
      self.value = value
      if self.value[-1] == '\n':
	 self.value = self.value[0:-1]
   def __str__(self):
      return str(self.value) + " || errno = " + str(self.errno) + " (" + os.strerror(self.errno & 0x7F) + ")"

def usage():
   print "Wrong number of arguments."
   print """
Usage:

dvd-handler DEVICE test
dvd-handler DEVICE free
dvd-handler DEVICE write APPEND FILE
dvd-handler DEVICE prepare

where DEVICE is a device name like /dev/sr0 or /dev/dvd.

Operations:
test	  Scan the device and report the information found.
	   This operation needs no further arguments.
free	  Scan the device and report the available space.
write	  Write a part file to disk.
	   This operation needs two additional arguments.
	   The first indicates to append (0), restart the
	   disk (1) or restart existing disk (2). The second
	   is the file to write.
prepare   Prepare a DVD+/-RW for being used by Bacula.
	   Note: This is only useful if you already have some
	   non-Bacula data on a medium, and you want to use
	   it with Bacula. Don't run this on blank media, it
	   is useless.
"""
   sys.exit(1)

if len(sys.argv) < 3:
   usage()

dvd = disk(sys.argv[1])

if "free" == sys.argv[2]:
   if len(sys.argv) == 3:
      try:
	 free = dvd.free()
      except DVDError, e:
	 if e.errno != 0:
	    print -e.errno
	 else:
	    print errno.EPIPE
	 print str(e)
      else:
	 print free
	 print "No Error reported."
   else:
      print "Wrong number of arguments for free operation. Wanted 3 got", len(sys.argv)
      usage()
elif "prepare" == sys.argv[2]:
   if len(sys.argv) == 3:
      try:
	 dvd.prepare()
      except DVDError, e:
	 print "Error while preparing medium: ", str(e)
	 if e.errno != 0:
	    sys.exit(e.errno & 0x7F)
	 else:
	    sys.exit(errno.EPIPE)
      else:
	 print "Medium prepared successfully."
   else:
      print "Wrong number of arguments for prepare operation. Wanted 3 got", len(sys.argv)
      usage()
elif "test" == sys.argv[2]:
   try:
      print str(dvd)
      print "Blank disk: " + str(dvd.is_blank()) + " ReWritable disk: " + str(dvd.is_RW())
      print "Free space: " + str(dvd.free())
   except DVDError, e:
      print "Error while getting informations: ", str(e)
elif "write" == sys.argv[2]:
   if len(sys.argv) == 5:
      try:
	 dvd.write(long(sys.argv[3]), sys.argv[4])
      except DVDError, e:
	 print "Error while writing part file: ", str(e)
	 if e.errno != 0:
	    sys.exit(e.errno & 0x7F)
	 else:
	    sys.exit(errno.EPIPE)
      else:
	 print "Part file " + sys.argv[4] + " successfully written to disk."
   else:
      print "Wrong number of arguments for write operation. Wanted 5 got", len(sys.argv)
      usage()
      sys.exit(1)
else:
   print "No operation - use test, free, prepare or write."
   print "THIS MIGHT BE A CASE OF DEBUGGING BACULA OR AN ERROR!"
sys.exit(0)
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to