
    9i                         S SK r S SKJr  S SK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 SKJr  S S	KJr  S
 r " S S\5      rg)    N)ArgumentParser)
CLICommand)HubApi)DEFAULT_MAX_WORKERS)dataset_file_downloadmodel_file_download)dataset_snapshot_downloadsnapshot_download)convert_patterns)DEFAULT_DATASET_REVISIONc                     [        U 5      $ )z=Function which will be called for a specific sub parser.
    )DownloadCMDargss    W/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/cli/download.pysubparser_funcr      s     t    c                   <    \ rS rSrSrS r\S\4S j5       rS r	Sr
g)	r      downloadc                     Xl         g )Nr   )selfr   s     r   __init__DownloadCMD.__init__   s    	r   parsersc                    U R                  [        R                  5      nUR                  5       nUR	                  S[
        SS9  UR	                  S[
        SS9  UR	                  S[
        SSS	S
9  UR	                  SS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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%9  g)&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--tokenz7Optional. Access token to download controlled entities.)r   r"   r   z
--revisionz%Revision of the entity (e.g., model).z--cache_dirz-Cache directory to save entity (e.g., 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   z--max-workersz0The maximum number of workers to download files.)func)

add_parserr   nameadd_mutually_exclusive_groupadd_argumentstrintr   set_defaultsr   )r   parsergroups      r   define_argsDownloadCMD.define_args   s    ")!3!3K4D4D!E335D 	 	E
 	D 	 	E
 	V 	 	
 	i(G	 	 	
 	J	 	 	L
 	8	 	 	:
 	@	 	 	B
 	L	 	 	M 	A 	 	B 	+ 	 	, 	+ 	 	, 	'C	 	 	E 	0r   c                    U R                   R                  (       d  U R                   R                  (       a  U R                   R                  b|  U R                   R                  (       a;  U R                   R                  R                  SU R                   R                  5        OU R                   R                  /U R                   l        OU R                   R                  b  U R                   R                  S:X  a&  U R                   R                  U R                   l        ObU R                   R                  S:X  a&  U R                   R                  U R                   l        O"[        SU R                   R                  -  5      eU R                   R                  (       d&  U R                   R                  (       d  [        S5      eS nU R                   R                  b-  [        5       nUR                  U R                   R                  S9nU R                   R                  (       Ga  [        U R                   R                  5      S:X  aw  [        U R                   R                  U R                   R                  S   U R                   R                  U R                   R                  U R                   R                  US9  GOY[        U R                   R                  5      S:  a  [!        U R                   R                  U R                   R                  U R                   R                  U R                   R                  U R                   R                  U R                   R"                  US	9  O[!        U R                   R                  U R                   R                  U R                   R                  U R                   R                  [%        U R                   R&                  5      [%        U R                   R(                  5      U R                   R"                  US
9  [+        SU R                   R                   S35        g U R                   R                  (       Ga  U R                   R                  (       a  U R                   R                  O[,        n[        U R                   R                  5      S:X  ac  [/        U R                   R                  U R                   R                  S   U R                   R                  U R                   R                  UUS9  GO1[        U R                   R                  5      S:  at  [1        U R                   R                  UU R                   R                  U R                   R                  U R                   R                  U R                   R"                  US	9  O[1        U R                   R                  UU R                   R                  U R                   R                  [%        U R                   R&                  5      [%        U R                   R(                  5      U R                   R"                  US
9  [+        SU R                   R                   S35        g g )Nr   r#   r$   zNot support repo-type: %szModel or dataset must be set.)access_token   )	cache_dir	local_dirrevisioncookies)r9   r7   r8   allow_file_patternmax_workersr:   )r9   r7   r8   r;   ignore_file_patternr<   r:   z$
Successfully Downloaded from model z.
z&
Successfully Downloaded from dataset )r   r#   r$   r   r&   insert	repo_type	Exceptiontokenr   get_cookieslenr   r7   r8   r9   r
   r<   r   includeexcludeprintr   r   r	   )r   r:   apidataset_revisions       r   executeDownloadCMD.executel   s4   99??dii//yy  ,99??IIOO**1dii.?.?@'+yy'8'8&9DIIOyy  ,99&&'1&*ii&7&7DIIOYY((I5(,		(9(9DII%#$?&*ii&9&9%: ; ;yytyy'8'8;<<99??&(Coo499??oCG99???499??#q(#IIOOIIOOA&"ii11"ii11!YY//#% IIOO%'()!IIOO!YY//"ii11"ii11'+yy $		 5 5#% "IIOO!YY//"ii11"ii11'7		8I8I'J(89J9J(K $		 5 5#% 9$))//9J#NOYY:>)):L:LDII$6$6Rj499??#q(%II%%IIOOA&"ii11"ii11-#% IIOO%'())II%%-"ii11"ii11'+yy $		 5 5#% *II%%-"ii11"ii11'7		8I8I'J(89J9J(K $		 5 5#% 9$)):K:K9LCP r   r   N)__name__
__module____qualname____firstlineno__r*   r   staticmethodr   r2   rI   __static_attributes__ r   r   r   r      s1    D M1^ M1 M1^Wr   r   )osargparser   modelscope.cli.baser   modelscope.hub.apir   modelscope.hub.constantsr   modelscope.hub.file_downloadr   r    modelscope.hub.snapshot_downloadr	   r
   modelscope.hub.utils.utilsr   modelscope.utils.constantr   r   r   rQ   r   r   <module>r[      s8    	 # * % 8?A 7 >m* mr   