
    -Ph!                     <    d Z ddlZddlmZ dZdZd	dZdd
Zd ZdS )z!Utilities for downloadable items.    N   )	zip_filesz
.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-gallery

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download all examples {0} source code: {1} </{2}>`
z
    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download all examples in Jupyter notebooks: {0} </{1}>`
.pyc                    t           j                            t           j                            |                    }|dk    r|dz  }n|dk    r|dz  }t           j                            ||dz             }t          | |||          S )a  Store all files in file_list into an zip file.

    Parameters
    ----------
    file_list : list
        Holds all the file names to be included in zip file
    gallery_path : str
        path to where the zipfile is stored
    extension : str | None
        In order to deal with downloads of plain source files and jupyter notebooks, if
        this value is not None, the file extension from files in file_list will be
        removed and replace with the value of this variable while generating the zip
        file

    Returns
    -------
    zipname : str
        zip file name, written as `target_dir_python.zip`, `target_dir_jupyter.zip`,
        or `target_dir.zip` depending on the extension
    r   _python.ipynb_jupyterz.zip)ospathbasenamenormpathjoinr   )	file_listgallery_path	extensionzipnames       X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/downloads.py
python_zipr      s    * grw//==>>GE9	h		:gll<6)9::GYyAAA    r   c                 H      fdt          j                   D             S )aq  Return a list of source files in target_dir.

    Parameters
    ----------
    target_dir : str
        path to the directory where source file are
    extensions : tuple[str]
        tuple of file extensions to include

    Returns
    -------
    list
        list of paths to all source files in `target_dir` ending with one of the
        specified extensions
    c                 z    g | ]7}|                               t          j                            |          8S  )endswithr
   r   r   ).0fname
extensions
target_dirs     r   
<listcomp>z-list_downloadable_sources.<locals>.<listcomp>I   sK       >>*%%
Z''  r   )r
   listdir)r   r   s   ``r   list_downloadable_sourcesr!   9   s>         Z
++   r   c                    t          |d                   }t          |d                   }t          | |          }t          | |          }t          t          j        |                     D ]}t          j                            t          j                            | |                    rft          j                            | |          }|                    t          ||                     |                    t          ||                     fd}	t          d |D                       }
t          || |
rdnd          }t                              |
rdndt          j                            |           |	|                    }|rUt          || d	          }|t                              t          j                            |           |	|                    z  }|S )
a  Collects downloadable sources and makes zipfiles of them.

    Collects all source files and Jupyter notebooks in gallery_dir.

    Parameters
    ----------
    gallery_dir : str
        path of the gallery to collect downloadable sources
    src_dir : str
        The build source directory. Needed to make the reST paths relative.
    gallery_conf : dict[str, Any]
        Sphinx-Gallery configuration dictionary

    Return
    ------
    download_rst: str
        RestructuredText to include download buttons to the generated files
    example_extensionsnotebook_extensionsc                     t           j                            | t           j                                                } |                     t           j        d          S )N/)r
   r   relpathr   replacesep)filepathsrc_dirs    r   rst_pathz#generate_zipfiles.<locals>.rst_pathm   s@    7??8RW-=-=g-F-FGG,,,r   c              3   @   K   | ]}|                     d           V  dS )r   N)r   )r   fs     r   	<genexpr>z$generate_zipfiles.<locals>.<genexpr>q   s.      ==1QZZ&&======r   r   Nz	in Pythonasr   )tupler!   sortedr
   r    r   isdirr   extendallr   CODE_ZIP_DOWNLOADformatr   NOTEBOOK_ZIP_DOWNLOAD)gallery_dirr+   gallery_confsrc_extnotebook_extsource_filesnotebook_files	directoryr   r,   
all_python
py_zipfiledw_rst
jy_zipfiles    `            r   generate_zipfilesrD   P   s   & L!5677G&;<==L,['BBL.{LIINBJ{3344 W W	7==k9==>> 	Wk9==J 9*g N NOOO!!";J"U"UVVV- - - - - =======JL+
7TuuPTUUJ%%!+t
$$ F  
XFF
'..GZ((HZ  
 
 	

 Mr   )r   )	__doc__r
   utilsr   r6   r8   r   r!   rD   r   r   r   <module>rG      s}    ( (
 
			        B B B B<   .0 0 0 0 0r   