
    bx                     f    d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ  G d d	e      Zy)
z;Contains writer for writing nbconvert output to filesystem.    N)Path)Unicodeobserve)ensure_dir_existslink_or_copy   )
WriterBasec                        e Zd ZdZ edd      j                  d      Z ed      j                  d      Z ed      d	        Z	 fd
Z
d ZddZ xZS )FilesWriterz-Consumes nbconvert output and produces files. a  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.)helpT)configaU  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.build_directoryc                 *    |d   }|rt        |       y y )Nnew)r   )selfchanger   s      9/usr/lib/python3/dist-packages/nbconvert/writers/files.py_build_directory_changedz$FilesWriter._build_directory_changed%   s    Umc"     c                 ^    t        |   di | | j                  d| j                  i       y )Nr    )super__init__r   r   )r   kw	__class__s     r   r   zFilesWriter.__init__+   s,    2%%ud.B.B&CDr   c                 X    |r(| j                   j                  d|       t        |       yy)z,Make a directory if it doesn't already existzMaking directory %sN)loginfor   )r   paths     r   _makedirzFilesWriter._makedir/   s%    HHMM/6d# r   c           	         |t        d      |j                  dd      }|j                  di       j                  dd      }| j                  xs |}| j                  xs |}|j                  di       j	                         }	|	rJ| j
                  j                  dt        j                  j                  |j                  d	d      d             |	D ]  \  }
}t        j                  j                  ||
      }t        j                  j                  |      }| j                  |       | j
                  j                  d
t        |      |       t        |d      5 }|j                  |       ddd        |r| j                   D ]  }
t#        j"                  |
      D ]  }|dk7  r!t        j                  j                  ||      }n|}t        j                  j                  ||      }t        j                  j                  |      }| j                  |       t        j                  j%                  |      t        j                  j%                  |      k(  r| j
                  j                  d||       t'        ||         |||z   }n|}t)        |      |z  }| j
                  j                  dt        |      |       t+        |t,              r*t        |dd      5 }|j                  |       ddd       |S t        |d      5 }|j                  |       ddd       |S # 1 sw Y   ]xY w# 1 sw Y   |S xY w# 1 sw Y   |S xY w)z
        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...
        Nnotebook_nameoutput_extensionmetadatar    r   outputszSupport files will be in %soutput_files_dirz#Writing %i bytes to support file %swbzCopying %s -> %szWriting %i bytes to %swzutf-8)encoding)	TypeErrorgetrelpathr   itemsr   r   osr    joindirnamer!   debuglenopenwritefilesglobnormpathr   r   
isinstancestr)r   output	resourcesr#   r   r$   resource_pathr-   r   r.   filenamedatadestr    fmatching_filenamedest_filenames                    r   r5   zFilesWriter.write5   s     O,, %==);TB "j"599&"E,,/-..?- i,224HHMM-Y]]+=rBBG $ 
	NHd 77<<:D77??4(DMM$ HHNN@#d)TRdD! Q 
	  JJ > *.8)< >% "}(*8I7(S(9 77<<GD77??40DMM$' 77++D1RWW5E5EFW5XX&8:KTR$%6=!>>, ' #33D DO$t+ 	.FTBfc"dC'2  a   dD!  Q  U H    s$   L#L0L=#L-	0L:=M)N)__name__
__module____qualname____doc__r   tagr   r-   r   r   r   r!   r5   __classcell__)r   s   @r   r   r      sw    7
M 
cc  3 
cc  #  #
E$Rr   r   )rG   r7   r/   pathlibr   	traitletsr   r   nbconvert.utils.ior   r   baser	   r   r   r   r   <module>rN      s*    A
  	  & > v* vr   