o
    /ѹg                     @   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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)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.
    N)DownloadCMDargs r   [/Users/admin/.pyenv/versions/3.10.0/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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
--revisionzRevision of the model.)r   r   r   z--cache_dirzCache directory to save 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)
Z
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   sL  | 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| j jrt| j jdkr|t	| j j| j jd | j j
| j j| j jd d S t| j jdkrt| j j| j j| j j
| j j| j j| j jd d S t| j j| j j| j j
| j jt| j jt| j j| j jd	 d S | j jr#| j jr| j jnt}t| j jdkrt| j j| j jd | j j
| j j|d d S t| j jdkrt| j j|| j j
| j j| j j| j jd d S t| j j|| j j
| j jt| j jt| j j| j jd	 d S 	 d S )
Nr   r   r   zNot support repo-type: %szModel or dataset must be set.   )	cache_dir	local_dirrevision)r-   r+   r,   allow_file_patternmax_workers)r-   r+   r,   r.   Zignore_file_patternr/   )r   r   r   r   r   insertZ	repo_type	Exceptionlenr   r+   r,   r-   r   r/   r	   includeexcluder
   r   r   )r   Zdataset_revisionr   r   r   executef   s   


	



	


	



zDownloadCMD.executeN)	__name__
__module____qualname__r!   r   staticmethodr   r)   r5   r   r   r   r   r      s    Jr   )osargparser   Zmodelscope.cli.baser   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   