
[[\A&              	   @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d d g Z d d d d d d d d	 d  Z d d d d d d d
 d  Z	 d d d d d d d d  Z
 d d   Z e d k r e e    Z e j e  n  d S)a  Module/script to byte-compile all .py files to .pyc (or .pyo) 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compile_dircompile_filecompile_path
   F   c             C   s  | s t  d j |    n  y t j |   } Wn+ t k
 r\ t  d j |    g  } Yn X| j   d }	 x| D]}
 |
 d k r qt n  t j j |  |
  } | d k	 r t j j | |
  } n d } t j j |  st	 | | | | | | |  sd }	 qqt | d k rt |
 t j
 k rt |
 t j k rt t j j |  rt t j j |  rt t | | d | | | | | |  sd }	 qqt qt W|	 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:     if True, be quiet during compilation
    legacy:    if True, produce legacy pyc paths instead of PEP 3147 paths
    optimize:  optimization level or -1 for level of the interpreter
    zListing {!r}...zCan't list {!r}r   __pycache__Nr   )printformatoslistdirOSErrorsortpathjoinisdirr   curdirpardirislinkr   )dir	maxlevelsddirforcerxquietlegacyoptimizenamessuccessnamefullnamedfile r!    /usr/lib/python3.4/compileall.pyr      s4    
*%c             C   s  d } t  j j |   } | d k	 r< t  j j | |  }	 n d }	 | d k	 rj | j |   }
 |
 rj | Sn  t  j j |   r	| r |  t r d n d } nL | d k r t j j	 |  d | } n t j j	 |   } t  j j
 |  } | d d  | d d  } } | d k r	| syn t t  j |   j  } t j d	 t j j |  } t | d
   } | j d  } Wd QX| | k r| SWqt k
 rYqXn  | st d j |    n  y" t j |  | |	 d d | } Wnt j k
 rw} zt | rt d j |    n t d d d | j j t j j d d } | j t j j  } t |  d } WYd d } ~ Xqt t  t f k
 r} zN | rt d j |    n t d d d t | j! j" d |  d } WYd d } ~ XqX| d k rd } qq	n  | S)a  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:     if True, be quiet during compilation
    legacy:    if True, produce legacy pyc paths instead of PEP 3147 paths
    optimize:  optimization level or -1 for level of the interpreter
    r   Ncor   debug_override   z.pyz<4slrb   zCompiling {!r}...Tr   z*** Error compiling {!r}...z*** end errorsbackslashreplace:r.   )#r
   r   basenamer   searchisfile	__debug__	importlibutilcache_from_sourcedirnameintstatst_mtimestructZ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   r   r    ZmocfileZ	cache_dirheadtailmtimeZexpectZchandleZactualokerrrA   er!   r!   r"   r   @   sj    	!		
c             C   st   d } xg t  j D]\ } | s, | t j k r? |  r? t d  q | oi t | | d | d | 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 False)
    legacy: as for compile_dir() (default False)
    optimize: as for compile_dir() (default -1)
    r   zSkipping current directoryNr   r   r   )rC   r   r
   r   r   r   )Zskip_curdirr   r   r   r   r   r   r   r!   r!   r"   r      s    c        	      C   s4  d d l  }  |  j d d  } | j d d d d d d	 d
 d d d d | j d d d d d d d | j d d d d d d d | j d d d d d d d | j d d d d d d	 d d d | j d d d d d  d	 d d d! | j d" d d# d d$ d d% | j d& d d' d( d) d d* | j   } | j } | j rt |  d+ k sut j j	 | d  r| j
 d,  n  | j rd d l } | j | j  | _ n  | j rEyX | j d- k rt j n t | j  + } x! | D] } | j | j    qWWd QXWqEt k
 rAt d. j | j   d/ SYqEXn  d0 } y | rx | D] } t j j |  rt | | j | j | j | j | j  sd/ } qq[t | | j | j | j | j | j | j  s[d/ } q[q[W| St d | j d | j d | j  SWn  t k
 r/t d1  d/ SYn Xd0 S)2zScript main program.r   NZdescriptionz1Utilities to support installing Python libraries.z-lactionZstore_constZconstdefaultr   destr   helpz!don't recurse into subdirectoriesz-f
store_truer   z/force rebuild even if timestamps are up to datez-qr   zoutput only error messagesz-br   z0use legacy (pre-PEP3147) compiled file locationsz-dmetavarZDESTDIRr   zdirectory to prepend to file paths for use in compile-time tracebacks and in runtime tracebacks in cases where the source file is unavailablez-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compile_destzFILE|DIRnargs*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.pathr   z2-d destdir requires exactly one directory argument-zError reading file list {}FTz
[interrupted]) argparseArgumentParseradd_argument
parse_argsrY   r   lenr
   r   r   exitr   rer?   rX   rC   stdinr<   appendstripr   r   r	   r1   r   r   r   r   r   r   r   KeyboardInterrupt)	r]   parserargsZcompile_destsrc   fliner   rT   r!   r!   r"   main   sn    					*!
	rl   __main__rn   rn   )__doc__r
   rC   importlib.utilr3   r>   r:   __all__r   r   r   rl   rJ   r7   Zexit_statusrb   r!   r!   r!   r"   <module>   s    *JL