ó
¬X[c           @   sº   d  Z  d d l m Z d d l Z d d l m Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d	 l m Z m Z m Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d Z d S(   s-   Tornado handlers for frontend config storage.iÿÿÿÿ(   t   ThreadPoolExecutorN(   t   Event(   t
   APIHandler(   t   gent   web(   t   run_on_executori   (   t   buildt   cleant   build_checkt   Builderc           B   s’   e  Z e Z e d  d ƒ Z e Z e Z d Z	 d Z
 d „  Z e j d „  ƒ Z e j d „  ƒ Z e j d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(	   t   max_workersi   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   logt	   core_modet   app_dir(   t   selfR   R   R   (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyt   __init__   s    		c         c   s,  |  j  r* t j t d d d d ƒ ƒ ‚ n  |  j rT t j t d d d d ƒ ƒ ‚ n  y{ |  j |  j |  j ƒ V} | r| d n d } | r¾ |  j j d ƒ g  | D] } |  j j | ƒ ^ qŸ n |  j j	 d ƒ Wn/ t
 k
 r } |  j j d	 ƒ d } g  } n Xt j t d | d d
 j | ƒ ƒ ƒ ‚ d  S(   Nt   statust   stablet   messaget    t   buildingt   neededs   Build recommendeds   Build is up to dates:   Could not determine jupyterlab build status without nodejss   
(   R   R   t   Returnt   dictR   t   _run_build_checkR   R   t   warnt   infot
   ValueErrort   join(   R   t   messagesR   t   mt   e(    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyt
   get_status   s"    	!	!&	
c         c   s  |  j  r t d ƒ ‚ n  |  j sÚ t |  _ t j ƒ  |  _ } t |  _ t	 ƒ  |  _
 } zt y+ |  j |  j |  j | ƒ V| j t ƒ WnB t k
 rÈ } t | ƒ d k r¸ | j t ƒ qÉ | j | ƒ n XWd  t |  _ Xn  y |  j VWn t k
 r} | ‚ n Xd  S(   Ns   Cancel in progresst   Aborted(   t
   _cancelingR   R   t   Falset   canceledR   t   Futuret   _futuret   TrueR   t   _kill_eventt
   _run_buildR   R   t
   set_resultt	   Exceptiont   strt   set_exception(   R   t   futuret   evtR   (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyR   5   s(    				 c         c   s?   |  j  s t d ƒ ‚ n  t |  _ |  j Vt |  _ t |  _ d  S(   Ns   No current build(   R   R   R'   R"   R&   R#   R$   (   R   (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyt   cancelM   s    			c         C   s   t  d | d | ƒ S(   NR   t   logger(   R   (   R   R   R1   (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyR   V   s    c         C   sw   t  d | d | d | ƒ } y t |   SWnG t k
 rr } |  j j ƒ  rN d  S|  j j d ƒ t | ƒ t |   SXd  S(   NR   R1   t
   kill_events)   Build failed, running a clean and rebuild(   R   R   R+   R(   t   is_setR   R   R   (   R   R   R1   R2   t   kwargsR   (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyR)   Z   s    
N(   t   __name__t
   __module__R#   R   R    t   executorR$   R"   t   NoneR(   R&   R   R   t	   coroutineR    R   R0   R   R   R)   (    (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyR	      s   		t   BuildHandlerc           B   sb   e  Z d  „  Z e j e j d „  ƒ ƒ Z e j e j d „  ƒ ƒ Z e j e j d „  ƒ ƒ Z	 RS(   c         C   s   | |  _  d  S(   N(   t   builder(   R   R;   (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyt
   initializei   s    c         c   s*   |  j  j ƒ  V} |  j t j | ƒ ƒ d  S(   N(   R;   R    t   finisht   jsont   dumps(   R   t   data(    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyt   getl   s    c         c   sa   |  j  j d ƒ y |  j j ƒ  VWn+ t k
 rO } t j d t | ƒ ƒ ‚ n X|  j d ƒ d  S(   Ns   Canceling buildiô  iÌ   (	   R   R   R;   R0   R+   R   t	   HTTPErrorR,   t
   set_status(   R   R   (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyt   deleter   s    c         c   s’   |  j  j d ƒ y |  j j ƒ  VWn+ t k
 rO } t j d t | ƒ ƒ ‚ n X|  j j rq t j d d ƒ ‚ n  |  j  j d ƒ |  j	 d ƒ d  S(   Ns   Starting buildiô  i  s   Build canceleds   Build succeedediÈ   (
   R   t   debugR;   R   R+   R   RB   R,   R$   RC   (   R   R   (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyt   post|   s    (
   R5   R6   R<   R   t   authenticatedR   R9   RA   RD   RF   (    (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyR:   g   s   		s   /lab/api/build(   t   __doc__t   concurrent.futuresR    R>   t	   threadingR   t   notebook.base.handlersR   t   tornadoR   R   t   tornado.concurrentR   t   commandsR   R   R   t   objectR	   R:   t
   build_path(    (    (    s7   lib/python2.7/site-packages/jupyterlab/build_handler.pyt   <module>   s   W&