def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, ignore_dangling_symlinks=False):
 names = os.listdir(src)
 if (ignore is not None):
  ignored_names = ignore(src, names)
 else:
  ignored_names = set()
 os.makedirs(dst)
 errors = []
 for name in names:
  if (name in ignored_names):
   continue
  srcname = os.path.join(src, name)
  dstname = os.path.join(dst, name)
  try:
   if os.path.islink(srcname):
    linkto = os.readlink(srcname)
    if symlinks:
     os.symlink(linkto, dstname)
    else:
     if ((not os.path.exists(linkto)) and ignore_dangling_symlinks):
      continue
     copy_function(srcname, dstname)
   elif os.path.isdir(srcname):
    copytree(srcname, dstname, symlinks, ignore, copy_function)
   else:
    copy_function(srcname, dstname)
  except Error as err:
   errors.extend(err.args[0])
  except EnvironmentError as why:
   errors.append((srcname, dstname, str(why)))
 try:
  copystat(src, dst)
 except OSError as why:
  if ((WindowsError is not None) and isinstance(why, WindowsError)):
   pass
  else:
   errors.extend((src, dst, str(why)))
 if errors:
  raise Error(errors)

def copytree ( src , dst , symlinks = False , ignore = None , copy_function = copy2 , ignore_dangling_symlinks = False ) : names = os . listdir ( src ) if ( ignore is not None ) : ignored_names = ignore ( src , names ) else : ignored_names = set ( ) os . makedirs ( dst ) errors = [ ] for name in names : if ( name in ignored_names ) : continue srcname = os . path . join ( src , name ) dstname = os . path . join ( dst , name ) try : if os . path . islink ( srcname ) : linkto = os . readlink ( srcname ) if symlinks : os . symlink ( linkto , dstname ) else : if ( ( not os . path . exists ( linkto ) ) and ignore_dangling_symlinks ) : continue copy_function ( srcname , dstname ) elif os . path . isdir ( srcname ) : copytree ( srcname , dstname , symlinks , ignore , copy_function ) else : copy_function ( srcname , dstname ) except Error as err : errors . extend ( err . args [ 0 ] ) except EnvironmentError as why : errors . append ( ( srcname , dstname , str ( why ) ) ) try : copystat ( src , dst ) except OSError as why : if ( ( WindowsError is not None ) and isinstance ( why , WindowsError ) ) : pass else : errors . extend ( ( src , dst , str ( why ) ) ) if errors : raise Error ( errors )
copy a complete file tree to a new destination .