
    yjO                     r   d Z ddlZddlZddlZddlZddlmZ ddlm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mZmZmZ dd	lmZmZ d
gZ G d dej                  Zd Z ej        d ej        d                    Zej                             e d          Z!d Z"d Z#e$dk    r e#             dS dS )u\   
命令行

Authors: xiangyiqing(xiangyiqing@baidu.com),suoyi@baidu.com
Date:    2024/03/05
    N)log)pipeline)model_file_downloadfile_download)snapshot_download)convert_patterns)DEFAULT_MAX_WORKERSREPO_TYPE_SUPPORTREPO_TYPE_MODELDEFAULT_DATASET_REVISIONREPO_TYPE_DATASET)upload_fileupload_foldermainc                       e Zd ZdZdS )CustomHelpFormatteru%   
    自定义帮助信息格式
    N)__name__
__module____qualname____doc__     d/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/aistudio_sdk/cmdline.pyr   r       s          	Dr   r   c            
         t          j                     t          j        dt                    } |                     dd          }|                    dd          }|                    d	d
t          ddd           |                    ddt          ddg dd           |                    dd          }|                                }|                    dd          }|                    ddt          ddd           |                    ddt          dd            |                    d!d"t          dd#            |                    d$d%t          dd&g d'd(           |                    d)d*t          dd+d+gd,           |                    d-d.t          dd/g d0d1           |                    d2d3t          dd4d4d5gd6           |                    d7d8d9t          dg d:;           |                    d<d=          }|                    d>t          d?dd@A           |                    ddt          dddB           |                    dCdDt          dddE           |                    dFdG          }|                                }|                    ddG          }	|	                    dHt          d@I           |	                    dJdKdLdMN           |                    ddO          }
|
                    dPt          dQI           |
                    dddRS          }|                    dTdU          }|                    dVt          d?ddWA           |                    dXdY          }|                    dZt          d[I           |                    d\t          d]I           d^d_d`dadbdcdddedf}|                    dgdht          i          }djdk
                    dl |                                D                       z   }|                    dm          }|                    dndot          i          }|                    ddt          ddp            |                    dJdqt          ddrdst           |                    ddudLdvN           |                    ddwt          dt          |                                          dx|y           |                    d)dzt          dd{            |                    d|d}t          i          }|                    d~dt          dd            |                    dJdqt          ddrdst           |                    ddt          i          }|                    dt          dI           |                    dt          dI           |                    dt          dd           |                    dt          dd           |                    dt          ddd           |                    dddt          d           |                    ddt          dd           |                    d
t          dd           |                    dt          t          d           |                    ddt          i          }|                    dt          dI           |                    d\t          d?ddA           |                    dt          d?ddA           |                    dt          t           d           |                    ddt          d           |                    ddt          d           |                    dt          dd           |                    d
t          dd           |                    dt          t#          dt%          j                    dz             d           | S )u   
    构建CLI Parser
    PROG)progformatter_classzAI Studio CLI SDKcommand)helpdestconfigu   首次使用AI Studio CLI管理任务时, 需要先使用AI Studio账号的访问令牌进行身份认证。            一次认证后，再次使用时无需认证。)r   z-tz--tokenF u   AI Studio账号的访问令牌)typerequireddefaultr   z-lz--log)infodebugr"   u   日志级别)r#   r$   r%   choicesr   submitu   提交SDK产线任务jobz-nz--nameTsummit_nameu   产线任务名称)r#   r$   r    r   z-pz--pathuE   代码包本地路径(文件夹)，要求文件总体积不超过50MB)r#   r$   r   z-cz--cmdu   任务启动命令z-ez--envpaddle2.6_py3.10)zpaddle2.4_py3.7zpaddle2.5_py3.10r,   zpaddle3.0_py3.10u*   飞桨框架版本, 默认paddle2.6_py3.10z-dz--devicev100u   硬件资源, 默认v100z-gz--gpus1)         u   gpu数量, 默认单卡z-payz	--paymentacoincouponu?   计费方式: * acoin-A币 * coupon-算力点. 默认使用A币z-mz--mount_datasetappendu-   数据集挂载, 单个任务最多挂载3个)actionr#   r$   r%   r   jobsu   查询SDK产线任务query_pipeline_id?u   产线id)r#   nargsr%   r   u   产线名称z-sz--statusu   状态stopu   停止SDK产线任务stop_pipeline_id)r#   r   z-fz--force
store_trueu!   强制停止，无需二次确认)r5   r   u   管理SDK产线任务job_idu   任务IDu   job子命令)r    r$   r   lsu4   查询某个 job 的 output 目录下文件夹内容	directoryu   输出目录路径cpu7   下载某个 job 的 output 目录下的文件到本地result_fileu   结果文件路径
local_pathu   本地保存路径u   公共领域 (CC0)u   署名 (CC BY 4.0)u>   署名-非商业性使用-相同方式共享 (CC BY-NC-SA 4.0)u(   署名-相同方式共享 (CC BY-SA 4.0)u   署名-禁止演绎 (CC-BY-ND)u   自由软件基金会 (GPL 2)u   署名-允许演绎 (ODC-BY)u   其他)r/         r0            r1   datasetu?   管理数据集，此命令不在支持，请使用新的命令)r   r   uo   数据集许可协议的ID，仅在设置public后生效。默认为1 (公共领域 CC0)。
可选项包括：

c              3   ,   K   | ]\  }}d | d| V  dS )z  z: Nr   ).0kvs      r   	<genexpr>zinit.<locals>.<genexpr>
  s2      .a.aA}A}}}}.a.a.a.a.a.ar   u   数据集操作createu   创建数据集u   数据集名称z--files+u'   本地文件路径，支持多个文件)r#   r$   r9   r   z--publicu   是否公开数据集z	--licenser/   )r#   r$   r(   r%   r   z--descriptionu   数据集描述addu   上传数据集文件z-idz--idu   数据集iddownloadu   下载文件z--modelu!   模型ID，例如 myname/myrepoidz	--datasetzkThe id of the dataset to be downloaded. For download, the id of either a model or dataset must be provided.z
--revisionNzRevision of the entity.)r#   r%   r   z--local_dirzNFile will be downloaded to local location specified bylocal_dir, in this case.files*zmSpecify relative path to the repository file(s) to download.(e.g 'tokenizer.json', 'dir/decoder_model.onnx').)r#   r%   r9   r   z	--includezEGlob patterns to match files to download.Ignored if file is specified)r9   r%   r#   r   z	--excludezLGlob patterns to exclude from files to download.Ignored if file is specified)r9   r#   r%   r   zA User Access Tokenz--max-workersz0The maximum number of workers to download files.uploadu   上传文件repo_idz;The ID of the repo to upload to (e.g. `username/repo-name`)zTOptional, Local path to the file or folder to upload. Defaults to current directory.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`.)r(   r%   r   z'Glob patterns to match files to upload.)r9   r#   r   z.Glob patterns to exclude from files to upload.z--commit-messagez,The message of commit. Default to be `None`.r1   r0   z1The number of workers to use for uploading files.)r   cli_logargparseArgumentParserr   add_subparsers
add_parseradd_argumentstrintjoinitemslistkeysr	   r
   r   minos	cpu_count)parsersubparser_aistudior!   r)   subparser_submit
