o
    ߥi                     @   sT   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 Z
G dd deZd	S )
    )ArgumentParser)
CLICommand)dataset_file_downloadmodel_file_download)dataset_snapshot_downloadsnapshot_downloadc                 C   s   t | S )z> Function which will be called for a specific sub parser.
    )DownloadCMDargs r   K/home/ubuntu/.local/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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   )func)
add_parserr   nameadd_mutually_exclusive_groupadd_argumentstr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| 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d d S t| j j| j j| j j
| j j| j j| j jd	 d S | j jr
t| j jdkrt| 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d d S t| j j| j j| j j
| j j| 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)r*   r(   r)   r+   ignore_file_pattern)r
   r   r   r   r   insert	repo_type	Exceptionlenr   r(   r)   r*   r   includeexcluder   r   )r   r   r   r   execute]   s   








	zDownloadCMD.executeN)	__name__
__module____qualname__r   r   staticmethodr   r&   r3   r   r   r   r   r      s    Dr   N)argparser   modelscope.cli.baser   modelscope.hub.file_downloadr   r    modelscope.hub.snapshot_downloadr   r   r   r   r   r   r   r   <module>   s   