B
    kG_5              	   @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZ dddgZdddZ	dddZ
dd ZdddZdddZdd Zedkree  Zee dS )    N)partialcompile_dircompile_filecompile_path
   c             c   s"  |dk rt | tjrt| } |s0td|  yt| }W n. tk
rl   |dk rdtd|  g }Y nX |  x|D ]}|dkrq|tj	
| |}|d k	rtj	
||}nd }tj	|s||fV  q||dkr||tjkr||tjkr|tj	|r|tj	|s|t|||d |dE d H  q|W d S )N   zListing {!r}...zCan't list {!r}__pycache__r      )ddir	maxlevelsquiet)
isinstanceosPathLikefspathprintformatlistdirOSErrorsortpathjoinisdircurdirpardirislink	_walk_dir)dirr
   r   r   namesnamefullnamedfile r"   ,/opt/hscpipe/8.4/lib/python3.7/compileall.pyr      s0    


r   Fr	   c
             C   s   d }
|d k	rP|dk rt dn2|dkrPyddlm}
 W n tk
rN   d}Y nX t| |||d}d}|d k	r|dkr|
d k	r|pd }|
|d0}|tt||||||	d|}t|dd	}W d Q R X n,x*|D ]"\}}t	||||||||	sd
}qW |S )Nr   z%workers must be greater or equal to 0r	   )ProcessPoolExecutor)r   r   r
   T)max_workers)forcerxr   legacyoptimizeinvalidation_mode)defaultF)

ValueErrorconcurrent.futuresr%   ImportErrorr   mapr   _compile_file_tupleminr   )r   r   r
   r'   r(   r   r)   r*   workersr+   r%   files_and_ddirssuccessexecutorresultsfiler!   r"   r"   r#   r   2   s6    


c             K   s   | \}}t ||f|S )N)r   )file_and_dfilekwargsr8   r!   r"   r"   r#   r1   e   s    r1   c          
   C   s  d}|dk r"t | tjr"t| } tj| }	|d k	rFtj||	}
nd }
|d k	rd|| }|rd|S tj| r|r| d }nB|dkr|dkr|nd}t	j
j| |d}nt	j
| }tj|}|	d d |	dd   }}|d	kr|sZyVtt| j}td
t	j
jd|}t|d}|d}W d Q R X ||kr@|S W n tk
rX   Y nX |sntd|  ytj| ||
d||d}W n tjk
r } zbd}|dkr|S |rtd|  ntddd |jjtjjdd}| tjj}t| W d d }~X Y n~ t!t"tfk
rz } zJd}|dkr6|S |rLtd|  ntddd t|j#j$d | W d d }~X Y nX |dkrd}|S )NTr   cr   r	    )optimizationz.pyz<4sllrb   zCompiling {!r}...)r*   r+   Fz*** Error compiling {!r}...z*** )endbackslashreplace)errors:)%r   r   r   r   r   basenamer   searchisfile	importlibutilcache_from_sourcedirnameintstatst_mtimestructpackMAGIC_NUMBERopenreadr   r   r   
py_compilecompilePyCompileErrormsgencodesysstdoutencodingdecodeSyntaxErrorUnicodeError	__class____name__)r    r
   r'   r(   r   r)   r*   r+   r5   r   r!   mocfileopt	cache_dirheadtailmtimeexpectchandleactualokerrrW   er"   r"   r#   r   j   sz    






$
c       	      C   sX   d}xNt jD ]D}|r|tjkr4| r4|dk rPtd q|oNt||d |||||d}qW |S )NTr   zSkipping current directory)r   r)   r*   r+   )rY   r   r   r   r   r   )	skip_curdirr   r'   r   r)   r*   r+   r5   r   r"   r"   r#   r      s    
c              C   s  dd l } | jdd}|jddddddd	 |jd
tddd |jddddd |jdddddd |jddddd |jdddd dd |jd d!d"d d#d |jd$d%d&d'd( |jd)d*d+d,d- |jd.d/d0td1d2 d3d4 tjD }|jd5t|d6d7 | }|j}|j	r$dd l
}||j	|_	|jd k	r8|j}n|j}|jryJ|jd8krZtjnt|j$}x|D ]}||  qlW W d Q R X W n2 tk
r   |jd9k rtd:|j d;S X |jd k	r|jpd |_|jr|jd8d< }	tj|	 }
nd }
d=}y|rxp|D ]h}tj|rTt||j |j!|j	|j|j"|
d>sd;}n,t#|||j |j!|j	|j|j"|j|
d?	sd;}qW |S t$|j"|j!|j|
d@S W n* t%k
r   |jd9k rtdA d;S X d=S )BNr   z1Utilities to support installing Python libraries.)descriptionz-lstore_constr   r   z!don't recurse into subdirectories)actionconstr,   desthelpz-r	recursionzhcontrol the maximum recursion level. if `-l` and `-r` options are specified, then `-r` takes precedence.)typers   rt   z-f
store_truer'   z/force rebuild even if timestamps are up to date)rq   rs   rt   z-qcountr   zIoutput only error messages; -qq will suppress the error messages as well.)rq   rs   r,   rt   z-br)   z0use legacy (pre-PEP3147) compiled file locationsz-dDESTDIRr
   zdirectory to prepend to file paths for use in compile-time tracebacks and in runtime tracebacks in cases where the source file is unavailable)metavarrs   r,   rt   z-xREGEXPr(   zskip files matching the regular expression; the regexp is searched for in the full path of each file considered for compilationz-iFILEflistzzadd all the files and directories listed in FILE to the list considered for compilation; if "-", names are read from stdin)rz   rs   rt   compile_destzFILE|DIR*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.path)rz   nargsrt   z-jz	--workersr	   zRun compileall concurrently)r,   rv   rt   c             S   s   g | ]}|j  d dqS )_-)r   lowerreplace).0moder"   r"   r#   
<listcomp>	  s   zmain.<locals>.<listcomp>z--invalidation-modezset .pyc invalidation mode; defaults to "checked-hash" if the SOURCE_DATE_EPOCH environment variable is set, and "timestamp" otherwise.)choicesrt   r   r   zError reading file list {}Fr   T)r+   )r3   r+   )r)   r'   r   r+   z
[interrupted])&argparseArgumentParseradd_argumentrL   rT   PycInvalidationModesorted
parse_argsr~   r(   rerU   ru   r   r}   rY   stdinrR   appendstripr   r   r   r   r3   r+   r   upperr   r   rG   r   r
   r'   r)   r   r   KeyboardInterrupt)r   parserinvalidation_modesargscompile_destsr   r   flineivl_moder+   r5   rs   r"   r"   r#   main   s    









"





r   __main__)Nr   r   )	r   NFNr   Fr$   r	   N)NFNr   Fr$   N)r	   r   Fr   Fr$   N)r   rY   importlib.utilrH   rT   rO   	functoolsr   __all__r   r   r1   r   r   r   r`   rL   exit_statusexitr"   r"   r"   r#   <module>   s*   

  
1  
T  
 l