ó
U¾÷Xc           @` sm  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l 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 d d	 l m Z d d
 l m Z d d l m Z d d l m Z i d e j 6d e j 6d e j 6d e j 6d e j 6Z d „  Z  d „  Z! d „  Z" d e j# e j$ f d „  ƒ  YZ% d „  Z& d S(   sv   Module for building TensorBoard servers.

This is its own module so it can be used in both actual code and test code.
i    (   t   absolute_import(   t   division(   t   print_functionN(   t   BaseHTTPServer(   t   socketserver(   t
   tf_logging(   t   event_accumulator(   t
   io_wrapper(   t   handler(   t   pluginiô  i   iè  i2   c         C` sÏ   i  } |  d k r | St j d ƒ } x£ |  j d ƒ D]’ } | j | ƒ d k r‡ d | k r‡ | d d k r‡ | j d ƒ \ } } } n d } | } | j | ƒ d k r½ t j j | ƒ } n  | | | <q5 W| S(   s  Parses `logdir` into a map from paths to run group names.

  The events files flag format is a comma-separated list of path specifications.
  A path specification either looks like 'group_name:/path/to/directory' or
  '/path/to/directory'; in the latter case, the group is unnamed. Group names
  cannot start with a forward slash: /foo:bar/baz will be interpreted as a
  spec with no name and path '/foo:bar/baz'.

  Globs are not supported.

  Args:
    logdir: A comma-separated list of run specifications.
  Returns:
    A dict mapping directory paths to names like {'/path/to/directory': 'name'}.
    Groups without an explicit name are named after their path. If logdir is
    None, returns an empty dict, which is helpful for testing things that don't
    require any valid runs.
  s   [a-zA-Z][0-9a-zA-Z.]*://.*t   ,t   :i    t   /N(	   t   Nonet   ret   compilet   splitt   matcht	   partitiont   ost   patht   realpath(   t   logdirt   filest   uri_patternt   specificationt   run_namet   _R   (    (    sg   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/tensorboard/backend/server.pyt   ParseEventFilesSpec2   s    c         C` s„   t  j  ƒ  } t j d ƒ x- t j | ƒ D] \ } } |  j | | ƒ q) Wt j d ƒ |  j ƒ  t  j  ƒ  | } t j d | ƒ d S(   sÿ   Loads all runs into the multiplexer.

  Args:
    multiplexer: The `EventMultiplexer` to add runs to and reload.
    path_to_run: A dict mapping from paths to run names, where `None` as the run
      name is interpreted as a run name equal to the path.
  s$   TensorBoard reload process beginnings8   TensorBoard reload process: Reload the whole Multiplexers0   TensorBoard done reloading. Load took %0.3f secsN(   t   timet   loggingt   infot   sixt	   iteritemst   AddRunsFromDirectoryt   Reload(   t   multiplexert   path_to_runt   startR   t   namet   duration(    (    sg   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/tensorboard/backend/server.pyt   ReloadMultiplexer[   s    
c         ` s>   ‡  ‡ ‡ f d †  } t  j d | ƒ } t | _ | j ƒ  | S(   sD  Starts a thread to automatically reload the given multiplexer.

  The thread will reload the multiplexer by calling `ReloadMultiplexer` every
  `load_interval` seconds, starting immediately.

  Args:
    multiplexer: The `EventMultiplexer` to add runs to and reload.
    path_to_run: A dict mapping from paths to run names, where `None` as the run
      name is interpreted as a run name equal to the path.
    load_interval: How many seconds to wait after one load before starting the
      next load.

  Returns:
    A started `threading.Thread` that reloads the multiplexer.
  c           ` s+   x$ t  r& t ˆ ˆ ƒ t j ˆ  ƒ q Wd  S(   N(   t   TrueR)   R   t   sleep(    (   t   load_intervalR$   R%   (    sg   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/tensorboard/backend/server.pyt   _ReloadForever   s    	t   target(   t	   threadingt   ThreadR*   t   daemonR&   (   R$   R%   R,   R-   t   thread(    (   R,   R$   R%   sg   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/tensorboard/backend/server.pyt   StartMultiplexerReloadingThreadm   s
    	
t   ThreadedHTTPServerc           B` s   e  Z d  Z e Z RS(   s   A threaded HTTP server.(   t   __name__t
   __module__t   __doc__R*   t   daemon_threads(    (    (    sg   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/tensorboard/backend/server.pyR4   Š   s   c         C` sA   i t  j ƒ  d 6} t j t j |  | | ƒ } t | | f | ƒ S(   sw  Sets up an HTTP server for running TensorBoard.

  Args:
    multiplexer: An `EventMultiplexer` that the server will query for
      information about events.
    host: The host name.
    port: The port number to bind to, or 0 to pick one automatically.
    logdir: The logdir argument string that tensorboard started up with.
  Returns:
    A `BaseHTTPServer.HTTPServer`.
  t	   projector(   t   projector_plugint   ProjectorPlugint	   functoolst   partialR   t   TensorboardHandlerR4   (   R$   t   hostt   portR   t   names_to_pluginst   factory(    (    sg   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/tensorboard/backend/server.pyt   BuildServer   s    ('   R7   t
   __future__R    R   R   R<   R   R/   R   R   R    t	   six.movesR   R   t   tensorflow.python.platformR   R   t   tensorflow.python.summaryR   t   tensorflow.python.summary.implR   t   tensorflow.tensorboard.backendR   t(   tensorflow.tensorboard.plugins.projectorR	   R:   t   COMPRESSED_HISTOGRAMSt   IMAGESt   AUDIOt   SCALARSt
   HISTOGRAMSt   TENSORBOARD_SIZE_GUIDANCER   R)   R3   t   ThreadingMixInt
   HTTPServerR4   RC   (    (    (    sg   /tmp/pip-build-h1VYrz/tensorflow/tensorflow-1.0.1.data/purelib/tensorflow/tensorboard/backend/server.pyt   <module>   s8   



	)			