<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _AddParentDirectories(self, path):
 """Adds the parent directories of a path to the fake file system. Args: path (str):
 path of the file within the fake file system. Raises: ValueError: if a parent directory is already set and is not a directory. """

    path_segments = self.file_system.SplitPath(path)
    for segment_index in range(len(path_segments)):
      parent_path = self.file_system.JoinPath(path_segments[:segment_index])
      file_entry = self.file_system.GetFileEntryByPath(parent_path)
      if file_entry and not file_entry.IsDirectory():
        raise ValueError(
            'Non-directory parent file entry: {0:s} already exists.'.format(
                parent_path))

    for segment_index in range(len(path_segments)):
      parent_path = self.file_system.JoinPath(path_segments[:segment_index])
      if not self.file_system.FileEntryExistsByPath(parent_path):
        self.file_system.AddFileEntry(
            parent_path, file_entry_type=definitions.FILE_ENTRY_TYPE_DIRECTORY)