B
    ›³ëbè  ã               @   s`   d Z ddlZddlZddlZddlZdd„ Zddddd	ed
œedœiZdd„ Ze	dkr\eƒ  dS )a  Show or convert the configuration of an SCons cache directory.

A cache of derived files is stored by file signature.
The files are split into directories named by the first few
digits of the signature. The prefix length used for directory
names can be changed by this script.
é    Nc             C   sÎ   t d| d|ƒ tƒ }tƒ }x–t tj dd¡¡D ]~}tj |¡}|d| …  ¡ }||krlt d|ƒ | 	|¡ |d|…  ¡ }||kr˜t 
|¡ | 	|¡ t |tj ||¡¡ q0W x|D ]}t |¡ q¸W dS )zªMove cache files if prefix length changed.

    Move the existing cache files to new directories of the
    appropriate name length and clean up the old directories.
    zChanging prefix length fromÚtoÚ*NZ	Migrating)ÚprintÚsetÚglobZiglobÚosÚpathÚjoinÚbasenameÚupperÚaddÚmkdirÚrenameÚrmdir)Zcurrent_prefix_lenZnew_prefix_lenÚdirsZold_dirsÚfileÚnameZdname© r   ú=lib/python3.7/site-packages/SCons/Utilities/ConfigureCache.pyÚrearrange_cache_entries)   s"    




r   Ú
prefix_lené   é   z5Length of cache file name used as subdirectory prefixz<number>)ÚhelpÚmetavarÚtype)ÚimplicitÚdefaultzcommand-lineÚ	converterc           	   C   s~  t jddd} | jddd x.tD ]&}| jd| dd	¡ ft| d
 Ž q"W | jdddd | jdddd tdd„ t|  ¡ ƒ ¡ D ƒƒ}|d }t	j
 |¡sªtd| ƒ‚t	 |¡ |d= t	j
 d¡sdd„ tddƒD ƒ}tt	 d¡ƒ |¡sütd| ƒ‚tƒ }ntdƒ}t |¡}W d Q R X | dd ¡ržtd| ƒ ttj|ddd d!ƒ d}x&t	 d¡D ]\}}}	|t|	ƒ7 }qbW |rŒ|d"8 }td#| ƒ |d= xbtD ]Z}
|
|kr¤d$t|
 krÒt|
 d$ ||
< nt|
 d% ||
< |
|kr¤t|
 d% ||
< q¤W xT|D ]L}
||
 ||
 krd&t|
 krFt|
 d& ||
 ||
 ƒ ||
 ||
< qW tdd'ƒ}t ||¡ W d Q R X d S )(Nz4Modify the configuration of an scons cache directoryz¬
               Unspecified options will not be changed unless they are not
               set at all, in which case they are set to an appropriate default.
               )ZdescriptionZepilogz	cache-dirzPath to scons cache directory)r   z--Ú_ú-zcommand-linez	--versionÚversionz%(prog)s 1.0)Úactionr!   z--showÚ
store_truezshow current configuration)r"   r   c             S   s   g | ]}|d  r|‘qS )r   r   )Ú.0Úxr   r   r   ú
<listcomp>q   s    zmain.<locals>.<listcomp>z$There is no cache directory named %sÚconfigc             S   s   g | ]}d   |¡‘qS )z{:X})Úformat)r$   r%   r   r   r   r&   ~   s    r   é   Ú.z7%s does not look like a valid version 1 cache directoryZshowzCurrent configuration in '%s':Té   )ú,z: )Z	sort_keysÚindentZ
separatorsr   zCache contains %s filesr   r   r   Úw)ÚargparseÚArgumentParserÚadd_argumentÚconfig_entriesÚreplaceÚdictÚvarsÚ
parse_argsÚitemsr   r   ÚisdirÚRuntimeErrorÚchdirÚexistsÚranger   ÚlistdirÚissubsetÚopenÚjsonÚloadÚgetr   ÚdumpsÚwalkÚlenÚdump)ÚparserZparamÚargsÚcacheZexpectedr'   ZconfZ
file_countr   ÚfilesÚkeyr   r   r   Úmain]   sh    








rL   Ú__main__)
Ú__doc__r/   r   r@   r   r   Úintr2   rL   Ú__name__r   r   r   r   Ú<module>"   s   '
M