qLc@s6dZdZddlZddlZddlZddlZddlZddlmZm Z m Z ej Z ej Z ej Z yeWnek rdZnXeZidZejZedkrejdkrdZnerdZn d Zd Zd Zd Zd ZdZde fdYZejdZdZde fdYZ!ddgidZ"dZ#dddgidZ$e%efZ&e'e fZ(e'e)e fZ*e+ee fZ,e+efZ-e.e&dZ/e.e(dZ0e.e*dZ1e.e)dZ2e.e,dZ3e.e,e*dZ4e.e,e*dZ5e.e,e*e5d Z6e.e,e*e5d!Z7e.e+e e-d"Z8e.e+e8e-e*e d#Z9e9e:d$Z;iZ<Z=d%Z>e>e=e%Zee!Zfd?Zgd@e fdAYZhdBefdCYZidDeifdEYZjejd<krdFZkn dGZkeldHZmdIZnddJZodKZpdLe fdMYZqdNe fdOYZrdPe fdQYZsdRZtddSZudTZvelZwdUZxdVdWZyyddlzZzWneRk rn.Xe{ezdXre|ZwdYZxdVdZZynd[Z}d\Z~d]e fd^YZd_efd`YZ[dS(as/SCons.Util Various utility functions go here. s7src/engine/SCons/Util.py 5023 2010/06/14 22:05:46 sconsiN(tUserDicttUserListt UserStringcCs.x't||D]\}}|||>> someList = NodeList([ ' foo ', ' bar ' ]) >>> someList.strip() [ 'foo', 'bar' ] cCst|jdkS(Ni(tlentdata(tself((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt __nonzero__rscCsdjtt|jS(Nt (tjointmapRR$(R%((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt__str__uscCs t|jS(N(titerR$(R%((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt__iter__xscOs2g|jD]}|||^q }|j|S(N(R$t __class__(R%targstkwargstxR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt__call__{s%cCs2g|jD]}t||^q }|j|S(N(R$tgetattrR-(R%tnameR0R((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt __getattr__s%(t__name__t __module__t__doc__R&R*R,R1R4(((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyR"hs      s!^\$([_a-zA-Z]\w*|{[_a-zA-Z]\w*})$cCsTtjt|}|rL|jd}|ddkrE|dd!S|SndSdS(sGiven a string, first determine if it looks like a reference to a single environment variable, like "$FOO" or "${FOO}". If so, return that variable with no decorations ("FOO"). If not, return None.iit{iN(t _get_env_vartmatcht to_StringtgrouptNone(tvarstrtmotvar((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytget_environment_vars t DisplayEnginecBs#eZeZddZdZRS(icCsR|js dS|r |d}nytjjt|Wntk rMnXdS(Ns (tprint_ittsyststdouttwritetunicodetIOError(R%ttexttappend_newline((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyR1s   cCs ||_dS(N(RC(R%tmode((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytset_modes(R5R6tTrueRCR1RL(((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRBs ic Cst|}||}d}x/|d D]#}|rB|d}q)|d}q)W||krl|d|dS|d|d}|stj|}nd ||sc Cst|}|r|dkredddddddd d d d }tjjt|nd g}|jdt|j|jdt|jo|j |jdddgt|j ddgt|j |jdt|j |jdt|j |jdt|j |jdt|j|jdt|j|jdt|j|jdng}d} tt| |d } ||} |r#||kr#| r#tjjdj|| d|dgddStjjdj|| d |gdd||<| r|jdt|} x+| d D]} t| ||| ||qWd|dscCs |||S(N((RvRwttuple((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytis_TupleAscCs |||S(N((RvRwt StringTypes((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt is_StringDscCs|||p||| S(N((RvRwRR|((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt is_ScalarGscCsQxJ|D]B}|||s,||| r<|j|qt||qWdS(N(RPt do_flatten(tsequenceRRwRR|titem((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRPs cCs}|||s||| r&|gSg}xJ|D]B}|||sX||| rh|j|q3|||q3W|S(sFlatten a sequence to a non-nested list. Flatten() converts either a single scalar or a nested sequence to a non-nested list. Note that flatten() considers strings to be scalars instead of sequences like Python would. (RP(RvRwRR|RRR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytflattenXs cCsWg}xJ|D]B}|||s2||| rB|j|q |||q W|S(sFlatten a sequence to a non-nested list. Same as flatten(), but it does not handle the single scalar case. This is slightly more efficient when one knows that the sequence to flatten can not be a scalar. (RP(RRwRR|RRR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytflatten_sequencejs  cCs7|||r|S|||r)|jS||SdS(N(R$(tsRwRRtBaseStringTypes((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyR;s c Cs}|||r|S|||rYg}x!|D]}|jt|q/Wdj|S|||ro|jS||SdS(NR'(RPtto_String_for_substR(R$( RRwRR;RR|Rtlte((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRs  cCs3y |j}Wn|k r'||SX|SdS(N(t for_signature(RvRtAttributeErrortf((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytto_String_for_signatures    cCs7i}x*|jD]\}}t|||scCsG|jdd}||d }||}t||}t||S(s%This utility function returns a value in the registry without having to open the key first. Only available on Windows platforms with a version of Python that can read the registry. Returns the same thing as SCons.Util.RegQueryValueEx, except you just specify the entire path to the value, and don't have to bother opening the key first. So: Instead of: k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion') out = SCons.Util.RegQueryValueEx(k, 'ProgramFilesDir') You can write: out = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir') s\i(R t RegOpenKeyExtRegQueryValueEx(RSRtptkeypRR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt RegGetValueHs  t WindowsErrorcBseZRS((R5R6(((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRjscCs tdS(N(R(RSR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRvscCs tdS(N(R(RSR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRyscCs|dkr5ytjd}Wq5tk r1dSXnt|rV|jtj}n|dkrytjd}Wqtk rd}qXnt|r|jtj}nx>|D]6}|j|t| jkrdg}PqqWt | rt | r|g}nx|D]}tj j ||}xb|D]Z}||}tj j |rAy|j|WqAtk rtj j|SXqAqAqAWqWdS(NtPATHtPATHEXTs.COM;.EXE;.BAT;.CMDR(R=RtenvirontKeyErrorRtsplittpathseptlowerR#R{RRR(tisfiletindext ValueErrortnormpath(tfileRtpathexttrejecttexttdirRtfext((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytWhereIs~s>        #      tos2cCsg|dkr5ytjd}Wq5tk r1dSXnt|rV|jtj}n|dkrqddg}nx>|D]6}|j|t| jkrxdg}PqxqxWt | rt | r|g}nx|D]}tj j ||}xb|D]Z}||}tj j |ry|j|Wqtk rTtj j|SXqqqWqWdS(NRs.exes.cmdR(R=RRRRRRRR#R{RRR(RRRR(RRRRRRRR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRs4     #      cCsCddl}|dkrAytjd}WqAtk r=dSXnt|rb|jtj}nt| rt | r|g}nx|D]}tj j ||}tj j |rytj|}Wnt k rqnX|j||jd@r;y|j|Wqtk r1tj j|SXqq;qqWdS(NiRiI(tstatR=RRRRRRR{RRR(RtOSErrortS_IMODEtST_MODERRR(RRRRRtdRtst((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRs0         c Cs+|}d}|}t| rDt| rD|j|}d}nt|rb|j|}n,t| rt| r|g}n|}|rtt||}n|sg} g} xa|D]Y} | sqntjjtjj | } | | kr| j | | j | qqW|j xd|D]\} | sEq3ntjjtjj | } | | kr3| j d| | j | q3q3W| }nt||}g} g}x[|D]S} tjjtjj | } | r| | kr|j | | j | qqW|r|S|j |SdS(sThis prepends newpath elements to the given oldpath. Will only add any particular path once (leaving the first one it encounters and ignoring the rest, to preserve path order), and will os.path.normpath and os.path.normcase all paths to help assure this. This can also handle the case where the given old path variable is a list instead of a string, in which case a list will be returned instead of a string. Example: Old Path: "/foo/bar:/foo" New Path: "/biz/boom:/foo" Result: "/biz/boom:/foo:/foo/bar" If delete_existing is 0, then adding a path that exists will not move it to the beginning; it will stay where it is in the list. If canonicalize is not None, it is applied to each element of newpath before use. iiN(R{RRRRnR)RRRtnormcaseRPtreversetinsertR(( toldpathtnewpathRtdelete_existingt canonicalizetorigtis_listtpathstnewpathsRt normpathsRR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt PrependPathsV             c Cs|}d}|}t| rDt| rD|j|}d}nt|rb|j|}n,t| rt| r|g}n|}|rtt||}n|szg} g} xL|D]D} | sqn| j| | jtjj tjj | qWxa|D]Y} | s&qntjj tjj | } | | kr| j| | j| qqW| }n||}|j g} g}x[|D]S} tjj tjj | } | r| | kr|j| | j| qqW|j |r |S|j |SdS(sThis appends new path elements to the given old path. Will only add any particular path once (leaving the last one it encounters and ignoring the rest, to preserve path order), and will os.path.normpath and os.path.normcase all paths to help assure this. This can also handle the case where the given old path variable is a list instead of a string, in which case a list will be returned instead of a string. Example: Old Path: "/foo/bar:/foo" New Path: "/biz/boom:/foo" Result: "/foo/bar:/biz/boom:/foo" If delete_existing is 0, then adding a path that exists will not move it to the end; it will stay where it is in the list. If canonicalize is not None, it is applied to each element of newpath before use. iiN( R{RRRRnR)RPRRRRRR(( RRRRRRRRRRRRR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt AppendPath/sT     )         tcygwincCs#tjd|jjddS(sTransforms an absolute path into a native path for the system. In Cygwin, this converts from a Cygwin path to a Windows one.s cygpath -w s R(Rtpopentreadtreplace(R((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytget_native_pathscCs|S(suTransforms an absolute path into a native path for the system. Non-Cygwin version, just leave the path alone.((R((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCs=t|st|r|St|r2|jS|gSdS(N(R{RRR(targ((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytSplits   tCLVarcBs>eZdZgdZdZdZdZdZRS(sA class for command-line construction variables. This is a list that uses Split() to split an initial string along white-space arguments, and similarly to split any strings that get added. This allows us to Do the Right Thing with Append() and Prepend() (as well as straight Python foo = env['VAR'] + 'arg1 arg2') regardless of whether a user adds a list or a string to a command-line construction variable. cCstj|t|dS(N(RRR(R%tseq((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCstj|t|S(N(Rt__add__R(R%R((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCstj|t|S(N(Rt__radd__R(R%R((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCs|t|fS(N(R(R%R((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyt __coerce__scCsdj|jS(NR'(R(R$(R%((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyR*s(R5R6R7RRRRR*(((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRs      t OrderedDictcBsqeZd dZdZdZdZdZdZdZ dZ d dZ d Z d Z RS( cCsg|_tj||dS(N(t_keysRR(R%tdict((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRs cCs$tj|||jj|dS(N(Rt __delitem__Rtremove(R%R((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCs9tj|||||jkr5|jj|ndS(N(Rt __setitem__RRP(R%RR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCstj|g|_dS(N(RtclearR(R%((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRs cCst}|j||S(N(Rtupdate(R%R((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRNs  cCs"tt|jt|jS(N(RnRRR(R%((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCs|jS(N(R(R%((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCsLy|jd}Wntk r0tdnX||}||=||fS(Nisdictionary is empty(Rt IndexErrorR(R%RR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pytpopitems  cCs9tj|||||jkr5|jj|ndS(N(Rt setdefaultRRP(R%Rtfailobj((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCs1x*|jD]\}}|j||q WdS(N(RR(R%RRR((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRscCstt|j|jS(N(RnR)RR(R%((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRsN(R5R6R=RRRRRNRRRRRR(((sZ/home/als/proj/qrscanner/ext/qrscanner/zxing/scons/scons-local-2.0.0.final.0/SCons/Util.pyRs         tSelectorcBseZdZddZRS(sA callable ordered dictionary that maps file suffixes to dictionary values. We preserve the order in which items are added so that get_suffix() calls always return the first suffix added.cCs|dkr:y|dj}Wq:tk r6d}q:Xny ||SWntk ri}xq|jD]c\}}|dk ri|j|}||krt||d||n||f||s>                   & Y               1                          !QP    2#    M  [ )