[A& @sdZddlZddlZddlZddlZddlZdddgZdddddddd dZddddddd dZ ddddddd dZ d d Z e dkre e ZejendS)aModule/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 Fc Cs|stdj|nytj|}Wn+tk r\tdj|g}YnX|jd} x|D]} | dkrqtntjj|| } |dk rtjj|| } nd} tjj| st | ||||||sd} qqt|dkrt| tj krt| tj krttjj| rttjj |  rtt | |d| |||||sd} qqtqtW| 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 zListing {!r}...zCan't list {!r}r __pycache__Nr)printformatoslistdirOSErrorsortpathjoinisdirrcurdirpardirislinkr) dir maxlevelsddirforcerxquietlegacyoptimizenamessuccessnamefullnamedfiler! /usr/lib/python3.4/compileall.pyrs4        *%cCs d}tjj|}|dk r<tjj||} nd} |dk rj|j|} | rj|Sntjj|r |r|trdnd} nL|dkrtjj |d| } ntjj |} tjj | } |dd|dd} }|dkr |synt tj |j }tjd tjj|}t| d }|jd }WdQX||kr|SWqtk rYqXn|std j|ny"tj|| | d d|}Wn tjk rw}zt|rtdj|ntddd|jjtjjdd}|jtjj}t|d}WYdd}~Xqtt tfk r}zN|rtdj|ntdddt|j!j"d|d}WYdd}~XqX|dkrd}qq n|S)aByte-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 rNcordebug_overridez.pyz<4slrbzCompiling {!r}...Trz*** Error compiling {!r}...z*** enderrorsbackslashreplace:r.)#r rbasenamersearchisfile __debug__ importlibutilcache_from_sourcedirnameintstatst_mtimestructZpack MAGIC_NUMBERopenreadr rr py_compilecompilePyCompileErrormsgencodesysstdoutencodingdecode SyntaxError UnicodeError __class____name__)rrrrrrrrrr ZmocfileZ cache_dirheadtailmtimeZexpectZchandleZactualokerrrAer!r!r"r@sj    !        c Cstd}xgtjD]\}| s,|tjkr?|r?tdq|oit||d|d|d|d|}qW|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) rzSkipping current directoryNrrr)rCrr rrr)Z skip_curdirrrrrrrrr!r!r"rs   c Cs4ddl}|jdd}|jdddddd d d d d d|jdddd dd d|jdddd dd d|jdddd dd d|jdddd dd dd d|jdddd d d dd d!|jd"dd#d d$d d%|jd&dd'd(d)d d*|j}|j}|jrt|d+ksutjj |d r|j d,n|j rddl }|j |j |_ n|jrEyX|jd-krtjn t|j+}x!|D]}|j|jqWWdQXWqEtk rAtd.j|jd/SYqEXnd0}y|rx|D]}tjj|rt||j|j|j |j|jsd/}qq[t||j|j|j|j |j|js[d/}q[q[W|Std|jd|jd|jSWn tk r/td1d/SYnXd0S)2zScript main program.rNZ descriptionz1Utilities to support installing Python libraries.z-lactionZ store_constZconstdefaultrdestrhelpz!don't recurse into subdirectoriesz-f store_truerz/force rebuild even if timestamps are up to datez-qrzoutput only error messagesz-brz0use legacy (pre-PEP3147) compiled file locationsz-dmetavarZDESTDIRrzdirectory to prepend to file paths for use in compile-time tracebacks and in runtime tracebacks in cases where the source file is unavailablez-xZREGEXPrzskip files matching the regular expression; the regexp is searched for in the full path of each file considered for compilationz-iZFILEflistzzadd all the files and directories listed in FILE to the list considered for compilation; if "-", names are read from stdin compile_destzFILE|DIRnargs*zrzero or more file and directory names to compile; if no arguments given, defaults to the equivalent of -l sys.pathrz2-d destdir requires exactly one directory argument-zError reading file list {}FTz [interrupted]) argparseArgumentParser add_argument parse_argsrYrlenr rrexitrrer?rXrCstdinr<appendstripr rr r1rrrrrrrKeyboardInterrupt) r]parserargsZ compile_destsrcflinerrTr!r!r"mainsn         * !         rl__main__rnrn)__doc__r rCimportlib.utilr3r>r:__all__rrrrlrJr7Z exit_statusrbr!r!r!r" s       * J  L