
    6pj                     l    S r 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
JrJr  S r " S S	\5      rg)
u&  Clear-cache CLI command — retained for backward compatibility.

The ``modelscope_hub`` CLI now owns ``clear-cache`` as an alias for
``cache clear``, but this module preserves the legacy :class:`ClearCacheCMD`
class so that existing tests and callers that import it directly continue
to work.
    N)ArgumentParser)
CLICommand)TEMPORARY_FOLDER_NAME)get_dataset_cache_rootget_model_cache_rootget_modelscope_cache_dirc                     [        U 5      $ )z=Function which will be called for a specific sub parser.
    )ClearCacheCMD)argss    U/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope/cli/clearcache.pysubparser_funcr      s         c                   \    \ rS rSrSrS r\SS j5       r\S\4S j5       r	S r
S	 rS
 rSrg)r
      zclear-cachec                 .    Xl         [        5       U l        g N)r   r   	cache_dir)selfr   s     r   __init__ClearCacheCMD.__init__   s    	13r   Nc                 .    [         R                  U 5        g)z:Register clear-cache subcommand (CLICommand ABC contract).N)r
   define_args)
subparserss    r   registerClearCacheCMD.register!   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9  g)z-define args for clear-cache command.
        z--modelzzThe id of the model whose cache will be cleared. If neither model or dataset id is provided, entire cache will be cleared.)typehelpz	--datasetz|The id of the dataset whose cache will be cleared. 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   r   ClearCacheCMD.define_args&   sy     ##M$6$67335 	 	  	 	 	  	0r   c                 $    U R                  5         g r   )_execute_with_confirmation)r   s    r   executeClearCacheCMD.execute;   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 U(       a
  [        5       O	[        5       n[        R                  R                  UW5      n[        R                  R                  U[        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.z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   r   ospathjoinr   )r   allsingle_modelpromptid
user_inputentity_rootentity_directorytemp_directoryentity_removedtemp_removeds              r   r+   (ClearCacheCMD._execute_with_confirmation>   s   -99??dii//yyYY__#$:2$b"AAYY&&$<RD"CC!<T^^<L ME  F GFCKL
 %'%%' 	
 &&t~~6&' " 3 '='? #%77<<R#@ !#k.CR"I!%!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)
r7   r8   existsislinkshutilrmtreereadlinkremover6   	Exception)r   r8   es      r   r5   ClearCacheCMD._remove_directoryn   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   )returnN)__name__
__module____qualname____firstlineno__r"   r   staticmethodr   r   r   r,   r+   r5   __static_attributes__ r   r   r
   r
      sK    D4 . . 1^ 1 1(*.`r   r
   )__doc__r7   rH   argparser   modelscope.cli.baser   modelscope.hub.constantsr   modelscope.utils.file_utilsr   r   r   r   r
   rV   r   r   <module>r\      s:    
  # * :C C
aJ ar   