def update_md_files(md_directory, file_list, snippet_list):
  """Update md files from snippets.

  Args:
    md_directory: Directory to look for md files in.
    snippet_list: Array of snippets to put into the md files.
  """
  for md_file in file_list:
    path = find_file(md_file, md_directory)
    if not path:
      print >> sys.stderr, 'WARNING: Cannot find %s, skipping.' % md_file
      continue
    new_file_handle = tempfile.NamedTemporaryFile(delete=False)
    temp_file_name = new_file_handle.name
    write_lines = True
    try:
      with open(path, 'r') as mdfile:
        for line in mdfile:
          match = MDDOXYSNIPPETSTART_RE.match(line)
          if match:
            token = match.groupdict()['token']
            new_file_handle.write(line)
            if snippet_list.has_key(token):
              write_lines = False
              for snippet_line in snippet_list[token]:
                new_file_handle.write(snippet_line)
          elif DOXYSNIPPETEND_RE.match(line):
            write_lines = True
            new_file_handle.write(line)
          elif write_lines:
            new_file_handle.write(line)
    except __HOLE__ as e:
      print >> sys.stderr, (
        'ERROR: Failed to open file %s: %s' % (md_file, e.strerror))
      os.remove(path)
      continue
    if write_lines is False:
      print >> sys.stderr, 'WARNING: Count not find end of %s.' % (token)
    new_file_handle.close()
    os.remove(path)
    shutil.move(temp_file_name, path)
dataset/ETHPy150Open google/fplutil/docs/update_code_snippets.py/update_md_files