
    1Vh                         d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ  ej                         Z
 ej                  d      Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zy)zIO helper functions.    N)tf)io_util)
tb_loggingz([*?[])c                 P    t        j                  |       rdS t        j                  S )N/)r   IsCloudPathosseppaths    _/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/backend/event_processing/io_wrapper.pyPathSeparatorr       s    %%d+377    c                     | st        d      dt        j                  j                  t        j
                  j                  |             v S )a  Check the path name to see if it is probably a TF Events file.

    Args:
      path: A file path to check if it is an event file.

    Raises:
      ValueError: If the path is an empty string.

    Returns:
      If path is formatted like a TensorFlowEventsFile. Dummy files such as
        those created with the '.profile-empty' suffixes and meant to hold
        no `Summary` protos are treated as true TensorFlowEventsFiles. For
        background, see: https://github.com/tensorflow/tensorboard/issues/2084.
    zPath must be a nonempty stringtfevents)
ValueErrorr   compat
as_str_anyr	   r   basenamer   s    r   IsTensorFlowEventsFiler   $   s<     9::--bgg.>.>t.DEEEr   c                 @    t        |       xr | j                  d       S )a  Check whether the path is probably a TF Events file containing Summary.

    Args:
      path: A file path to check if it is an event file containing `Summary`
        protos.

    Returns:
      If path is formatted like a TensorFlowEventsFile. Dummy files such as
        those created with the '.profile-empty' suffixes and meant to hold
        no `Summary` protos  are treated as `False`. For background, see:
        https://github.com/tensorflow/tensorboard/issues/2084.
    z.profile-empty)r   endswithr   s    r   IsSummaryEventsFiler   8   s!     "$'O>N0O,OOr   c                 h      fdt         j                  j                  j                         D        S )zJYields all files in the given directory.

    The paths are absolute.
    c              3   ^   K   | ]$  }t         j                  j                  |       & y wNr	   r   join).0r   	directorys     r   	<genexpr>z(ListDirectoryAbsolute.<locals>.<genexpr>M   s%      *.Y%   *-)r   iogfilelistdir)r    s   `r   ListDirectoryAbsoluter&   H   s(    
24%%++2E2Ei2P r   c                 z    t         j                  j                  |       \  }} |t        j	                  d|       S )zEscapes the glob characters in a path.

    Python 3 has a glob.escape method, but python 2 lacks it, so we manually
    implement this method.

    Args:
      path: The absolute path to escape.

    Returns:
      The escaped path string.
    z[\1])r	   r   
splitdrive_ESCAPE_GLOB_CHARACTERS_REGEXsub)r   drives     r   _EscapeGlobCharactersr,   R   s5     ''$$T*KE49==gtLMMr   c              #     K   t         j                  j                  t        |       d      }d}	 t        j                  d|       t        j                  j                  j                  |      }t        j                  dt        |      |       |syt        j                  t              }|D ]3  }|t         j                  j                  |         j                  |       5 |j!                         D ]  \  }}|t#        |      f  t        |      dk(  r:t         j                  j                  t        |j%                               d   d      }t         j                  j                  |d      }|dz  }Iw)a  Recursively lists all files within the directory.

    This method does not list subdirectories (in addition to regular files), and
    the file paths are all absolute. If the directory does not exist, this yields
    nothing.

    This method does so by glob-ing deeper and deeper directories, ie
    foo/*, foo/*/*, foo/*/*/* and so on until all files are listed. All file
    paths are absolute, and this method lists subdirectories too.

    For certain file systems, globbing via this method may prove significantly
    faster than recursively walking a directory. Specifically, TF file systems
    that implement TensorFlow's FileSystem.GetMatchingPaths method could save
    costly disk reads by using this method. However, for other file systems, this
    method might prove slower because the file system performs a walk per call to
    glob (in which case it might as well just perform 1 walk).

    Args:
      top: A path to a directory.

    Yields:
      A (dir_path, file_paths) tuple for each directory/subdirectory.
    *r   z+GlobAndListFiles: Starting to glob level %dz.GlobAndListFiles: %d files glob-ed at level %dN   )r	   r   r   r,   loggerinfor   r#   r$   globlencollectionsdefaultdictlistdirnameappenditemstuplekeys)topcurrent_glob_stringlevelr2   pairs	file_pathdir_name
file_pathss           r   ListRecursivelyViaGlobbingrC   b   s9    0 '',,'<S'A3GE
A5Iuu{{ 34<c$i	
  ''- 	@I"''//),-44Y?	@$)KKM 	0 HjU:.//	0 u:?
 #%'',,tEJJL/A!/Dc"J !ggll+>D
7 s   E6E8c              #      K   t         j                  j                  j                  | d      D ]  \  }}fd|D        f  yw)af  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()/tf.io.gfile.walk()/ListRecursivelyViaGlobbing, this does not
    list subdirectories. The file paths are all absolute. If the directory does
    not exist, this yields nothing.

    Walking may be incredibly slow on certain file systems.

    Args:
      top: A path to a directory.

    Yields:
      A (dir_path, file_paths) tuple for each directory/subdirectory.
    T)topdownc              3   ^   K   | ]$  }t         j                  j                  |       & y wr   r   )r   filenamedir_paths     r   r!   z,ListRecursivelyViaWalking.<locals>.<genexpr>   s      H(RWW\\(H-Hr"   N)r   r#   r$   walk)r<   _	filenamesrH   s      @r   ListRecursivelyViaWalkingrL      sL     " #%%%++"2"23"2"E 
!YHiH
 	

s   AAc                 z   t         j                  j                  j                  |       syt         j                  j                  j	                  |       st        d| z        t        j                  |       rt        j                  d       t        }nt        j                  d       t        }d  ||       D        S )a  Obtains all subdirectories with events files.

    The order of the subdirectories returned is unspecified. The internal logic
    that determines order varies by scenario.

    Args:
      path: The path to a directory under which to find subdirectories.

    Returns:
      A tuple of absolute paths of all subdirectories each with at least 1 events
      file directly within the subdirectory.

    Raises:
      ValueError: If the path passed to the method exists and is not a directory.
     z?GetLogdirSubdirectories: path exists and is not a directory, %szCGetLogdirSubdirectories: Starting to list directories via glob-ing.zBGetLogdirSubdirectories: Starting to list directories via walking.c              3   J   K   | ]  \  }}t        d  |D              r|  yw)c              3   2   K   | ]  }t        |        y wr   )r   )r   fs     r   r!   z4GetLogdirSubdirectories.<locals>.<genexpr>.<genexpr>   s     8Q%a(8s   N)any)r   subdirfiless      r   r!   z*GetLogdirSubdirectories.<locals>.<genexpr>   s*      VU8%88 	s   !#)r   r#   r$   existsisdirr   r   r   r0   r1   rC   rL   )r   traversal_methods     r   GetLogdirSubdirectoriesrX      s      55;;d#55;;T""#
 	

 4  	Q	
 6 	P	
 5/5 r   )__doc__r4   r	   retensorboard.compatr   tensorboard.utilr   r   
get_loggerr0   compiler)   r   r   r   r&   r,   rC   rL   rX   rN   r   r   <module>r_      sm      	 	 " $ ' 
			  *

9 5 8F(P N 6r
0-r   