3
ØLôYt  ã               @   s`   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	 d dl
mZ G dd„ deƒZdS )	é    )Úconvert_path)Úlog)ÚDistutilsOptionErrorN)Úsix)Ú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úmatch=Úmúpatterns to match (required)ú	dist-dir=Údú%directory where the distributions areúkeep=Úkú(number of matching distributions to keepc             C   s   d | _ d | _d | _d S )N)ÚmatchÚdist_dirÚkeep)Úself© r   ús/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/setuptools/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
rP   tdƒ‚Y nX t| j tjƒrxdd„ | j jdƒD ƒ| _ | j	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 |jƒ ƒ‘qS r   )r   Ústrip)Ú.0Úpr   r   r   ú
<listcomp>+   s    z+rotate.finalize_options.<locals>.<listcomp>ú,Úbdistr   )r   r   )
r   r   r   ÚintÚ
ValueErrorÚ
isinstancer   Ústring_typesÚsplitÚset_undefined_options)r   r   r   r   Úfinalize_options   s    

zrotate.finalize_optionsc             C   sÔ   | j dƒ ddlm} x¸| jD ]®}| jjƒ d | }|tjj| j|ƒƒ}dd„ |D ƒ}|j	ƒ  |j
ƒ  tjdt|ƒ|ƒ || jd … }xD|D ]<\}}tjd|ƒ | jsŒtjj|ƒr¾tj|ƒ qŒtj|ƒ qŒW qW d S )	NÚegg_infor   )ÚglobÚ*c             S   s   g | ]}t jj|ƒ|f‘qS r   )ÚosÚpathÚgetmtime)r   Úfr   r   r   r   6   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)r   r	   r
   )r   r   r   )r   r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdescriptionÚuser_optionsÚboolean_optionsr   r$   r<   r   r   r   r   r      s   r   )Údistutils.utilr   Ú	distutilsr   Zdistutils.errorsr   r(   r6   Zsetuptools.externr   Ú
setuptoolsr   r   r   r   r   r   Ú<module>   s   