
    Fh                     j    S r SSKrSSKrSSKrSSKJr  SSKJrJr  SSK	J
r
  SSKJr   " S S	\5      rg)
z;Contains writer for writing nbconvert output to filesystem.    N)Path)Unicodeobserve)link_or_copy   )
WriterBasec                      ^  \ rS rSrSr\" SSS9R                  SS9r\" SS9R                  SS9r\	" S	5      S
 5       r
U 4S jrSS jrS rSS jrSrU =r$ )FilesWriter   z-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                 @    US   nU(       a  U R                  U5        g g )Nnew)_makedir)selfchanger   s      jC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\nbconvert/writers/files.py_build_directory_changed$FilesWriter._build_directory_changed&   s    UmMM#     c                 `   > [         TU ]  " S0 UD6  U R                  SU R                  05        g)zInitialize the writer.r   N )super__init__r   r   )r   kw	__class__s     r   r   FilesWriter.__init__,   s,    2%%ud.B.B&CDr   c                    [         R                  R                  U5      (       d2  U R                  R	                  SU5         [         R
                  " XS9  g[         R                  R                  U5      (       d  [        SU-  5      eg! [         a)  nUR                  [        R                  :w  a  e  SnAgSnAff = f)zensure that a directory exists

If it doesn't exist, try to create it and protect against a race condition
if another process is doing the same.

The default permissions are 755, which differ from os.makedirs default of 777.
zMaking directory %s)modeNz %r exists but is not a directory)
ospathexistsloginfomakedirsOSErrorerrnoEEXISTisdir)r   r#   r!   es       r   r   FilesWriter._makedir1   s     ww~~d##HHMM/6D, t$$<tCDD %  77ell* +s   B
 

B=B88B=c                 t   U H  u  p4[         R                  R                  X#5      n[         R                  R                  U5      nU R	                  U5        U R
                  R                  S[        U5      U5        [        US5       nUR                  U5        SSS5        M     g! , (       d  f       M  = f)z-Write a dict containing filename->binary dataWriting %i bytes to %swbN)
r"   r#   joindirnamer   r%   debuglenopenwrite)r   items	build_dirfilenamedatadestr#   fs           r   _write_itemsFilesWriter._write_itemsC   s    #NH77<<	4D77??4(DMM$ HHNN3SYEdD!Q "! $ "!s   	B((
B7	c           	         Uc  Sn[        U5      eUR                  SS5      nUR                  S0 5      R                  SS5      nU R                  =(       d    UnU R                  =(       d    Un	UR                  S0 5      R	                  5       n
U
(       a[  U R
                  R                  S[        R                  R                  UR                  S	S5      S5      5        U R                  X5        UR                  S
0 5      R	                  5       nU(       a[  U R
                  R                  S[        R                  R                  UR                  SS5      S5      5        U R                  X5        U	(       Ga  U R                   GH  n[        R                  " U5       H  nUS:w  a   [        R                  R                  X5      nOUn[        R                  R                  X5      n[        R                  R                  U5      nU R                  U5        [        R                  R                  U5      [        R                  R                  U5      :w  d  M  U R
                  R                  SX5        [!        X5        M     GM     Ub  X6-   OUn[#        U	5      U-  nU R
                  R                  S[%        U5      U5        ['        U[(        5      (       a'  [+        USSS9 nUR-                  U5        SSS5        U$ [+        US5       nUR-                  U5        SSS5        U$ ! , (       d  f       U$ = f! , (       d  f       U$ = f)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_dirattachmentszAttachments will be in %sattachment_files_dirzCopying %s -> %sr/   wzutf-8)encodingr0   )	TypeErrorgetrelpathr   r7   r%   r&   r"   r#   r1   r=   filesglobr2   r   normpathr   r   r4   
isinstancestrr5   r6   )r   output	resourcesr@   r   msgrA   resource_pathrK   r   r7   rE   r9   matching_filenamedest_filenamer;   r#   	dest_pathr<   s                      r   r6   FilesWriter.writeP   s     !CC.  %==);TB "j"599&"E,,/-..?- i,224HHMM-Y]]+=rBBG e5  mmM26<<>HHMM+Y]]+A2FK k;  JJ)-8)<%"}(*8I(S(9 77<<GD77??40DMM$' ww''-1A1ABS1TT&8:KR$%6= *= '( 4D3O}/Ub)D0	 	.FYGfc""iw71 8  i&! '  87  '& s   *L.M .
L= 
Mr   )i  )N)__name__
__module____qualname____firstlineno____doc__r   tagr   rK   r   r   r   r   r=   r6   __static_attributes____classcell__)r   s   @r   r
   r
      s    7
M 
cc  3 
cc    
E
E$N Nr   r
   )r]   r)   rM   r"   pathlibr   	traitletsr   r   nbconvert.utils.ior   baser   r
   r   r   r   <module>re      s-    A
   	  & + L* Lr   