۶eTc@s|dZdZddd!ZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddlmZdd lmZmZdd lmZejd Zejd Zd ZdefdYZdfdYZde jdZdeZdZ de!fdYZ"dZ#dZ$e%dkrxe"j&ndS(sCheetah command-line interface. 2002-09-03 MSO: Total rewrite. 2002-09-04 MSO: Bugfix, compile command was using wrong output ext. 2002-11-08 MSO: Another rewrite. Meta-Data ================================================================================ Author: Tavis Rudd and Mike Orr > Version: $Revision: 1.26 $ Start Date: 2001/03/30 Last Revision Date: $Date: 2007/10/02 01:22:04 $ sETavis Rudd and Mike Orr s$Revision: 1.26 $i iiN(t OptionParser(tVersion(tTemplatetDEFAULT_COMPILER_SETTINGS(tmkdirsWithPyInitFiless^-{1,2}s^[a-zA-Z_][a-zA-Z_0-9]*$cGsQ|ddkr|d }n |d7}|r:||}n|}|j|dS(Nit^s (twrite(tstreamtformattargstmessage((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pytfprintfMessages   tErrorcBseZRS((t__name__t __module__(((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR (stBundlecBs eZdZdZdZRS(sxWrap the source, destination and backup paths in one neat little class. Used by CheetahWrapper.getBundles(). cKs|jj|dS(N(t__dict__tupdate(tselftkw((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyt__init__0scCs d|jS(Ns (R(R((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyt__repr__3s(R Rt__doc__RR(((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR,s tcCs^|jt|j|d}|rM|jd|jd|d}ntj|dS(sGWrite help text, an optional error message, and abort the program. is s*** USAGE ERROR ***: %s iN(Rt WRAPPER_TOPtsystexit(t usageMessaget errorMessagetoutt exitStatus((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pytusage:s    s7 __ ____________ __ \ \/ \/ / \/ * * \/ CHEETAH %(Version)s Command-Line Tool \ | / \ ==----== / by Tavis Rudd \__________/ and Mike Orr sUSAGE: ------ cheetah compile [options] [FILES ...] : Compile template definitions cheetah fill [options] [FILES ...] : Fill template definitions cheetah help : Print this help message cheetah options : Print options help message cheetah test [options] : Run Cheetah's regression tests : (same as for unittest) cheetah version : Print Cheetah version number You may abbreviate the command to the first letter; e.g., 'h' == 'help'. If FILES is a single "-", read standard input and write standard output. Run "cheetah options" for the list of valid options. tCheetahWrappercBseZeZdZdZdZdZddZ dZ dZ dZ dZ dZdZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZRS(s.bakcCsCd|_d|_d|_d|_g|_g|_d|_dS(N(tNonetprogNametcommandtoptstpathArgst sourceFilest searchListtparser(R((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyRks      cCs;|dkrtj}nyktjj|d|_}tjd|d|_ }|dkrq|d|_ n|j |dWnt k rt tdnX|j|j|j|j|j|jf}xU|D]M}|j}|d}|||fkrtjdcd|7<|dSqWt td |dS( sThe main program controller.iRittestis!not enough command-line argumentst Nsunknown command '%s'(R!RtargvtostpathtbasenameR"toptionDashesREtsubR#ttestOptst parseOptst IndexErrorRt HELP_PAGE1tcompiletfillthelptoptionsR)tversionR (RR+R"R#tmethstmethtmethNamet methInitial((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pytmainws(       cCs|j|j|j}}}|jddk|_}|rCdpFd}t|_|jj}|ddddd d d d d |dddddd d d d|dddddd dd d|dddddd |d d|dddddd td d|ddddddd td d|d dd!dd"d t d d#|d$dddd%d td d&|d'dddd(d td d)|d*dddd+d d d d,|d-dddd.d td d/|d0dddd1d td d2|d3dddd4d dd d5|d6dddd7d d8|d9dddd:d dd d;|d<ddd=d>dd?d d@d dA|dBddCd dDd dE|jj |\}} ||_ t jdFkr"g} x@| D]8} tj| } | r| j| q| j| qW| } n| |_|dG|tjt|| |jrdOGHdHGHdIdJlm} | }|jdKdLx|D]}dM|GHqWt jdngtjtjgD]}|r|^q}xqd dgD]c}xZ|D]R}t||d}|r|j|r|t | }t!|||PqqWqW|j"|j#r~|j$j%dtj&n|j'rt(|j'dN}t'j)|}|j*|j$j%d|ndS(PNitcs.pys.htmls--idirtactiontstoretdesttidirtdefaultRR7s/Input directory (defaults to current directory)s--odirtodirs0Output directory (defaults to current directory)s--iexttiexts.tmpls<File input extension (defaults: compile: .tmpl, fill: .tmpl)s--oexttoexts;File output extension (defaults: compile: .py, fill: .html)s-Rt store_truetrecurses6Recurse through subdirectories looking for input filess--stdouts-ptstdouts2Send output to stdout instead of writing to a files--quiett store_falsetverboses-Do not print informational messages to stdouts--debugtdebugs,Print diagnostic/debug information to stderrs--envtenvs)Pass the environment into the search lists--pickletpickles4Unpickle FILE and pass it through in the search lists--flattflats'Do not build destination subdirectoriess --nobackuptnobackups1Do not make backup files when generating new oness --settingstcompilerSettingsStringscString of compiler settings to pass through, e.g. --settings="useNameMapper=False,useFilters=False"s--print-settingstprint_settingss1Print out the list of available compiler settingss--templateAPIClassttemplateClassNames\Name of a subclass of Cheetah.Template.Template to use for compilation, e.g. MyTemplateClasss --parallelttypetinttparallelis5Compile/fill templates in parallel, e.g. --parallel=4s--shbangtshbangs#!/usr/bin/env pythonsbSpecify the shbang to place at the top of compiled templates, e.g. --shbang="#!/usr/bin/python2.6"twin32s.cheetah compile %s Options are %s Files are %ss'>> Available Cheetah compiler settings:i(t_DEFAULT_COMPILER_SETTINGStkeycSs|ddjS(Ni(tlower(tl((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pytss %s (default: "%s") %strb((+tchatterRMtwarnR#t isCompileRR(t add_optiontFalsetTrueR!t parse_argsR$RtplatformtglobtextendtappendR%tpprinttpformattvarsRStCheetah.CompilerRZtsortRR,tseptaltseptgetattrtendswithtlentsetattrt_fixExtsRNR'tinserttenvironROtopentloadtclose(RR tCtDtWRbt defaultOexttpaoR$tfilest new_filestspect file_listRZtlistingR]RptsepstattrR-tft unpickled((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR2sx  """""%""""""""(       +      cCs|jdS(N(t_compileOrFill(R((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR5scCs%ddlm}||jdS(Ni(tinstall(tCheetah.ImportHooksRR(RR((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR6scCsttdtjdS(NR(RR4RRJ(R((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR7scCs |jjS(N(R(t print_help(R((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR8scCsd}yt|d}WntjdnX|jtj|ddlm}ddl}d}d|j krd}nd |j krd }n|j d |}|j |j |j }tt|j dS( Ns&cheetah_test_file_creation_ability.tmptwsCannot run the tests because you don't have write permission in the current directory. The tests need to create temporary files. Change to a directory you do have write permission to and re-run the tests.i(tTestis-qis-vit verbosity(RyRRR{R,tremovet Cheetah.TestsRtunittestR1tTextTestRunnertrunt TestSuitetsuitesRVt wasSuccessful(RtTEST_WRITE_FILENAMERRRRtrunnertresults((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR)s$      cCs tGHdS(N(R(R((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR9 scGs4|jjs|jj rdSttj||dS(stPrint a verbose message to stdout. But don't if .opts.stdout is true or .opts.verbose is false. N(R$RJRLR R(RRR ((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR`scGs&|jjr"ttj||ndS(sVPrint a debugging message to stderr, but don't if .debug is false. N(R$RMR Rtstderr(RRR ((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyRMs cGsttj||dS(s2Always print a warning message to stderr. N(R RR(RRR ((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyRa$scGs$ttj||tjddS(sVAlways print a warning message to stderr and exit with an error code. iN(R RRR(RRR ((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyterror)scCso|jj|jj}}|rB|jd rBd||j_n|rk|jd rkd||j_ndS(Nt.(R$RFRGt startswith(RRFRG((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyRv3s csw|j|j|j}}}|j|j}}|dgkrM|jdS| r|jr|jrldpod}|d|g}tj j |jjtj }tj j ||j |n.|sttdn|j||jt}g|D]} tj j| ^q}|d||j|} |dtj| |jjr`|j| n|jjdkrUd } tfd } x| r| j} tj}|rj|n|j| tjd t |jjkr| } | rPqqqWx"r7| }| s|} qqW| rstjd | qsnx| D]} |j| q\WdS( Nt-RCtcurrents,Drilling down recursively from %s directory.sNeither files nor -R specified!sAll source files found: %ssAll bundles: %siics,tj\}}j|tj|S(N(R,twaitRt WEXITSTATUS(tpidtstatus(tpid_pool(sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyt child_wait_s s)Child process failed, exited with code %d(!R`RMRaR$R%t_compileOrFillStdinRIRCR,R-tjointcurdirtwalkt_expandSourceFilesWalkRR4t_expandSourceFilesRetnormpatht _getBundlesRkRlRPt_checkForCollisionsRWtsettpoptforktaddt_compileOrFillBundleRRRt(RR|R}R~R$RtwhichR&tdirtxtbundlestbad_child_exitRtbRt child_exit((RsC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR=sV  %               c Cs|j|j|j}}}t}i}xJ|D]B}|j|kr_||jj|jq0|jg||j %s^s (backup %s)Rsn%s: base name %s contains invalid characters. It must be named according to the same rules as Python modules.RRt moduleNamet classNametcommandlineoptsRR'R("R`RMRaRRRRRR.R,R-RRbRR$RQRR!t moduleNameREtmatchR R5RdRR'tshutiltcopyfileRtmakedirsRJRRRyR{(RRR|R}R~RRRRRR.tdstDirRRttupRRttclassR((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR9sN                 N(R RRet MAKE_BACKUPSRR!RRRR>R2R5R6R7R8R)R9R`RMRaRRvRRRRRRRRR(((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyR es6 " M         A   ! * "  cCstjdS(N(R R>(((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyt_cheetahkscCs$tjjddtjdS(NiR5(RR+RwR R>(((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyt_cheetah_compileost__main__('Rt __author__t __revision__tgetoptRhR,RktreRRtcPickleROtoptparseRtCheetah.VersionRtCheetah.TemplateRRtCheetah.Utils.MiscRR5R/RR t ExceptionR RRRtglobalsRR4tobjectR RRR R>(((sC/opt/freeware/lib/python2.7/site-packages/Cheetah/CheetahWrapper.pyts. T