o
    W+ i                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZmZ d dlmZ d d	lmZ d
d ZG dd deZdS )    N)ArgumentParser)
CLICommand)HubApi)DEFAULT_MAX_WORKERS)dataset_file_downloadmodel_file_download)dataset_snapshot_downloadsnapshot_download)convert_patterns)DEFAULT_DATASET_REVISIONc                 C   s   t | S )z> Function which will be called for a specific sub parser.
    )DownloadCMDargs r   c/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/modelscope/cli/download.pysubparser_func   s   r   c                   @   s2   e Zd ZdZdd ZedefddZdd Zd	S )
r   downloadc                 C   s
   || _ d S )Nr   )selfr   r   r   r   __init__   s   
zDownloadCMD.__init__parsersc                 C   s  |  tj}| }|jdtdd |jdtdd |jdtddd	d
 |jdddgddd |jdtddd |jdtddd |jdtddd |jdtddd |jdtdddd |jdddtdd |jd dtdd!d" |jd#ttd$d |jt	d% dS )&z+ define args for download command.
        z--modelziThe id of the model to be downloaded. For download, the id of either a model or dataset must be provided.)typehelpz	--datasetzkThe id of the dataset to be downloaded. For download, the id of either a model or dataset must be provided.repo_id?NzQOptional, ID of the repo to download, It can also be set by --model or --dataset.)r   nargsdefaultr   z--repo-typemodeldatasetz4Type of repo to download from (defaults to 'model').)choicesr   r   z--tokenz7Optional. Access token to download controlled entities.)r   r   r   z
--revisionz%Revision of the entity (e.g., model).z--cache_dirz-Cache directory to save entity (e.g., model).z--local_dirzsFile will be downloaded to local location specified bylocal_dir, in this case, cache_dir parameter will be ignored.files*znSpecify relative path to the repository file(s) to download.(e.g 'tokenizer.json', 'onnx/decoder_model.onnx').)r   r   r   r   z	--includezEGlob patterns to match files to download.Ignored if file is specified)r   r   r   r   z	--excludezLGlob patterns to exclude from files to download.Ignored if file is specified)r   r   r   r   z--max-workersz0The maximum number of workers to download files.)func)

add_parserr   nameadd_mutually_exclusive_groupadd_argumentstrintr   set_defaultsr   )r   parsergroupr   r   r   define_args   s   zDownloadCMD.define_argsc              
   C   s  | j js| j jr%| j jd ur$| j jr| j jd| j j n0| j jg| j _n(| j jd urM| j jdkr8| j j| j _n| j jdkrE| j j| j _ntd| j j | j jsY| j jsYtdd }| j jd urlt	 }|j
| j jd}| j jrt| j jdkrt| j j| j jd | j j| j j| j j|d n>t| j jdkrt| j j| j j| j j| j j| j j| j j|d	 nt| j j| j j| j j| j jt| j jt| j j| j j|d
 td| j j d d S | j jrM| j jr| j jnt}t| j jdkrt| j j| j jd | j j| j j||d n;t| j jdkr%t| j j|| j j| j j| j j| j j|d	 nt| j j|| j j| j jt| j jt| j j| j j|d
 td| j j d d S 	 d S )Nr   r   r   zNot support repo-type: %szModel or dataset must be set.)Zaccess_token   )	cache_dir	local_dirrevisioncookies)r/   r-   r.   allow_file_patternmax_workersr0   )r/   r-   r.   r1   Zignore_file_patternr2   r0   z$
Successfully Downloaded from model z.
z&
Successfully Downloaded from dataset )r   r   r   r   r   insertZ	repo_type	Exceptiontokenr   Zget_cookieslenr   r-   r.   r/   r	   r2   r
   includeexcludeprintr   r   r   )r   r0   apiZdataset_revisionr   r   r   executel   s   
	

	

	

	zDownloadCMD.executeN)	__name__
__module____qualname__r#   r   staticmethodr   r+   r;   r   r   r   r   r      s    Or   )osargparser   Zmodelscope.cli.baser   Zmodelscope.hub.apir   Zmodelscope.hub.constantsr   Zmodelscope.hub.file_downloadr   r   Z modelscope.hub.snapshot_downloadr   r	   Zmodelscope.hub.utils.utilsr
   Zmodelscope.utils.constantr   r   r   r   r   r   r   <module>   s   