o
    1ôjy  ã                   @   s®   d dl Z d dlZd dlmZ d dlmZmZmZ dd„ Zdd„ Z	de
fd	d
„Zde
fdd„Zde
fdd„Zde
de
fdd„Zde
de
fdd„Zdd„ Zddeddfdd„ZdS )é    N)ÚPath)ÚErrorÚcopy2Úcopystatc                 C   sx   t  | ¡}|j}|j}|du r|du sdS |jsg n|j}|r*|d dv r*| d¡n| t|ƒdkr:|d dv r:dS dS )zëto decide if a func could recieve dict inputs or not

    Args:
        func (class): the target function to be inspected

    Returns:
        bool: if func only has one arg ``input`` or ``inputs``, return True, else return False
    NFr   )ÚselfÚclsé   )ÚinputÚinputsT)ÚinspectÚgetfullargspecÚvarargsÚvarkwÚargsÚpopÚlen)ÚfuncZfull_args_specr   r   r   © r   ún/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/modelscope/utils/file_utils.pyÚfunc_receive_dict_inputs
   s   
	€r   c                  C   s   t  ¡  dd¡} | S )z1
    default base dir: '~/.cache/modelscope'
    z.cacheÚ
modelscope)r   ÚhomeÚjoinpath)Zdefault_cache_dirr   r   r   Ú get_default_modelscope_cache_dir"   s   r   Úreturnc                   C   s   t  dtƒ ¡S )z�Get modelscope cache dir, default location or
       setting with MODELSCOPE_CACHE

    Returns:
        str: the modelscope cache root.
    ÚMODELSCOPE_CACHE)ÚosÚgetenvr   r   r   r   r   Úget_modelscope_cache_dir*   s   r   c                   C   ó   t j tƒ d¡S )z[Get model cache root path.

    Returns:
        str: the modelscope model cache root.
    Úhub©r   ÚpathÚjoinr   r   r   r   r   Úget_model_cache_root4   ó   r$   c                   C   r   )zqGet dataset raw file cache root path.

    Returns:
        str: the modelscope dataset raw file cache root.
    Údatasetsr!   r   r   r   r   Úget_dataset_cache_root=   r%   r'   Ú
dataset_idc                 C   ó$   t ƒ }| du r	|S tj || d ¡S )z·Get the dataset_id's path.
       dataset_cache_root/dataset_id.

    Args:
        dataset_id (str): The dataset id.

    Returns:
        str: The dataset_id's cache root path.
    Nú/)r'   r   r"   r#   )r(   Zdataset_rootr   r   r   Úget_dataset_cache_dirF   ó   
ÿr+   Úmodel_idc                 C   r)   )zýcache dir precedence:
        function parameter > environment > ~/.cache/modelscope/hub/model_id

    Args:
        model_id (str, optional): The model id.

    Returns:
        str: the model_id dir if model_id not None, otherwise cache root dir.
    Nr*   )r$   r   r"   r#   )r-   Z	root_pathr   r   r   Úget_model_cache_dirU   r,   r.   c                 C   s8   t | dƒ�}| ¡ }W d   ƒ |S 1 sw   Y  |S )NÚr)ÚopenÚread)r"   ÚfÚtextr   r   r   Ú	read_filed   s   

ÿþr4   Fc                 C   sâ  t  | ¡}|dur|| |ƒ}ntƒ }t j||d� g }	|D ]Ÿ}
|
|v r$qt j | |
¡}t j ||
¡}zUt j |¡rpt  |¡}|rOt  ||¡ t	||| d� n7t j 
|¡sY|rYW qt j |¡rjt||||||d� n|||ƒ nt j |¡r�t||||||d� n|||ƒ W q ty¡ } z|	 |jd ¡ W Y d}~qd}~w ty¼ } z|	 ||t|ƒf¡ W Y d}~qd}~ww zt	| |ƒ W n$ tyè } zt|ddƒdu rÞ|	 | |t|ƒf¡ W Y d}~nd}~ww |	rït|	ƒ‚|S )z7copy from py37 shutil. add the parameter dirs_exist_ok.N)Úexist_ok)Úfollow_symlinks)Údirs_exist_okr   Úwinerror)r   ÚlistdirÚsetÚmakedirsr"   r#   ÚislinkÚreadlinkÚsymlinkr   ÚexistsÚisdirÚcopytree_py37r   Úextendr   ÚOSErrorÚappendÚstrÚgetattr)ÚsrcÚdstÚsymlinksÚignoreÚcopy_functionÚignore_dangling_symlinksr7   ÚnamesÚignored_namesÚerrorsÚnameÚsrcnameÚdstnameÚlinktoÚerrÚwhyr   r   r   rA   k   sr   

úú
	€€ €ÿ€ýrA   )r   r   Úpathlibr   Úshutilr   r   r   r   r   rE   r   r$   r'   r+   r.   r4   rA   r   r   r   r   Ú<module>   s$   
			ú