o
    ॵiy                     @   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 )zto 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)funcfull_args_specr   r   r    r   O/home/ubuntu/.local/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)default_cache_dirr   r   r    get_default_modelscope_cache_dir"   s   r   returnc                   C   s   t dt S )zGet 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 )zGet 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*   dataset_rootr   r   r   get_dataset_cache_dirF      
r.   model_idc                 C   r+   )zcache 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%   )r0   	root_pathr   r   r   get_model_cache_dirU   r/   r2   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   

r8   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|rt||||||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 |	rt|	|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_symlinksr;   namesignored_nameserrorsnamesrcnamedstnamelinktoerrwhyr   r   r   rE   k   sr   


	 rE   )r   r   pathlibr   shutilr   r   r   r   r   rI   r    r&   r)   r.   r2   r8   rE   r   r   r   r   <module>   s$   
			