(source, target, erase=True, verify=True, show_activity=False)
return True
A wrapper around 'asr' to clone one disk object onto another.

  We run with --puppetstrings so that we get non-buffered output that we can
  actually read when show_activity=True.

  Args:
    source: A Disk or Image object.
    target: A Disk object (including a Disk from a mounted Image)
    erase:  Whether to erase the target. Defaults to True.
    verify: Whether to verify the clone operation. Defaults to True.
    show_activity: whether to print the progress to the screen.
  Returns:
    boolean: whether the operation succeeded.
  Raises:
    MacDiskError: source is not a Disk or Image object
    MacDiskError: target is not a Disk object
A wrapper around 'asr' to clone one disk object onto another.
A wrapper around asr to clone one disk object onto another .
def Clone(source, target, erase=True, verify=True, show_activity=False):
  """A wrapper around 'asr' to clone one disk object onto another.

  We run with --puppetstrings so that we get non-buffered output that we can
  actually read when show_activity=True.

  Args:
    source: A Disk or Image object.
    target: A Disk object (including a Disk from a mounted Image)
    erase:  Whether to erase the target. Defaults to True.
    verify: Whether to verify the clone operation. Defaults to True.
    show_activity: whether to print the progress to the screen.
  Returns:
    boolean: whether the operation succeeded.
  Raises:
    MacDiskError: source is not a Disk or Image object
    MacDiskError: target is not a Disk object
  """

  if isinstance(source, Image):
    # even attached dmgs can be a restore source as path to the dmg
    source_ref = source.imagepath
  elif isinstance(source, Disk):
    source_ref = "/dev/%s" % source.deviceidentifier
  else:
    raise MacDiskError("source is not a Disk or Image object")

  if isinstance(target, Disk):
    target_ref = "/dev/%s" % target.deviceidentifier
  else:
    raise MacDiskError("target is not a Disk object")

  command = ["/usr/sbin/asr", "restore", "--source", source_ref, "--target",
             target_ref, "--noprompt", "--puppetstrings"]

  if erase:
    # check we can unmount the target... may as well fail here than later.
    if target.Mounted():
      target.Unmount()
    command.append("--erase")

  if not verify:
    command.append("--noverify")

  task = subprocess.Popen(command, stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
  returncode = task.poll()
  if show_activity:
    while returncode < 0:
      print task.stdout.readline().strip()
      returncode = task.poll()

  (unused_stdout, stderr) = task.communicate()

  if task.returncode:
    raise MacDiskError("Cloning Error: %s" % stderr)

  return True
def Clone ( source , target , erase = True , verify = True , show_activity = False ) : if isinstance ( source , Image ) : # even attached dmgs can be a restore source as path to the dmg source_ref = source . imagepath elif isinstance ( source , Disk ) : source_ref = "/dev/%s" % source . deviceidentifier else : raise MacDiskError ( "source is not a Disk or Image object" ) if isinstance ( target , Disk ) : target_ref = "/dev/%s" % target . deviceidentifier else : raise MacDiskError ( "target is not a Disk object" ) command = [ "/usr/sbin/asr" , "restore" , "--source" , source_ref , "--target" , target_ref , "--noprompt" , "--puppetstrings" ] if erase : # check we can unmount the target... may as well fail here than later. if target . Mounted ( ) : target . Unmount ( ) command . append ( "--erase" ) if not verify : command . append ( "--noverify" ) task = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) returncode = task . poll ( ) if show_activity : while returncode < 0 : print task . stdout . readline ( ) . strip ( ) returncode = task . poll ( ) ( unused_stdout , stderr ) = task . communicate ( ) if task . returncode : raise MacDiskError ( "Cloning Error: %s" % stderr ) return True