Re: Looking for multi-DVD spanning archiver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jun 6, 2010 at 10:28 AM, Richard Shaw <hobbes1069@xxxxxxxxx> wrote:
> On Sun, Jun 6, 2010 at 7:10 AM, Richard Shaw <hobbes1069@xxxxxxxxx> wrote:
>> Ok, a python guru I am not, but I did manage to replace the 'popen2'
>> call to the current 'subprocess' call which fixed DVD device discovery
>> for me. I still have to figure something else out though. When it
>> executed growisofs it crashed and I haven't figured out which piece of
>> it I broke, but I cut & pasted the growisofs call and now it's running
>> (burning). If I get it all figured out I'll put up the fixed script
>> somewhere.
>
> Ok, a couple of hours of hacking later here you go. Hopefully no one
> minds the attachment as it's a pretty small file. It come with a "It
> worked for me" warranty :)
>
> Other than fixing how it calls growisofs, I added a simple --help
> arguement and fixed the size for DVD +R discs.

Ignore the previous attachment, fixed one small error.

Richard
#! /usr/bin/python

import os, sys, os.path, math, tempfile, dbus, readline
from subprocess import *

def discover():

  # get a connection to the system bus
  
  drives = []
  discs = {
  'dvd_r' : 4.38 * 1024 * 1024 * 1024,
  'dvd_rw' : 4.38 * 1024 * 1024 * 1024,
  'dvd_plus_r' : 4.37 * 1024 * 1024 * 1024,
  'dvd_plus_rw' : 4.37 * 1024 * 1024 * 1024,
  'dvd_plus_r_dl':  4.37 * 2 * 1024 * 1024 * 1024,
  'dvd_plus_rw_dl':  4.37 * 2 * 1024 * 1024 * 1024,

#  bd_re      If someone can test this with these new formats,
#  hddvd_rw   let me know!  I need values for their capacity
#  bd_r
#  hddvd_r
  }
  
  bus = dbus.SystemBus ()

  hal_obj = bus.get_object ('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
  hal = dbus.Interface (hal_obj, 'org.freedesktop.Hal.Manager')
  
  udis = hal.FindDeviceByCapability ('volume')
  drives = {}
  for udi in udis:

    dev_obj = bus.get_object ('org.freedesktop.Hal', udi)
    dev = dbus.Interface (dev_obj, 'org.freedesktop.Hal.Device')
    parent_obj = bus.get_object ('org.freedesktop.Hal', dev.GetProperty("info.parent"))
    parent = dbus.Interface (parent_obj, 'org.freedesktop.Hal.Device')
    
    if parent.GetProperty ('storage.hotpluggable') or 'storage.cdrom' in parent.GetProperty('info.capabilities'):
        try:
          if dev.GetProperty('volume.disc.type') in discs.keys():
            device_name = dev.GetProperty ('block.device')
            capacity = discs[dev.GetProperty('volume.disc.type')]
            print capacity
            drive_name = parent.GetProperty('info.product')
            drives[device_name] = [capacity, drive_name]
            print "Found a %s in %s (%s)" % (dev.GetProperty('volume.disc.type'), device_name, drive_name  )
        except:
          continue
        else:
          continue
              
  return drives

def RunCmd(command):
    
    print "Running command : %s" % command
    app = Popen(command, bufsize=0, shell=True, close_fds=True, stdout=PIPE, stderr=STDOUT)
    output= []
    while app.poll() == None:
        while 1:

          try:
            line = app.stdout.readline().rstrip("\n")
            sys.stdout.flush()
          except:
            pass
            
          if not line: break
          output.append(line)
          print line
        
    if app.poll() > 0 :
     
         print "There was an error running %s." % command
         sys.exit(1)

    return output


def build_list(files, dvd_capacity):
 
  file_count = 1
  disc_size = 0
  disc_list = []
  disc_files = []
  outfiles = []
 
  for file in files:
    
    if not os.path.islink(file):    
      size = os.path.getsize(file)
      disc_size = disc_size + size
    else:
      size = 0
    
    if disc_size >= dvd_capacity:
      disc_list.append(disc_files)
      disc_size = 0
      disc_size = disc_size + size
      disc_files = []
      disc_files.append(file)

    else:
      disc_files.append(file)
      
  disc_list.append(disc_files)

  return (disc_list)
    

def burn(disc, dir, drive, speed, disc_num, total_disc):
  
  if disc_num ==1:
    msg = "\nReady to burn disc %s/%s.  Press Enter"  % (disc_num, total_disc )
  else:
    msg = "\nInsert Empty Disc %s/%s and Press Enter\n" % (disc_num, total_disc )

  input=raw_input(msg)
  
  list = ""
  for file in disc:
    file_on_disc = file.replace(dir, "")
    list = list + "%s=%s\n" % (file_on_disc, file)
  fd, temp_list = tempfile.mkstemp(suffix=".discspanlist")
  output = open(temp_list, 'w')
  output.write(list)
  output.close()
  burn_cmd = "growisofs -Z %s -speed=%s -use-the-force-luke=notray" \
              " -use-the-force-luke=tty  -gui" \
              " -V DiscSpanData -A DiscSpan -p Unknown -iso-level 3" \
              " -l -r -hide-rr-moved -J -joliet-long" \
              " -graft-points --path-list %s" %(drive, speed, temp_list)
  
  if len(sys.argv) >=2 :
  
    if sys.argv[1] == "test":

      burn_cmd = "growisofs -Z %s -speed=%s -use-the-force-luke=notray" \
                  " -use-the-force-luke=tty  -gui -use-the-force-luke=dummy" \
                  " -V DiscSpanData -A DiscSpan -p Unknown -iso-level 3" \
                  " -l -r -hide-rr-moved -J -joliet-long" \
                  " -graft-points --path-list %s" %(drive, speed, temp_list)


  RunCmd(burn_cmd)
  os.unlink(temp_list)
  RunCmd("eject")
  
if __name__ == "__main__":

  if len(sys.argv) > 1:
    if sys.argv[1] == '--help':
      print """
Usage: discspan.py

To test without burning run: discspan.py test
"""
  else:
	try:
	  valid = False
	  while valid == False:
	    dir = raw_input('Which directory would you like to backup?\n')
	  
	    if os.path.isdir(dir):
	      valid = True
	    else:
	      print "You must enter a valid directory."
	      valid = False
	  
	  input = raw_input("\nPlease put a blank DVD in your drive so I can attempt to autodetect the device name and press Enter\n")
	  
	  drives = discover()
	  
	  if len(drives) == 1:
	    statement = '\nUsing %s (%s) as your dvd burner, if this is wrong enter a valid one or press Enter to continue\n' % (drives.keys()[0], drives[drives.keys()[0]][1])
	    
	  elif len(drives) > 1:
	    statement ='\nFound these capable dvd burners %s, enter one\n' % " ".join(drives).keys()
	  else:
	    statement ='\nNo dvd burner(s) found.  You may attempt to manually enter a device name\n'
	  
	  drive_input=raw_input(statement)
	  
	  if drive_input == "" and len(drives) ==1:
	    drive = drives.keys()[0]
	  else:
	    drive = drive_input
	    
	  
	  
	  total_size = 0
	  disc_capacity = int(drives[drive][0])
	  
	  print "The disc capacity of the disc in %s (%s) is %s GB" % (drive, drives[drive][1], str(disc_capacity / 1073741824.0) )
	    
	  speed = raw_input("\nEnter the speed which your drive and media support and press Enter\n")
	  
	  
	  if dir[len(dir)-1:] != "/":
	    dir = dir + "/"
	  
	  file_list = []
	  
	  for path, dirs, files in os.walk(dir):
	    for filename in files:
	       file_list.append(os.path.join(path, filename))
	       print os.path.join(path, filename)
	  
	  
	  file_list.sort()
	  
	  for file in file_list:
	    if not os.path.islink(file):
	      size = os.path.getsize(file)
	      total_size = total_size + size
	      if size >= disc_capacity:
		print "%s is larger than the capacity of the disc.  I can not span large files across discs."
		sys.exit(1)
	      
	  
	  num_discs = int( math.ceil (total_size / disc_capacity) )
	  
	  
	  (discs) = build_list(file_list, disc_capacity)
	  
	  print "\nNumber of %s's required to burn: %s" % ("dvd", len(discs))
	  
	  file_count = 0
	  
	  for disc in discs:
	    file_count = file_count + len(disc)
	  
	  print "\nSanity Check\n"
	  print "Total files in directory", len(file_list)
	  print "Total files in all discs: ", file_count
	  
	  
	  disc_num = 1 
	  for disc in discs:
	    burn(disc,dir, drive, speed, disc_num, len(discs))
	    disc_num = disc_num + 1


	except KeyboardInterrupt:
	  print "\nUser Interrupted.\n"
	  sys.exit(1)
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux