B
    w2[3              	   @   s   d Z ddlZddlZddlZddlZddlZyddlmZ W n e	k
rT   dZY nX ddl
mZ dddgZdd	d
Zddddddddejjf	ddZddddddejjfddZddddddejjfddZdd Zedkree  Zee dS )a  Module/script to byte-compile all .py files to .pyc files.

When called as a script with arguments, this compiles the directories
given as arguments recursively; the -l option prevents it from
recursing into directories.

Without arguments, if compiles all modules on sys.path, without
recursing into subdirectories.  (Even though it should do so for
packages -- for now, you'll have to deal with packages separately.)

See module py_compile for details of the actual byte-compilation.
    N)ProcessPoolExecutor)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|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#   $/root/Python-3.7.0/Lib/compileall.pyr      s0    


r   Fr
   c
             C   s   |dk	r|dk rt dt| |||d}
d}|dk	r|dkrtdk	r|pJd}t|d2}|tt|||||||	d|
}t|dd	}W dQ R X n(x&|
D ]}t||||||||	sd
}qW |S )a  Byte-compile all modules in the given directory tree.

    Arguments (only dir is required):

    dir:       the directory to byte-compile
    maxlevels: maximum recursion level (default 10)
    ddir:      the directory that will be prepended to the path to the
               file as it is compiled into each byte-code file.
    force:     if True, force compilation, even if timestamps are up-to-date
    quiet:     full output with False or 0, errors only with 1,
               no output with 2
    legacy:    if True, produce legacy pyc paths instead of PEP 3147 paths
    optimize:  optimization level or -1 for level of the interpreter
    workers:   maximum number of parallel workers
    invalidation_mode: how the up-to-dateness of the pyc will be checked
    Nr   z%workers must be greater or equal to 0)r   r   r   Tr
   )Zmax_workers)r   forcerxr   legacyoptimizeinvalidation_mode)defaultF)
ValueErrorr   r   mapr   r   min)r   r   r   r&   r'   r   r(   r)   workersr*   filessuccessZexecutorresultsfiler#   r#   r$   r   6   s*    

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 )aT  Byte-compile one file.

    Arguments (only fullname is required):

    fullname:  the file to byte-compile
    ddir:      if given, the directory name compiled in to the
               byte-code file.
    force:     if True, force compilation, even if timestamps are up-to-date
    quiet:     full output with False or 0, errors only with 1,
               no output with 2
    legacy:    if True, produce legacy pyc paths instead of PEP 3147 paths
    optimize:  optimization level or -1 for level of the interpreter
    invalidation_mode: how the up-to-dateness of the pyc will be checked
    Tr   N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*   r1   r    r"   mocfileopt	cache_dirheadtailmtimeZexpectZchandleactualokerrrP   er#   r#   r$   r   a   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 )a  Byte-compile all module on sys.path.

    Arguments (all optional):

    skip_curdir: if true, skip current directory (default True)
    maxlevels:   max recursion level (default 0)
    force: as for compile_dir() (default False)
    quiet: as for compile_dir() (default 0)
    legacy: as for compile_dir() (default False)
    optimize: as for compile_dir() (default -1)
    invalidation_mode: as for compiler_dir()
    Tr   zSkipping current directoryN)r   r(   r)   r*   )rR   r   r   r   r   r   )	Zskip_curdirr   r&   r   r(   r)   r*   r1   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/d0d1td2d3 d4d5 tjD }|jd6d7t|d8d9 | }|j}|j	r&ddl
}||j	|_	|jdk	r:|j}n|j}|jryJ|jd:kr\tjnt|j$}x|D ]}||  qnW W dQ R X W n2 tk
r   |jd;k rtd<|j d=S X |jdk	r|jpd|_|jd:d> }	tj|	 }
d?}y|r~xp|D ]h}tj|rHt||j |j!|j	|j|j"|
d@std=}n,t#|||j |j!|j	|j|j"|j|
dA	sd=}qW |S t$|j"|j!|j|
dBS W n* t%k
r   |jd;k rtdC d=S X d?S )DzScript main program.r   Nz1Utilities 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.)typeri   rj   z-f
store_truer&   z/force rebuild even if timestamps are up to date)rg   ri   rj   z-qcountr   zIoutput only error messages; -qq will suppress the error messages as well.)rg   ri   r+   rj   z-br(   z0use legacy (pre-PEP3147) compiled file locationsz-dZ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)metavarri   r+   rj   z-xZREGEXPr'   zskip files matching the regular expression; the regexp is searched for in the full path of each file considered for compilationz-iZFILEflistzzadd all the files and directories listed in FILE to the list considered for compilation; if "-", names are read from stdin)ro   ri   rj   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)ro   nargsrj   z-jz	--workersr
   zRun compileall concurrently)r+   rl   rj   c             S   s   g | ]}|j  d dqS )_-)r    lowerreplace).0moder#   r#   r$   
<listcomp>   s   zmain.<locals>.<listcomp>z--invalidation-mode	timestampz+How the pycs will be invalidated at runtime)r+   choicesrj   ru   r   zError reading file list {}Frt   T)r*   )r/   r*   )r(   r&   r   r*   z
[interrupted])&argparseArgumentParseradd_argumentrE   rM   PycInvalidationModesorted
parse_argsrq   r'   rerN   rk   r   rp   rR   stdinrK   appendstripr   r   r   r   r/   r*   rw   upperr   r   r@   r   r   r&   r(   r   r   KeyboardInterrupt)r}   parserZinvalidation_modesargsZcompile_destsr   r   flineZivl_moder*   r1   ri   r#   r#   r$   main   s    









"






r   __main__)Nr   r   )__doc__r   rR   importlib.utilrA   rM   rH   Zconcurrent.futuresr   ImportError	functoolsr   __all__r   r   Z	TIMESTAMPr   r   r   r   rY   rE   exit_statusexitr#   r#   r#   r$   <module>   s2   


)T f