
ˆ`@_ö  ã               @   sv   d  d l  m Z d  d l m Z d  d l m Z d  d l Z d  d l m Z d  d l	 m
 Z
 Gd d „  d e
 ƒ Z d S)	é    )Úconvert_path)Úlog)ÚDistutilsOptionErrorN)Úsix)ÚCommandc               @   sU   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   ú?/tmp/pip-build-tw3_dw7d/setuptools/setuptools/command/rotate.pyÚinitialize_options   s    		zrotate.initialize_optionsc             C   s¸   |  j  d  k r t d ƒ ‚ |  j d  k r6 t d ƒ ‚ y t |  j ƒ |  _ Wn t k
 rl t d ƒ ‚ Yn Xt |  j  t j ƒ r¤ d 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 Sr   )r   Ústrip)Ú.0Úpr   r   r   ú
<listcomp>*   s   	 z+rotate.finalize_options.<locals>.<listcomp>ú,Úbdistr   )údist_dirr   )
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  … } x: | D]2 \ } } t j d | ƒ |  j s¼ t j | ƒ q¼ Wq' Wd  S)	NÚegg_infor   )ÚglobÚ*c             S   s(   g  |  ] } t  j j | ƒ | f ‘ q Sr   )ÚosÚpathÚgetmtime)r   Úfr   r   r   r   5   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Ú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)   Zsetuptools.externr   Ú
setuptoolsr   r   r   r   r   r   Ú<module>   s   