o
    W+ i                     @   sl   d dl Z d dlmZ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 ZG d	d
 d
eZdS )    N)ArgumentParser_SubParsersAction)
CLICommand)HubApi)convert_patternsget_endpoint)REPO_TYPE_MODELREPO_TYPE_SUPPORTc                 C   s   t | S )z> Function which will be called for a specific sub parser.
    )	UploadCMDargs r   a/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/modelscope/cli/upload.pysubparser_func   s   r   c                   @   s8   e Zd ZdZdefddZedefddZdd	 Zd
S )r
   Zuploadr   c                 C   s
   || _ d S )Nr   )selfr   r   r   r   __init__   s   
zUploadCMD.__init__parsersc                 C   s   |  tj}|jdtdd |jdtdd dd |jdtdd d	d |jd
ttdd |jddtdd |jddtdd |jdtd dd |jdtd dd |jdtd dd |jdttdt	
 d dd |jdtt dd |jtd  d S )!Nrepo_idz;The ID of the repo to upload to (e.g. `username/repo-name`))typehelp
local_path?zTOptional, Local path to the file or folder to upload. Defaults to current directory.)r   nargsdefaultr   path_in_repozfOptional, Path of the file or folder in the repo. Defaults to the relative path of the file or folder.z--repo-typezPType of the repo to upload to (e.g. `dataset`, `model`). Defaults to be `model`.)choicesr   r   z	--include*z'Glob patterns to match files to upload.)r   r   r   z	--excludez.Glob patterns to exclude from files to upload.z--commit-messagez,The message of commit. Default to be `None`.)r   r   r   z--commit-descriptionz>The description of the generated commit. Default to be `None`.z--tokenzIA User Access Token generated from https://modelscope.cn/my/myaccesstokenz--max-workers      z1The number of workers to use for uploading files.z
--endpointz Endpoint for ModelScope service.)func)
add_parserr
   nameadd_argumentstrr	   r   intminos	cpu_countr   set_defaultsr   )r   parserr   r   r   define_args   s   
zUploadCMD.define_argsc                 C   s  | j jsJ d| j jddksJ d| j jdd }| j j| _| j jd u r6tj|r6|| _|| _nW| j jd u rItj	|rI|| _d| _nD| j jd u rWt
d| d| j jd u rttj| j jrt| j j| _tj| j j| _n| j jd u r| j j| _d	| _n
| j j| _| j j| _t| j jd
}tj| jr|j| j| j| j| j j| j j| j j| j jd n4tj	| jr|j| j| j| j| j j| j j| j jt| j jt| j j| j j| j jd
 nt
| j dtd| j  d S )Nz`repo_id` is required/   z1repo_id should be in format of username/repo-name.'zD' is not a local file or folder. Please set `local_path` explicitly. )endpoint)Zpath_or_fileobjr   r   	repo_typecommit_messagecommit_descriptiontoken)
r   Zfolder_pathr   r3   r4   r2   Zallow_patternsignore_patternsmax_workersr5   z is not a valid local pathzFinished uploading to )r   r   countsplitr   r&   pathisfiler   isdir
ValueErrorbasenamer   r1   Zupload_filer2   r3   r4   r5   Zupload_folderr   includeexcluder7   print)r   	repo_nameapir   r   r   executeb   sp   





	

zUploadCMD.executeN)	__name__
__module____qualname__r!   r   r   staticmethodr*   rD   r   r   r   r   r
      s    Ir
   )r&   argparser   r   Zmodelscope.cli.baser   Zmodelscope.hub.apir   Zmodelscope.hub.utils.utilsr   r   Zmodelscope.utils.constantr   r	   r   r
   r   r   r   r   <module>   s   