
    uj                     x    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 Z G d d	e          ZdS )
    N)ArgumentParser_SubParsersAction)
CLICommand)HubApi)convert_patternsresolve_endpoint)REPO_TYPE_MODELREPO_TYPE_SUPPORTc                      t          |           S )z> Function which will be called for a specific sub parser.
    )	UploadCMDargss    e/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/cli/upload.pysubparser_funcr      s     T??    c                   @    e Zd ZdZdefdZedefd            Zd ZdS )r   uploadr   c                     || _         d S )Nr   )selfr   s     r   __init__zUploadCMD.__init__   s    			r   parsersc           	      ^   |                      t          j                  }|                    dt          d           |                    dt          dd d           |                    dt          dd d	           |                    d
t
          t          d           |                    ddt          d           |                    ddt          d           |                    dt          d d           |                    dt          d d           |                    dt          d d           |                    dt          t          dt          j
                    dz             d           |                    dt          d d           |                    t                      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
--endpointzModelScope server endpoint, e.g. modelscope.cn or modelscope.ai    Full URL like https://modelscope.cn is also accepted. Scheme (https://) is auto-completed if omitted. Falls back to env MODELSCOPE_DOMAIN, then defaults to https://www.modelscope.cn.)func)
add_parserr   nameadd_argumentstrr
   r	   intminos	cpu_countset_defaultsr   )r   parsers     r   define_argszUploadCMD.define_args   sC    ")!3!3IN!C!CN 	 	P 	P 	P 	Y 	 	
 	
 	
 	k 	 	
 	
 	
 	%#^ 	 	
 	
 	
 	:	 	 	< 	< 	<
 	A	 	 	C 	C 	C
 	?	 	 	A 	A 	A
 	"L 	 	N 	N 	N 	W 	 	
 	
 	
 	*, ,D 	 	F 	F 	F 	:	 	 	; 	; 	; 	00000r   c                    | j         j        s
J d            | j         j                            d          dk    s
J d            | j         j                            d          d         }| j         j        | _        | j         j        /t
          j                            |          r|| _        || _        n| j         j        .t
          j        	                    |          r|| _        d| _        n| j         j        t          d| d          | j         j        it
          j                            | j         j                  r@| j         j        | _        t
          j                            | j         j                  | _        nG| j         j        | j         j        | _        d	| _        n"| j         j        | _        | j         j        | _        t          t          | j         j                  
          }t
          j                            | j                  rT|                    | j        | j        | j        | j         j        | j         j        | j         j        | j         j                   nt
          j        	                    | j                  r|                    | j        | j        | j        | j         j        | j         j        | j         j        t+          | j         j                  t+          | j         j                  | j         j        | j         j        
  
         nt          | j         d          t3          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)path_or_fileobjr    r   	repo_typecommit_messagecommit_descriptiontoken)
r   folder_pathr    r;   r<   r:   allow_patternsignore_patternsmax_workersr=   z is not a valid local pathz
Finished uploading to )r   r   countsplitr   r,   pathisfiler    isdir
ValueErrorbasenamer   r   r8   upload_filer:   r;   r<   r=   upload_folderr   includeexcluderA   print)r   	repo_nameapis      r   executezUploadCMD.executef   s    y 99"999 y &&   J  *0055b9	y( 9'BGNN9,E,E''DO )DY!)bgmmI.F.F) (DO #DY!) cIccc   Y#+	$1& 1&+ #i2DO " 0 01E F FDY#+ #i2DO "D #i2DO $	 6D.ty/ABBCCC7>>$/** 	MOO $!.)-#y7#'9#?io      W]]4?++ 	M O!.#y7#'9#?)-/	0ABB 01B C C I1io      KKKLLL77788888r   N)	__name__
__module____qualname__r'   r   r   staticmethodr0   rP    r   r   r   r      sw        D.     K1. K1 K1 K1 \K1ZD9 D9 D9 D9 D9r   r   )r,   argparser   r   modelscope.cli.baser   modelscope.hub.apir   modelscope.hub.utils.utilsr   r   modelscope.utils.constantr	   r
   r   r   rU   r   r   <module>r[      s    				 6 6 6 6 6 6 6 6 * * * * * * % % % % % % I I I I I I I I H H H H H H H H  Y9 Y9 Y9 Y9 Y9
 Y9 Y9 Y9 Y9 Y9r   