o
    eJ                     @   sT   d 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 Z	G dd de
ZdS )zCLoader for event file data for an entire TensorBoard log directory.    N)directory_watcher)
io_wrapper)
tb_loggingc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )LogdirLoadera  Loader for a root log directory, maintaining multiple DirectoryLoaders.

    This class takes a root log directory and a factory for DirectoryLoaders, and
    maintains one DirectoryLoader per "logdir subdirectory" of the root logdir.

    Note that this class is not thread-safe.
    c                 C   s6   |du rt d|du rt d|| _|| _i | _dS )aZ  Constructs a new LogdirLoader.

        Args:
          logdir: The root log directory to load from.
          directory_loader_factory: A factory for creating DirectoryLoaders. The
            factory should take a path and return a DirectoryLoader.

        Raises:
          ValueError: If logdir or directory_loader_factory are None.
        NzA logdir is requiredz&A directory loader factory is required)
ValueError_logdir_directory_loader_factory_directory_loaders)selfZlogdirZdirectory_loader_factory r   RD:\Projects\ConvertPro\env\Lib\site-packages\tensorboard/uploader/logdir_loader.py__init__&   s   
zLogdirLoader.__init__c                 C   s   t d| j t }t| jD ]"}tj|| j}|	| || j
vr2t d| | || j
|< qt| j
| }|rK|D ]}t d| | j
|= q>t d| j dS )zFinds new runs within `logdir` and makes `DirectoryLoaders` for
        them.

        In addition, any existing `DirectoryLoader` whose run directory
        no longer exists will be deleted.
        zStarting logdir traversal of %sz&- Adding run for relative directory %sz(- Removing run for relative directory %szEnding logdir traversal of %sN)loggerinfor   setr   ZGetLogdirSubdirectoriesospathrelpathaddr	   r   )r
   Z	runs_seensubdirrunZ
stale_runsr   r   r   synchronize_runs:   s"   



zLogdirLoader.synchronize_runsc                 C   sP   t | j}tdt| t }t|D ]}| j| }| |	 ||< q|S )a  Returns tf.Event generators for each run's `DirectoryLoader`.

        Warning: the generators are stateful and consuming them will affect the
        results of any other existing generators for that run; calling code should
        ensure it takes events from only a single generator per run at a time.

        Returns:
          Dictionary containing an entry for each run, mapping the run name to a
          generator yielding tf.Event protobuf objects loaded from that run.
        z-Creating event loading generators for %d runs)
listr	   r   r   lencollectionsOrderedDictsorted_wrap_loader_generatorLoad)r
   runsZrun_to_loaderrun_nameloaderr   r   r   get_run_eventsR   s   

zLogdirLoader.get_run_eventsc                 c   s0    z|D ]}|V  qW dS  t jy   Y dS w )zMWraps `DirectoryLoader` generator to swallow
        `DirectoryDeletedError`.N)r   ZDirectoryDeletedError)r
   Zloader_generatoritemr   r   r   r   e   s   z#LogdirLoader._wrap_loader_generatorN)__name__
__module____qualname____doc__r   r   r"   r   r   r   r   r   r      s    r   )r'   r   r   Z$tensorboard.backend.event_processingr   r   Ztensorboard.utilr   Z
get_loggerr   objectr   r   r   r   r   <module>   s   