o
    /ѹg                     @   sp   d dl Z d dlmZ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mZ dd ZG d	d
 d
eZdS )    N)ArgumentParser_SubParsersAction)
CLICommand)HubApiModelScopeConfig)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.
    N)	UploadCMDargs r   Y/Users/admin/.pyenv/versions/3.10.0/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   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)Z
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
}| j jr|j| j jd t }|d u rt
dtj| jr|j| j| j| j| j j| j j| j jd n1tj	| jr|j| j| j| j| j j| j j| j jt| j jt| 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access_tokenzThe `token` is not provided! You can pass the `--token` argument, or use api.login(access_token=`your_sdk_token`). Your token is available at https://modelscope.cn/my/myaccesstoken)Zpath_or_fileobjr   r   	repo_typecommit_messagecommit_description)	r   Zfolder_pathr   r4   r5   r3   Zallow_patternsignore_patternsmax_workersz is not a valid local pathzFinished uploading to )r   r   countsplitr   r'   pathisfiler   isdir
ValueErrorbasenamer   r2   tokenloginr   Zget_cookiesZupload_filer3   r4   r5   Zupload_folderr   includeexcluder7   print)r   	repo_nameapicookiesr   r   r   executeb   sz   







zUploadCMD.executeN)	__name__
__module____qualname__r"   r   r   staticmethodr+   rG   r   r   r   r   r      s    Ir   )r'   argparser   r   Zmodelscope.cli.baser   Zmodelscope.hub.apir   r   Zmodelscope.hub.utils.utilsr   r   Zmodelscope.utils.constantr	   r
   r   r   r   r   r   r   <module>   s   