î
É Xò  ã               @   sv   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l	 m
 Z
 Gd d „  d e ƒ Z d S)	é    N)ÚCommand)Ú
basestring)Úconvert_path)Úlog)ÚDistutilsOptionErrorc               @   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   úK/home/ubuntu/projects/ifolica/build/setuptools/setuptools/command/rotate.pyÚinitialize_options   s    		zrotate.initialize_optionsc             C   s¾   |  j  d  k r t d ƒ ‚ n  |  j d  k r< t d ƒ ‚ n  y t |  j ƒ |  _ Wn t k
 rr t d ƒ ‚ Yn Xt |  j  t ƒ rª d d „  |  j  j d ƒ Dƒ |  _  n  |  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   Ú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]5 \ } } t j d | ƒ |  j s¼ t j | ƒ q¼ 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   1   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$   r9   r   r   r   r   r      s   	r   )r(   Ú
setuptoolsr   Zsetuptools.compatr   Údistutils.utilr   Ú	distutilsr   Údistutils.errorsr   r   r   r   r   r   Ú<module>   s   