def merge_trees(src, dest):
 if (not os.path.exists(src)):
  return
 elif (not os.path.exists(dest)):
  if os.path.isfile(src):
   shutil.copy2(src, dest)
  else:
   shutil.copytree(src, dest, symlinks=True)
  return
 elif (os.path.isfile(src) and os.path.isfile(dest)):
  destfile = open(dest, 'a')
  try:
   srcfile = open(src)
   try:
    destfile.write(srcfile.read())
   finally:
    srcfile.close()
  finally:
   destfile.close()
 elif (os.path.isdir(src) and os.path.isdir(dest)):
  for name in os.listdir(src):
   merge_trees(os.path.join(src, name), os.path.join(dest, name))
 else:
  return

def merge_trees ( src , dest ) : if ( not os . path . exists ( src ) ) : return elif ( not os . path . exists ( dest ) ) : if os . path . isfile ( src ) : shutil . copy2 ( src , dest ) else : shutil . copytree ( src , dest , symlinks = True ) return elif ( os . path . isfile ( src ) and os . path . isfile ( dest ) ) : destfile = open ( dest , 'a' ) try : srcfile = open ( src ) try : destfile . write ( srcfile . read ( ) ) finally : srcfile . close ( ) finally : destfile . close ( ) elif ( os . path . isdir ( src ) and os . path . isdir ( dest ) ) : for name in os . listdir ( src ) : merge_trees ( os . path . join ( src , name ) , os . path . join ( dest , name ) ) else : return
merges a source directory tree at src into a destination tree at dest .