a
    6Rîh‹  ã                   @  sh   d dl mZ d dl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 G d	d
„ d
eƒZdS )é    )ÚannotationsN)ÚClassVaré   )ÚCommandÚ_shutil)Úlog)ÚDistutilsOptionError)Úconvert_pathc                   @  sN   e Zd ZU dZdZg d¢Zg Zded< dd„ Zdd	œd
d„Z	dd	œdd„Z
dS )ÚrotatezDelete older distributionsz2delete older distributions, keeping N newest files))zmatch=Úmzpatterns to match (required))z	dist-dir=Údz%directory where the distributions are)zkeep=Úkz(number of matching distributions to keepzClassVar[list[str]]Úboolean_optionsc                 C  s   d | _ d | _d | _d S )N)ÚmatchÚdist_dirÚkeep)Úself© r   úO/opt/python-3.9.24/usr/lib/python3.9/site-packages/setuptools/command/rotate.pyÚinitialize_options   s    zrotate.initialize_optionsÚNone)Úreturnc              
   C  s˜   | j d u rtdƒ‚| jd u r$tdƒ‚zt| jƒ| _W n. tyb } ztdƒ|‚W Y d }~n
d }~0 0 t| j tƒrˆdd„ | j  d¡D ƒ| _ |  dd¡ d S )	NzQMust specify one or more (comma-separated) match patterns (e.g. '.zip' or '.egg')z$Must specify number of files to keepz--keep must be an integerc                 S  s   g | ]}t | ¡ ƒ‘qS r   )r	   Ústrip)Ú.0Úpr   r   r   Ú
<listcomp>+   ó    z+rotate.finalize_options.<locals>.<listcomp>ú,Úbdist)r   r   )	r   r   r   ÚintÚ
ValueErrorÚ
isinstanceÚstrÚsplitÚset_undefined_options)r   Úer   r   r   Úfinalize_options   s    
ÿ
 zrotate.finalize_optionsc                 C  sÌ   |   d¡ ddlm} | jD ]ª}| j ¡ d | }|tj | j|¡ƒ}dd„ |D ƒ}| 	¡  | 
¡  t dt|ƒ|¡ || jd … }|D ]<\}}t d|¡ | jsˆtj |¡rºt |¡ qˆt |¡ qˆqd S )	NÚegg_infor   )ÚglobÚ*c                 S  s   g | ]}t j |¡|f‘qS r   )ÚosÚpathÚgetmtime)r   Úfr   r   r   r   5   r   zrotate.run.<locals>.<listcomp>z%d file(s) matching %szDeleting %s)Úrun_commandr(   r   ÚdistributionÚget_namer*   r+   Újoinr   ÚsortÚreverser   ÚinfoÚlenr   Údry_runÚisdirr   ÚrmtreeÚunlink)r   r(   ÚpatternÚfilesÚtr-   r   r   r   Úrun.   s     

z
rotate.runN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdescriptionÚuser_optionsr   Ú__annotations__r   r&   r=   r   r   r   r   r
      s   
r
   )Ú
__future__r   r*   Útypingr   Ú r   r   Ú	distutilsr   Údistutils.errorsr   Údistutils.utilr	   r
   r   r   r   r   Ú<module>   s   