def RecursiveDownload(dir_obj, target_dir, max_depth=10, depth=1, overwrite=False, max_threads=10):
 if (not isinstance(dir_obj, aff4.AFF4Volume)):
  return
 thread_pool = threadpool.ThreadPool.Factory('Downloader', max_threads)
 thread_pool.Start()
 for sub_file_entry in dir_obj.OpenChildren():
  path_elements = [target_dir]
  sub_target_dir = u'/'.join(path_elements)
  try:
   if isinstance(sub_file_entry, aff4.AFF4Stream):
    args = (sub_file_entry.urn, sub_target_dir, sub_file_entry.token, overwrite)
    thread_pool.AddTask(target=CopyAFF4ToLocal, args=args, name='Downloader')
   elif ('Container' in sub_file_entry.behaviours):
    if (depth >= max_depth):
     continue
    try:
     os.makedirs(sub_target_dir)
    except OSError:
     pass
    RecursiveDownload(sub_file_entry, sub_target_dir, overwrite=overwrite, depth=(depth + 1))
  except IOError:
   logging.exception('Unable to download %s', sub_file_entry.urn)
  finally:
   sub_file_entry.Close()
 if (depth <= 1):
  thread_pool.Stop()

def RecursiveDownload ( dir_obj , target_dir , max_depth = 10 , depth = 1 , overwrite = False , max_threads = 10 ) : if ( not isinstance ( dir_obj , aff4 . AFF4Volume ) ) : return thread_pool = threadpool . ThreadPool . Factory ( 'Downloader' , max_threads ) thread_pool . Start ( ) for sub_file_entry in dir_obj . OpenChildren ( ) : path_elements = [ target_dir ] sub_target_dir = u'/' . join ( path_elements ) try : if isinstance ( sub_file_entry , aff4 . AFF4Stream ) : args = ( sub_file_entry . urn , sub_target_dir , sub_file_entry . token , overwrite ) thread_pool . AddTask ( target = CopyAFF4ToLocal , args = args , name = 'Downloader' ) elif ( 'Container' in sub_file_entry . behaviours ) : if ( depth >= max_depth ) : continue try : os . makedirs ( sub_target_dir ) except OSError : pass RecursiveDownload ( sub_file_entry , sub_target_dir , overwrite = overwrite , depth = ( depth + 1 ) ) except IOError : logging . exception ( 'Unable to download %s' , sub_file_entry . urn ) finally : sub_file_entry . Close ( ) if ( depth <= 1 ) : thread_pool . Stop ( )
recursively downloads a file entry to the target path .