def AddRunsFromDirectory(self, path, name=None):
        """Load runs from a directory; recursively walks subdirectories.

    If path doesn't exist, no-op. This ensures that it is safe to call
      `AddRunsFromDirectory` multiple times, even before the directory is made.

    If path is a directory, load event files in the directory (if any exist) and
      recursively call AddRunsFromDirectory on any subdirectories. This mean you
      can call AddRunsFromDirectory at the root of a tree of event logs and
      TensorBoard will load them all.

    If the `EventMultiplexer` is already loaded this will cause
    the newly created accumulators to `Reload()`.
    Args:
      path: A string path to a directory to load runs from.
      name: Optionally, what name to apply to the runs. If name is provided
        and the directory contains run subdirectories, the name of each subrun
        is the concatenation of the parent name and the subdirectory name. If
        name is provided and the directory contains event files, then a run
        is added called "name" and with the events from the path.

    Raises:
      ValueError: If the path exists and isn't a directory.

    Returns:
      The `EventMultiplexer`.
    """
        subdirs = []
        if gcs.IsGCSPath(path):
            subdirs = [
                subdir
                for (subdir, files) in gcs.ListRecursively(path) if list(
                    filter(event_accumulator.IsTensorFlowEventsFile, files))
            ]
        else:
            if not gfile.Exists(path):
                return  # Maybe it hasn't been created yet, fail silently to retry later
            if not gfile.IsDirectory(path):
                raise ValueError(
                    'AddRunsFromDirectory: path exists and is not a '
                    'directory, %s' % path)
            subdirs = [
                subdir for (subdir, _, files) in gfile.Walk(path) if list(
                    filter(event_accumulator.IsTensorFlowEventsFile, files))
            ]

        for subdir in subdirs:
            logging.info('Adding events from directory %s', subdir)
            rpath = os.path.relpath(subdir, path)
            subname = os.path.join(name, rpath) if name else rpath
            self.AddRun(subdir, name=subname)

        return self
def ListRecursively(top):
    """Walks a directory tree, yielding (dir_path, file_paths) tuples.

  For each of `top` and its subdirectories, yields a tuple containing the path
  to the directory and the path to each of the contained files.  Note that
  unlike os.Walk()/gfile.Walk(), this does not list subdirectories and the file
  paths are all absolute.

  If the directory does not exist, this yields nothing.

  Args:
    top: A path to a directory..
  Yields:
    A list of (dir_path, file_paths) tuples.
  """
    if gcs.IsGCSPath(top):
        for x in gcs.ListRecursively(top):
            yield x
    else:
        for dir_path, _, filenames in gfile.Walk(top):
            yield (dir_path, (os.path.join(dir_path, filename)
                              for filename in filenames))