
bc           @   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  Z d d d d d	  Z	 d
 d d d d  Z
 d   Z d   Z e d k r e e    Z e j e  n  d S(   s  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.
iNt   compile_dirt   compile_filet   compile_pathi
   i    c         C   sc  | s d G|  Gd GHn  y t  j |   } Wn# t  j k
 rN d G|  GHg  } n X| j   d } x | D] } t  j j |  |  }	 | d k	 r t  j j | |  }
 n d }
 t  j j |	  s t |	 | | | |  s[d } q[qf | d k rf | t  j	 k rf | t  j
 k rf t  j j |	  rf t  j j |	  rf t |	 | d |
 | | |  s[d } q[qf qf W| S(   s  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 1, force compilation, even if timestamps are up-to-date
    quiet:     if 1, be quiet during compilation
    t   Listings   ...s
   Can't listi   i    N(   t   ost   listdirt   errort   sortt   patht   joint   Nonet   isdirR   t   curdirt   pardirt   islinkR    (   t   dirt	   maxlevelst   ddirt   forcet   rxt   quiett   namest   successt   namet   fullnamet   dfile(    (    s    /usr/lib/python2.7/compileall.pyR       s2    	

	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| d  | d }	 }
 |
 d k r| s>y t t  j |   j	  } t
 j d t j   |  } |  t r d p d } t | d   } | j d  } Wd	 QX| | k r&| SWq>t k
 r:q>Xn  | sTd
 G|  Gd GHn  y t j |  d	 | t  } Wn[ t j k
 r} | rd
 G|  Gd GHn  | j GHd } qt k
 r} d G| GHd } qX| d k rd } qqn  | S(   sI  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 1, force compilation, even if timestamps are up-to-date
    quiet:     if 1, be quiet during compilation
    i   is   .pys   <4slt   ct   ot   rbi   Nt	   Compilings   ...i    t   Sorry(   R   R   t   basenameR
   R	   t   searcht   isfilet   intt   statt   st_mtimet   structt   packt   impt	   get_magict	   __debug__t   opent   readt   IOErrort
   py_compilet   compilet   Truet   PyCompileErrort   msg(   R   R   R   R   R   R   R   R   t   mot   headt   tailt   mtimet   expectt   cfilet   chandlet   actualt   okt   errt   e(    (    s    /usr/lib/python2.7/compileall.pyR   =   sL    		
i   c         C   sc   d } xV t  j D]K } | s, | t j k r: |  r: d GHq | oX t | | d | d | } q W| S(   s  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 0)
    quiet: as for compile_dir() (default 0)
    i   s   Skipping current directoryR   N(   t   sysR   R   R   R    R
   (   t   skip_curdirR   R   R   R   R   (    (    s    /usr/lib/python2.7/compileall.pyR   q   s    
c         C   s   |  } | r yV | d k r( t  j } n t |  } x+ | j   } | sM Pn  | j | d   q7 WWq t k
 r d | GH  q Xn  | S(   s&   read names in flist and append to argst   -is   Error reading file list %s(   R=   t   stdinR*   t   readlinet   appendR,   (   t   argst   flistt   expandedt   fdt   line(    (    s    /usr/lib/python2.7/compileall.pyt   expand_args   s    	
c          C   s  d d l  }  y# |  j  t j d d  \ } } Wnk |  j k
 r } | GHd GHHd GHd GHHd GHd	 GHd
 GHd GHd GHd GHd GHd GHd GHd GHt j d  n Xd } d } d } d } d } d }	 x | D] \ }
 } |
 d k r d } n  |
 d k r | } n  |
 d k rd } n  |
 d k r(d } n  |
 d k rRd d l } | j |  } n  |
 d k r | }	 q q W| rt |  d k rt	 j
 j | d  rd GHt j d  qn  d } y | s|	 rty |	 rt | |	  } n  Wn t k
 rd } n X| r}xk | D]` } t	 j
 j |  rIt | | | | | |  sjd } qjq
t | | | | |  s
d } q
q
Wq}n	 t   } Wn t k
 rd GHd } n X| S(   s   Script main program.iNi   s	   lfqd:x:i:sb   usage: python compileall.py [-l] [-f] [-q] [-d destdir] [-x regexp] [-i list] [directory|file ...]sT   arguments: zero or more file and directory names to compile; if no arguments given, s4              defaults to the equivalent of -l sys.paths   options:s%   -l: don't recurse into subdirectoriess3   -f: force rebuild even if timestamps are up-to-dates   -q: output only error messagessX   -d destdir: directory to prepend to file paths for use in compile-time tracebacks and insL               runtime tracebacks in cases where the source file is unavailablesX   -x regexp: skip files matching the regular expression regexp; the regexp is searched forsC              in the full path of each file considered for compilationsT   -i file: add all the files and directories listed in file to the list considered fors7            compilation; if "-", names are read from stdini   i
   i    s   -ls   -ds   -fs   -qs   -xs   -is1   -d destdir require exactly one directory arguments   
[interrupted](   t   getoptR=   t   argvR   t   exitR
   t   reR.   t   lenR   R   R   RH   R,   R    R   R   t   KeyboardInterrupt(   RI   t   optsRC   R1   R   R   R   R   R   RD   R   t   aRL   R   t   arg(    (    s    /usr/lib/python2.7/compileall.pyt   main   s    # 	 	 	 	 )

t   __main__(   t   __doc__R   R=   R-   R%   R'   t   __all__R
   R    R   R   RH   RR   t   __name__R"   t   exit_statusRK   (    (    (    s    /usr/lib/python2.7/compileall.pyt   <module>   s   '4		J