
    9i                     l    S SK r 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  S r " S S	\5      rg)
    N)ArgumentParser)Path)
CLICommand)TEMPORARY_FOLDER_NAME)get_model_masked_directoryc                     [        U 5      $ )z=Function which will be called for a specific sub parser.
    )ClearCacheCMD)argss    Y/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/cli/clearcache.pysubparser_funcr      s         c                   H    \ rS rSrSrS r\S\4S j5       rS r	S r
S rS	rg
)r	      zclear-cachec                     Xl         [        R                  " S[        R                  " 5       R                  SS5      5      U l        g )NMODELSCOPE_CACHEz.cache
modelscope)r
   osgetenvr   homejoinpath	cache_dir)selfr
   s     r   __init__ClearCacheCMD.__init__   s0    	IIK  <8: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9  g)z-define args for clear-cache command.
        z--modelzThe id of the model whose cache will be cleared. For clear-cache, if neither model or dataset id is provided, entire cache will be cleared.)typehelpz	--datasetzThe id of the dataset whose cache will be cleared. For clear-cache, if neither model or dataset id is provided, entire cache will be cleared.)funcN)
add_parserr	   nameadd_mutually_exclusive_groupadd_argumentstrset_defaultsr   )r   parsergroups      r   define_argsClearCacheCMD.define_args   s{     ##M$6$67335X	 	 	
 	X	 	 	
 	0r   c                 $    U R                  5         g )N)_execute_with_confirmation)r   s    r   executeClearCacheCMD.execute2   s    '')r   c                    SnSnSnU R                   R                  (       d  U R                   R                  (       a]  U R                   R                  (       a"  U R                   R                  nSnUSU S3-   nO5U R                   R                  nUSU S3-   nOUSU R                   S3-   nSn[	        US	-   5      R                  5       R                  5       nUS
:X  a  U(       a'  U R                  U R                  5        [        S5        g [        R                  R                  U R                  U(       a  SOSW5      n[        R                  R                  U R                  U(       a  SOS[        U5      nU R                  U5      nU R                  U5      n	U(       d.  U	(       d'  U(       a  [        SU S35        g [        SU S35        g [        S5        g [        S5        g )NFz
You are about to delete Tzlocal cache for model z. zlocal cache for dataset zentire ModelScope cache at z$, including ALL models and dataset.
z9
Please press Y or y to proceed, any other key to abort.
YzCache cleared.hubdatasetszCache for Model z not found. Nothing to do.zCache for Dataset zOperation aborted.)r
   modeldatasetr   inputstripupper_remove_directoryprintr   pathjoinr   )
r   allsingle_modelpromptid
user_inputentity_directorytemp_directoryentity_removedtemp_removeds
             r   r+   (ClearCacheCMD._execute_with_confirmation5   s   -99??dii//yyYY__#$:2$b"AAYY&&$<RD"CC ;DNN;KKpqqFCKL
 %'%%' 	
 &&t~~6&'#%77<<NN\Ez2$O !#NN\Ez)2"/ "&!7!78H!I#55nE&#.rd2LMO 04NO *+&'r   c                    [         R                  R                  U5      (       a   [         R                  R                  U5      (       aP  [        R
                  " [         R                  " U5      5        [         R                  " U5        [        SU S35        g[        R
                  " U5        [        SU S35        gg ! [         a  n[        SU SU 35         S nAgS nAff = f)NzCache and link for z	 removed.zCache folder Tz*An error occurred while clearing cache at z: F)
r   r9   existsislinkshutilrmtreereadlinkremover8   	Exception)r   r9   es      r   r7   ClearCacheCMD._remove_directoryd   s    77>>$
P77>>$''MM"++d"34IIdO/vY?@  MM$'M$y9:    PB4&1#NOOPs   A3C %C 
C&C!!C&)r
   r   N)__name__
__module____qualname____firstlineno__r!   r   staticmethodr   r(   r,   r+   r7   __static_attributes__ r   r   r	   r	      s7    D: 1^ 1 1,*-^r   r	   )r   rH   argparser   pathlibr   modelscope.cli.baser   modelscope.hub.constantsr   modelscope.hub.utils.utilsr   r   r	   rU   r   r   <module>r[      s-    	  #  * : A_J _r   