submit_jobr6   r:   subparser_stopstop_jobr*   subparser_jobjob_lsjob_cplicense_mappingrH   license_helpdatasets_createrO   rQ   rR   rU   s                         r   initrs   &   s    KMMM$&BUVVVF..  /    **> +  F
 i-     g%%%      **$ +  F ,,.. ",,$ -  J h!     hT	     g!	     g"___9     j'     h		&     (#N     <     (($ )  D 	     	h     	j     (($ )  D ((**N (($ )  H     
 i0     
'
'$ (  C      &&I>&ZZM %%C &  F !     %%F &  F !    
 !      K5+*)	 	O !++N+ ,  G#%)YY.a.aI^I^I`I`.a.a.a%a%ab 
 ,,2C,DDO ''+ (  F
 h	     i6     j$    
 k_))++,,     o	     
$
$$+ %  C v	     i6     ",,+ -  H
 0    
 D  E E E
 &	  ( ( (
 (	  ) ) ) A  B B B ,  - - - ,  - - - "	     #?	  A A A  **+ + - -F
 J  L L L
 Z     l     !_	     6	  8 8 8
 =	  ? ? ?
 ;	  = = =
 "	     ALNNQ&( (@  B B B Mr   AISTUDIO_CACHE_HOMEHOMEr%   z/.cache/aistudio/.auth/tokenc                     t          |            t          t          d          5 }|                    t	          |                      ddd           n# 1 swxY w Y   t          j        t          d           dS )z#
    save to separate location
    wNi  )printopen
TOKEN_FILEwriter^   re   chmod)tokenfs     r   
save_tokenr     s     
%LLL	j#		 !	E

              HZs   #AAAc                     t                      } t          j        dd         }t          |            	 |                     |          }n#  Y dS xY wt          |dd          dk    r|j        s
