o
    wZŽh‘  ã                   @   sP   d dl mZmZ dgZG dd„ dƒZ		ddedee dd	d
d	def
dd„ZdS )é   )Ú	GlobGroupÚGlobPatternÚ	Directoryc                   @   s€   e Zd ZdZdedefdd„Zdee dd fdd	„Zd
efdd„Z	dedefdd„Z
dd„ Z		ddee dedefdd„ZdS )r   zËA file structure representation. Organized as Directory nodes that have lists of
    their Directory children. Directories for a package are created by calling
    :meth:`PackageImporter.file_structure`.ÚnameÚis_dirc                 C   s   || _ || _i | _d S )N)r   r   Úchildren)Úselfr   r   © r	   úZ/var/www/auris/lib/python3.10/site-packages/torch/package/file_structure_representation.pyÚ__init__   s   
zDirectory.__init__ÚdirsÚreturnc                 C   sJ   t |ƒdkr| S |d }|| jvrt|dƒ| j|< | j|  |dd… ¡S )a$  Builds path of Directories if not yet built and returns last directory
        in list.

        Args:
            dirs (List[str]): List of directory names that are treated like a path.

        Returns:
            :class:`Directory`: The last Directory specified in the dirs list.
        é    Tr   N)Úlenr   r   Ú_get_dir)r   r   Údir_namer	   r	   r
   r      s   

zDirectory._get_dirÚ	file_pathc                 C   s.   |  d¡^ }}|  |¡}t|dƒ|j|< dS )zÇAdds a file to a Directory.

        Args:
            file_path (str): Path of file to add. Last element is added as a file while
                other paths items are added as directories.
        ú/FN)Úsplitr   r   r   )r   r   r   ÚfileÚdirr	   r	   r
   Ú	_add_file$   s   
zDirectory._add_fileÚfilenamec                 C   s\   |j ddd}|d }t|ƒdkr|d nd}|| j ¡ v r,|du r$dS | j|  |¡S dS )zÜChecks if a file is present in a :class:`Directory`.

        Args:
            filename (str): Path of file to search for.
        Returns:
            bool: If a :class:`Directory` contains the specified file.
        r   r   )Úmaxsplitr   NTF)r   r   r   ÚkeysÚhas_file)r   r   ZlineageÚchildZgrandchildrenr	   r	   r
   r   /   s   zDirectory.has_filec                 C   s   g }|   |¡ d |¡S )NÚ )Ú_stringify_treeÚjoin)r   Ústr_listr	   r	   r
   Ú__str__A   s   

zDirectory.__str__r   õ
   â”€â”€â”€ r    ÚpreambleÚdir_ptrc                 C   s"  d}d}d}d}|  |› |› | j› d¡ ||kr|| }n|| }g }g }	| j ¡ D ]\}
}|jr8|	  |
¡ q+|  |
¡ q+tt|	ƒƒD ]'\}}
|t|	ƒd krat|ƒdkra| j|
  |||¡ qD| j|
  |||¡ qDtt|ƒƒD ]\}}|t|ƒd kr€|n|}|  |› |› |› d¡ qrdS )	zCRecursive method to generate print-friendly version of a Directory.z    u   â”‚   u
   â”œâ”€â”€ u
   â””â”€â”€ Ú
r   r   N)	Úappendr   r   Úitemsr   Ú	enumerateÚsortedr   r   )r   r    r#   r$   ÚspaceÚbranchÚteeÚlastZ	file_keysZdir_keysÚkeyÚvalÚindexr   Zpointerr	   r	   r
   r   F   s,   
þzDirectory._stringify_treeN)r   r"   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚboolr   Úlistr   r   r   r!   r   r	   r	   r	   r
   r   	   s     üþýüú**r	   r   Ú	file_listÚincluder   Úexcluder   c                 C   s:   t ||dd}t| dƒ}|D ]}| |¡r| |¡ q|S )aâ  Return a :class:`Directory` file structure representation created from a list of files.

    Args:
        filename (str): The name given to the top-level directory that will be the
            relative root for all file paths found in the file_list.

        file_list (List[str]): List of files to add to the top-level directory.

        include (Union[List[str], str]): An optional pattern that limits what is included from the file_list to
            files whose name matches the pattern.

        exclude (Union[List[str], str]): An optional pattern that excludes files whose name match the pattern.

    Returns:
            :class:`Directory`: a :class:`Directory` file structure representation created from a list of files.
    r   )r;   Ú	separatorT)r   r   Úmatchesr   )r   r9   r:   r;   Zglob_patternZtop_dirr   r	   r	   r
   Ú _create_directory_from_file_listm   s   


€r>   N)r8   r	   )Z
glob_groupr   r   Ú__all__r   r5   r7   r>   r	   r	   r	   r
   Ú<module>   s    güÿþýüû