zfc@sldZddlmZddlZddlZddlZddlZddlZddlZddl Z e ej drdZ ndZ ej dZej dZej d Zej d ZeefZejZejZd ZiZd ZiZd ZdfdYZdfdYZdZedkrhy eZWnek rddGHnXndS(s3Find modules used by a script, using introspection.i(t generatorsNtnewlinestUtrt LOAD_CONSTt IMPORT_NAMEt STORE_NAMEt STORE_GLOBALccsd}t|}d}x||krt||}|}|d}d}|tkrt||t||dd|}d}|d}|tkr|d}qn|||fVqWdS(Niiiii(tlentordtNonet HAVE_ARGUMENTt EXTENDED_ARG(tcodet extended_argtntitoptoffsettarg((s$/usr/lib64/python2.7/modulefinder.pyt_unpack_opargss   *  cCs-tj|g}|j||t| Noneisdetermine_parent ->t.srelative importpath too deep( R>R?R R!R#R1tAssertionErrortcountt ImportErrortjoinRLtrfind(R'RVR:tpnameRXR((s$/usr/lib64/python2.7/modulefinder.pyRRsB             cCs/|jdd||d|krL|jd}|| }||d}n |}d}|rtd|j|f}n|}|j|||}|r|jdd||f||fS|r |}d}|j|||}|r |jdd||f||fSn|jdd|td |dS( NiRSR\iRAs%s.%ssfind_head_package ->s"raise ImportError: No module namedsNo module named (R>tfindR!t import_moduleR?R R_(R'RXR(RtheadRZtqnameRY((s$/usr/lib64/python2.7/modulefinder.pyRSs.    cCs|jdd|||}x|r|jd}|dkrOt|}n|| ||d}}d|j|f}|j|||}|s|jdd|td|qqW|jdd ||S( NiRTR\iis%s.%ss"raise ImportError: No module namedsNo module named s load_tail ->(R>RcRR!RdR?R_(R'RYRZR[RRetmname((s$/usr/lib64/python2.7/modulefinder.pyRTs  cCs|jdd|||x|D]}|dkri|s|j|}|rf|j||dqfqq t||s d|j|f}|j|||}|std|qq q WdS(NiRUt*is%s.%ssNo module named (R=tfind_all_submodulesRUthasattrR!RdR_(R'R[RWt recursivetsubtalltsubnametsubmod((s$/usr/lib64/python2.7/modulefinder.pyRUs  c Cs|js dSi}g}x%tjD]}|j|dq&Wx|jD]}ytj|}Wn*tjk r|jdd|qKnXxp|D]h}d}x:|D]2} t | } || | kr|| }PqqW|r|dkr|||simport_module -> None( R>R1tKeyErrorR?R2R R#t find_moduleR_RGtclosetsetattr(R'tpartnametfqnameRXR[RIRHRJ((s$/usr/lib64/python2.7/modulefinder.pyRds6  " c Csr|\}}}|jdd||o'd||tjkrf|j||}|jdd||S|tjkrt|jd|d} nr|tjkr|jdtj kr|jdd|t d |n|jdt j |} nd} |j|}||_| r[|jr?|j| } n| |_|j| |n|jdd||S( NiRGRIsload_module ->s texecis#raise ImportError: Bad magic numbersBad magic number in %s(R>REt PKG_DIRECTORYt load_packageR?RFtcompiletreadt PY_COMPILEDt get_magicR_tmarshaltloadR t add_moduleR"R6treplace_paths_in_codeR$t scan_code( R'R~RIRHt file_infotsuffixtmodettypeR[tco((s$/usr/lib64/python2.7/modulefinder.pyRG-s0    cCsQ||jkri|j|( R>RRRR"R#RRzRGR?R{(R'R~RHRR[RItbufRJ((s$/usr/lib64/python2.7/modulefinder.pyRs    cCs5||jkr|j|St||j|<}|S(N(R1R (R'R~R[((s$/usr/lib64/python2.7/modulefinder.pyRs cCs|dk r |jd|}n|}||jkrT|jdd|t|n|dkr|tjkrddddtjffS|j }ntj ||S(NR\isfind_module -> ExcludedRA( R R!R5R?R_R0tbuiltin_module_namesREt C_BUILTINRRz(R'R(RRXR((s$/usr/lib64/python2.7/modulefinder.pyRzs    cCs<HddGHddGH|jj}|jxE|D]=}|j|}|jrVdGndGd|G|jpndGHq3W|j\}}|rHd GHxH|D]=}|j|j}|jd G|Gd Gd j|GHqWn|r8Hd GdGHxH|D]=}|j|j}|jd G|Gd Gd j|GHqWndS(sPrint a report to stdout, listing the found modules with their paths, as well as modules that are missing, or seem to be missing. s %-25s %stNametFiles----tPR[s%-25sRAsMissing modules:t?s imported froms, s7Submodules that appear to be missing, but could also bes#global names in the parent package:N(RR(s----s----(R1RstsortR#R"tany_missing_maybeR2R`(R'RstkeyR[tmissingtmaybeR(tmods((s$/usr/lib64/python2.7/modulefinder.pytreports6        !  cCs|j\}}||S(sReturn a list of modules that appear to be missing. Use any_missing_maybe() if you want to know which modules are certain to be missing, and which *may* be missing. (R(R'RR((s$/usr/lib64/python2.7/modulefinder.pyt any_missingscCs"g}g}x|jD]}||jkr1qn|jd}|dkr_|j|qn||d}|| }|jj|}|dk r||j|kr|j|q||jkrq|jr|j|q|j|q|j|qW|j |j ||fS(sReturn two lists, one with modules that are certainly missing and one with modules that *may* be missing. The latter names could either be submodules *or* just global names in the package. The reason it can't always be determined is that it's impossible to tell which names are imported when "from module import *" is done with an extension module, short of actually importing it. R\iiN( R2R5RaRR1RR R%R&R(R'RRR(RRntpkgnametpkg((s$/usr/lib64/python2.7/modulefinder.pyRs0        cCstjj|j}}x>|jD]3\}}|j|r#||t|}Pq#q#W|jr||jkr||kr|j dd||fn|j dd|f|jj |nt |j }xMt t|D]9}t||t|r|j||||R?R@RPRQRRRSRTRURiRdRGRRtstructRRRRRRRzRRRR(((s$/usr/lib64/python2.7/modulefinder.pyR/^s4     #          6    %  .cCs"ddl}y#|jtjdd\}}Wn|jk rM}|GHdSXd}d}g}g}x|D]\}} |dkr|d}n|dkrd}n|dkr|| jtj}n|dkrd}n|d krm|j| qmqmW|sd } n |d} tj} tjj | | d<|| } |dkrxd GHx | D]} d Gt | GHq\Wnt | ||} xz|dD]n}|dkrd}qn|r|d dkr| j |d ddgq| j |q| j|qW| j| | j| S(Niisdmp:qx:is-ds-ms-ps-qs-xshello.pyspath:s is.*Rh(tgetoptR0targvRrRLRKtpathsepRRtdirnameR9R/RQR RPR@R(RtoptsR<R=R3tdomodstaddpathtexcludetotatscriptRtitemtmfR((s$/usr/lib64/python2.7/modulefinder.pyttesthsX #                 RBs [interrupt]( t__doc__t __future__RtdisRERRKR0RRRjt __stdout__RDtopmapRRRRRR R RRRRRR R/RR!RtKeyboardInterrupt(((s$/usr/lib64/python2.7/modulefinder.pytsB                   ;