B
    ‹dP  ã               @   sT   d dl mZ d dlmZ d dlmZ d dlZd dlZd dlm	Z	 G dd„ de	ƒZ
dS )é    )Úconvert_path)Úlog)ÚDistutilsOptionErrorN)ÚCommandc               @   s:   e Zd ZdZdZdddgZg Zdd„ Zdd	„ Z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 keepc             C   s   d | _ d | _d | _d S )N)ÚmatchÚdist_dirÚkeep)Úself© r   úf/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/setuptools/command/rotate.pyÚinitialize_options   s    zrotate.initialize_optionsc          
   C   s–   | j d krtdƒ‚| jd kr$tdƒ‚yt| jƒ| _W n, tk
r` } ztdƒ|‚W d d }~X Y nX 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>)   s    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} x¸| jD ]®}| j ¡ d | }|tj | j|¡ƒ}dd„ |D ƒ}| 	¡  | 
¡  t dt|ƒ|¡ || jd … }xD|D ]<\}}t d|¡ | jsŒtj |¡r¾t |¡ qŒt |¡ qŒW qW d S )	NÚegg_infor   )ÚglobÚ*c             S   s   g | ]}t j |¡|f‘qS r   )ÚosÚpathÚgetmtime)r   Úfr   r   r   r   4   s    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ÚisdirÚshutilÚrmtreeÚunlink)r   r    ÚpatternÚfilesÚtr%   r   r   r   Úrun-   s     
z
rotate.runN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdescriptionÚuser_optionsÚboolean_optionsr   r   r6   r   r   r   r   r   
   s   r   )Údistutils.utilr   Ú	distutilsr   Údistutils.errorsr   r"   r0   Ú
setuptoolsr   r   r   r   r   r   Ú<module>   s   