docs: def write_contents_to_file(path, contents=None, link_to=None,
                             content_mode='text', root=None, conflicts='fail'):
      """
      Uses provided filename patterns to write contents to a new path, given
      a corresponding entity map.
  
      Args:
          path (str): Destination path of the desired contents.
          contents (str): Raw text or binary encoded string of contents to write
              to the new path.
          link_to (str): Optional path with which to create a symbolic link to.
              Used as an alternative to and takes priority over the contents
              argument.
          content_mode (str): Either 'text' or 'binary' to indicate the writing
              mode for the new file. Only relevant if contents is provided.
          root (str): Optional root directory that all patterns are relative
              to. Defaults to current working directory.
          conflicts (str): One of 'fail', 'skip', 'overwrite', or 'append'
              that defines the desired action when the output path already
              exists. 'fail' raises an exception; 'skip' does nothing;
              'overwrite' overwrites the existing file; 'append' adds  a suffix
              to each file copy, starting with 1. Default is 'fail'.
      """
  
      if root is None and not isabs(path):
          root = os.getcwd()
  
      if root:
          path = join(root, path)
  
      if exists(path) or islink(path):
          if conflicts == 'fail':
              msg = 'A file at path {} already exists.'
              raise ValueError(msg.format(path))
          elif conflicts == 'skip':
              msg = 'A file at path {} already exists, skipping writing file.'
              logging.warn(msg.format(path))
              return
          elif conflicts == 'overwrite':
              if isdir(path):
                  logging.warn('New path is a directory, not going to '
                               'overwrite it, skipping instead.')
                  return
              os.remove(path)
          elif conflicts == 'append':
              i = 1
              while i < sys.maxsize:
                  path_splits = splitext(path)
                  path_splits[0] = path_splits[0] + '_%d' % i
                  appended_filename = os.extsep.join(path_splits)
                  if not exists(appended_filename) and \
                     not islink(appended_filename):
                      path = appended_filename
                      break
                  i += 1
          else:
              raise ValueError('Did not provide a valid conflicts parameter')
  
      if not exists(dirname(path)):
          os.makedirs(dirname(path))
  
      if link_to:
          os.symlink(link_to, path)
      elif contents:
          mode = 'wb' if content_mode == 'binary' else 'w'
          with open(path, mode) as f:
              f.write(contents)
      else:
          raise ValueError('One of contents or link_to must be provided.')