
    9i                     p    S SK r S SKJrJr  S SKJr  S SKJr  S SKJ	r	J
r
  S SKJrJr  S r " S S	\5      rg)
    N)ArgumentParser_SubParsersAction)
CLICommand)HubApi)convert_patternsget_endpoint)REPO_TYPE_MODELREPO_TYPE_SUPPORTc                     [        U 5      $ )z=Function which will be called for a specific sub parser.
    )	UploadCMDargss    U/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/cli/upload.pysubparser_funcr      s     T?    c                   D    \ rS rSrSrS\4S jr\S\4S j5       rS r	Sr
g	)
r      uploadr   c                     Xl         g )Nr   )selfr   s     r   __init__UploadCMD.__init__   s    	r   parsersc           	         U R                  [        R                  5      nUR                  S[        SS9  UR                  S[        SS SS9  UR                  S[        SS S	S9  UR                  S
[
        [        SS9  UR                  SS[        SS9  UR                  SS[        SS9  UR                  S[        S SS9  UR                  S[        S SS9  UR                  S[        S SS9  UR                  S[        [        S[        R                  " 5       S-   5      SS9  UR                  S[        [        5       SS9  UR                  [        S 9  g )!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   parsers     r   define_argsUploadCMD.define_args   s    ")!3!3INN!CN 	 	P 	Y 	 	
 	k 	 	
 	%#^ 	 	
 	:	 	 	<
 	A	 	 	C
 	?	 	 	A
 	"L 	 	N 	W 	 	
 	*,D 	 	F 	 N3	 	 	5 	0r   c                    U R                   R                  (       d   S5       eU R                   R                  R                  S5      S:X  d   S5       eU R                   R                  R                  S5      S   nU R                   R                  U l        U R                   R                  c2  [
        R                  R                  U5      (       a  Xl        Xl        GOU R                   R                  c3  [
        R                  R                  U5      (       a  Xl        SU l        GO9U R                   R                  c  [        SU S35      eU R                   R                  c  [
        R                  R                  U R                   R                  5      (       aT  U R                   R                  U l        [
        R                  R                  U R                   R                  5      U l        OpU R                   R                  c#  U R                   R                  U l        S	U l        O6U R                   R                  U l        U R                   R                  U l        [        U R                   R                  S
9n[
        R                  R                  U R                  5      (       a  UR                  U R                  U R                  U R                  U R                   R                  U R                   R                   U R                   R"                  U R                   R$                  S9  GO[
        R                  R                  U R                  5      (       a  UR'                  U R                  U R                  U R                  U R                   R                   U R                   R"                  U R                   R                  [)        U R                   R*                  5      [)        U R                   R,                  5      U R                   R.                  U R                   R$                  S9
  O[        U R                   S35      e[1        SU R                   35        g )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;   upload_filer=   r>   r?   r@   upload_folderr   includeexcluderD   print)r   	repo_nameapis      r   executeUploadCMD.executeb   s   yy  9"99 yy  && 	KJ	K **005b9	yy(( 99'BGGNN9,E,E'O )YY!!)bggmmI.F.F (O #DYY!!) I;bc  YY##+		$$1& 1& #ii22DO " 0 01E1E FDYY##+ #ii22DO "D #ii22DO $		 6 6Ddii00177>>$//**OO $!..))--#yy77#'99#?#?iioo   WW]]4??++ OO!..#yy77#'99#?#?))--/		0A0AB 01B1B C II11iioo   00JKLL&t||n56r   )r   r   r"   r   N)__name__
__module____qualname____firstlineno__r)   r   r   staticmethodr2   rS   __static_attributes__ r   r   r   r      s:    D.  G1. G1 G1RD7r   r   )r.   argparser   r   modelscope.cli.baser   modelscope.hub.apir   modelscope.hub.utils.utilsr   r   modelscope.utils.constantr	   r
   r   r   r[   r   r   <module>ra      s*    	 6 * % E HU7
 U7r   