ó
§]c           @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z m Z d d l m Z m	 Z	 d d l
 m Z d d l m Z d e f d	     YZ d S(
   s;   Contains writer for writing nbconvert output to filesystem.iÿÿÿÿN(   t   Unicodet   observe(   t   link_or_copyt   ensure_dir_exists(   t   unicode_typei   (   t
   WriterBaset   FilesWriterc           B   sz   e  Z d  Z e d d d j d e  Z e d d  j d e  Z e d  d    Z	 d   Z
 d	   Z d d
  Z RS(   s-   Consumes nbconvert output and produces files.t    t   helps  Directory to write output(s) to. Defaults
                              to output to the directory of each notebook. To recover
                              previous default behaviour (outputting to the current 
                              working directory) use . as the flag value.t   configsU  When copying files that the notebook depends on, copy them in
        relation to this path, such that the destination filename will be
        os.path.relpath(filename, relpath). If FilesWriter is operating on a
        notebook that already exists elsewhere on disk, then the default will be
        the directory containing that notebook.t   build_directoryc         C   s!   | d } | r t  |  n  d  S(   Nt   new(   R   (   t   selft   changeR   (    (    s6   lib/python2.7/site-packages/nbconvert/writers/files.pyt   _build_directory_changed%   s    
c         K   s1   t  t |   j |   |  j i |  j d 6 d  S(   NR   (   t   superR   t   __init__R   R
   (   R   t   kw(    (    s6   lib/python2.7/site-packages/nbconvert/writers/files.pyR   +   s    c         C   s*   | r& |  j  j d |  t |  n  d S(   s,   Make a directory if it doesn't already exists   Making directory %sN(   t   logt   infoR   (   R   t   path(    (    s6   lib/python2.7/site-packages/nbconvert/writers/files.pyt   _makedir/   s    c         K   sâ  | d k r t d   n  | j d d  } | j d i   j d d  } |  j pW | } |  j pf | } | j d i   j   }	 |	 rž |  j j d t j	 j
 | j d d  d   n  x |	 D] \ }
 } t j	 j
 | |
  } t j	 j |  } |  j |  |  j j d	 t |  |  t j | d
   } | j |  Wd QXq¿ W| r&xÖ |  j D]È }
 x¿ t j |
  D]® } | d k rt j	 j | |  } n | } t j	 j
 | |  } t j	 j |  } |  j |  t j	 j |  t j	 j |  k sm|  j j d | |  t | |  qmqmWqWWn  | d k	 r?| | } n | } t j	 j
 | |  } |  j j d t |  |  t | t  r¶t j | d d d  } | j |  Wd QXn( t j | d
   } | j |  Wd QX| S(   sæ   
            Consume and write Jinja output to the file system.  Output directory
            is set via the 'build_directory' variable of this instance (a 
            configurable).

            See base for more...
            t   notebook_namet   output_extensiont   metadataR   R   t   outputss   Support files will be in %st   output_files_dirs#   Writing %i bytes to support file %st   wbNs   Copying %s -> %ss   Writing %i bytes to %st   wt   encodings   utf-8(   t   Nonet	   TypeErrort   gett   relpathR
   t   itemsR   R   t   osR   t   joint   dirnameR   t   debugt   lent   iot   opent   writet   filest   globt   normpathR   t
   isinstanceR   (   R   t   outputt	   resourcesR   R   R   t   resource_pathR!   R
   R"   t   filenamet   datat   destR   t   ft   matching_filenamet   dest_filename(    (    s6   lib/python2.7/site-packages/nbconvert/writers/files.pyR*   5   sN    
1$N(   t   __name__t
   __module__t   __doc__R    t   tagt   TrueR
   R!   R   R   R   R   R   R*   (    (    (    s6   lib/python2.7/site-packages/nbconvert/writers/files.pyR      s   					(   R:   R(   R#   R,   t	   traitletsR    R   t   ipython_genutils.pathR   R   t   ipython_genutils.py3compatR   t   baseR   R   (    (    (    s6   lib/python2.7/site-packages/nbconvert/writers/files.pyt   <module>   s   