J d            |j                            d          dk    s
J d            |j                            d          d         }|j        | _        |j	        .t          j                            |          r|| _	        || _        n|j	        .t          j                            |          r|| _	        d	| _        n|j	        t          d
| d          |j        Zt          j                            |j	                  r6|j	        | _	        t          j                            |j	                  | _        n3|j        |j	        | _	        d| _        n|j	        | _	        |j        | _        t          j                            | j	                  r4t#          | j	        | j        | j        |j        |j        |j                   nt          j                            | j	                  r`t+          | j        | j	        | j        |j        |j        t-          |j                  t-          |j                  |j        |j        	  	         nt          | j	         d          t          d| j                    dS t5          |d          r|j        rt9          |j                  dk    r5t=          |j        |j        d         |j        |j         |j                   dS t9          |j                  dk    r5tC          |j        |j         |j        |j        |j        |j                   dS tC          |j        |j         |j        t-          |j                  t-          |j                  |j        |j                   dS t5          |d          r|j"        r|j         r|j         ntF          }t9          |j                  dk    r5tI          |j"        |j        d         |j        |tJ          |j                   nt9          |j                  dk    r/tC          |j"        ||j        |j        |j        |j                   nNtC          |j"        ||j        t-          |j                  t-          |j                  |j        |j                   t          d|j"         d           dS d|v rtM          j'        |           dS d|v rtM          j(        |           dS d|v rtM          j)        |           dS d|v r]|j*        s@tW          j,        dd           st[          j.        d!           dS t[          j.        d"           tM          j/        |           dS d#|v rtM          j0        |           dS d$|v rd%|v rtM          j1        |           dS d&|v r.d'|v r*t[          j2        d(           tM          j3        |           dS d)|v r.d'|v r*t[          j2        d(           tM          j4        |           dS t[          j.        d*           dS )+u	   CLI入口r/   Nr   rU   z`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.r"   )path_or_fileobjrW   rV   	repo_typecommit_messager~   )	rV   folder_pathrW   r   r   allow_patternsignore_patternsmax_workersr~   z is not a valid local pathzFinished uploading to modelr   )	local_dirrevisionr~   )rV   r   r   r   r   r~   )rV   r   r   r   r   r   r~   rH   )r   r   r   r~   z&
Successfully Downloaded from dataset z.
r~   r+   r7   r;   zDo you want to continue?Frv   zAborted.z
Confirmed.r?   rA   rB   namerS   z&This command is not supported any moreidu   无效的命令)5rs   sysargvry   
parse_argsgetattrrV   countsplitrB   re   pathisfilerW   isdir
ValueErrorbasenamer   r   r   r~   r   r   includeexcluder   hasattrr   lenrS   r   r   r   r   rH   r   r   r   r   
set_configrO   queryforceclickconfirmr   r&   r:   list_output_filesdownload_output_fileerrorcreate_datasetadd_file)rg   args	repo_namedataset_revisions       r   r   r     s   VVF8ABB<D	T)  &&tY%%11|44444||!!   J  ++C004	 ?"rw~~i'@'@" )F"+F_$y)A)A$ !*F"%F_$ cIccc   &27>>,! ,!& !%F"$'"2"24?"C"CF& !%F"$F !%F"&"3F 7>>&+,, 	O & 1#0.#2j     W]]6,-- 	O"-#0#2./== 0 > > ,j
 
 
 
 
  1MMMNNN7v~7788888	w		 \$TZ \$tz??a

1.j      
    
.#z ,j      
./== 0 > > ,j      
y	!	! ?$dl ?$15 \D\tz??a
1.)+j     
    ).#z ,j     )./== 0 > > ,j    	GdlGGG	
 	
 	
 	
 	
 
DD!!!!!	$				$	$t	t	#	#z 	#=!;UKKK $$$H\"""d			"4(((((	$		<4#7#7%d+++++	4GtOO	:;;;%%%%%	'T//	:;;;$"#####s   A
 
A__main__)%r   r   rY   r   re   aistudio_sdkr   aistudio_sdk.sdkr   aistudio_sdk.file_downloadr   r   aistudio_sdk.snapshot_downloadr   aistudio_sdk.utils.utilr   aistudio_sdk.configr	   r
   r   r   r   aistudio_sdk.hubr   r   __all__RawTextHelpFormatterr   rs   getenv
cache_homer   
expanduserr{   r   r   r   r   r   r   <module>r      s    


   				       % % % % % % I I I I I I I I < < < < < < 4 4 4 4 4 4N N N N N N N N N N N N N N 7 7 7 7 7 7 7 7 
	 	 	 	 	(7 	 	 	l l l\ RY,ibi6G6GHHH
W: K K KLL
     g$ g$ g$R zDFFFFF r   