ó LzñWc@s¶dZddlZddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZddlmZd efd „ƒYZdS( s§ LaTeX document building system for Rubber. This module contains all the code in Rubber that actually does the job of building a LaTeX document from start to finish. iÿÿÿÿN(t_tmsg(tWatcher(t LogParser(t TexParser(tModules(tDependtLatexcBs§eZd„Zd„Zd„Zd„Zd„Zd„Zdd„Z d„Z dd „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„ZRS(cCsãtj||ƒd|_d|_d|_d|_d|_d|_d|_ d|_ g|_ d|_ d|_ d|_tƒ|_tƒ|_t|ƒ|_t|ƒ|_d|_t|_t|_d|_g|_dS(NtlatextTeXtii(Rt__init__tNonetlogfiletauxfiletsrcfiletsrcbasetoutfiletprogramtenginetpapertprodst must_compiletsomething_donet failed_moduleRtwatcherRtlogRtmodulesRtparsertdatetFalset draft_onlyt draft_supporttbatchtopts(tselftmaker((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyR s,                  cCs|j|jƒdS(N(R tenv(R#((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pytreinit0scCsntjj|ƒ|_tjj|jƒd|_|j|_|jd|_|jd|_|j dƒdS(Nis.logs.auxtdvi( tostpathtrealpathRtsplitextRtsrc_baseR Rt set_format(R#tinput((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyt set_source4s  cCs'|jd||_|jg|_dS(Nt.(RRR(R#tformat((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyR-<scCs|jr dStjtdƒƒ|j rWtjj|jƒ rWtj tdƒƒdStjj|j ƒsƒtj tdƒƒdS|j rÎtjj |jƒtjj |j ƒkrÎtj tdƒƒdS|jj |j ƒrútj tdƒƒdS|jƒS(s Returns true if a first compilation is needed. This method supposes that no compilation was done (by the script) yet. is%checking if compiling is necessary...sthe output file doesn't existsthe log file does not exists*the source is younger than the output files#the log file is not produced by TeX(RRRRR R(R)texistsRtdebugR tgetmtimeRtreadtrecompile_needed(R#((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pytcompile_needed@s"   *cCs0|jjƒ}|jrdS|jjƒrBtjtdƒƒdS|rŒt|ƒdksm|d|j krŒtjtdƒ|dƒdS|jj ƒrÏtjtdƒƒ|sËtjtdƒƒdSdS|rtjtdƒ|dƒ|j dkrtjtd ƒƒdSntjtd ƒƒdS( s† Returns true if another compilation is needed. This method is used when a compilation has already been done. islast compilation failedisthe %s file has changedsLaTeX asks to run againsbut the aux files are unchangeds/the %s file has changed but no re-run required?txelatexs"force recompilation (XeTeX engine)sno new compilation is needed( RtupdateRRterrorsRR3RtlenRt run_neededR(R#tchanged((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyR6Ws. + cCs3t|jƒ}|jj|d|ƒ|jƒdS(s Prepare the compilation by parsing the source file. The parsing loads all the necessary modules required by the packages used, etc. t exclude_modsN(topenRRtparsetclose(R#R>tf((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pytpreparexscCs|jddƒdS(Ntforcei(trun(R#((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyt force_runsicCsÊ|j|ƒrdS||_d|_|jrA|jjdƒn|pP|jƒ}x6|r‹|jƒrldS|j ƒr|dS|j ƒ}qVWd|_|j ƒr¥dS|j rÆt tjƒƒ|_ndS(sˆ Run the building process until the last compilation, or stop on error. This method supposes that the inputs were parsed to register packages and that the LaTeX source is ready. If the second (optional) argument is true, then at least one compilation is done. As specified by the class Depend, the method returns 0 on success and 1 on failure. is-interaction=batchmodeiN(t pre_compilet failed_depR RR!R"tappendR7tcompilet post_compileR6t last_compileRtintttimeR(R#RDt need_compile((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRE„s&         cCsyx)d D]!}|jj|jd|ƒqWtjtdƒƒx3|jjjƒD]}|j ƒrR||_ dSqRWdS( s7 Prepare the source for compilation using package-specific functions. This function must return true on failure. This function sets `must_compile' to 1 if we already know that a compilation is needed, because it may avoid some unnecessary preprocessing (e.g. BibTeXing). tauxttoctlottlofR0sbuilding additional files...ii(RPRQRRRS( RtwatchRRRRRtobjectstvaluesRGR(R#RDtexttmod((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRG¦s   cCsMtjtdƒƒx3|jjjƒD]}|jƒr&||_dSq&WdS(sš Run the package-specific operations that are to be performed after each compilation of the main source. Returns true on failure. s#running post-compilation scripts...ii(RRRRRURVRKR(R#RX((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRK¸s   cCsMtjtdƒƒx3|jjjƒD]}|jƒr&||_dSq&WdS(s Run the module-specific operations that are to be performed after the last compilation of the main source. Returns true on failure. s#running last-compilation scripts...ii(RRRRRURVRLR(R#RX((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRLÅs   cCsÓd|_|jg|jtjj|jƒg}tjdj |ƒƒt j |dtj ƒ}|dkr‰tj tdƒ|jƒn|jj|jƒr¼tj tdƒ|jƒdS|jjƒrÏdS|S(Nit tstdouts %s failedsCould not run %s.i(RRR"R(R)tbasenameRRRtjoint subprocesstcallRZterrorRR5R R:(R#tcmdtrc((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRJÒs ) c Csc|jddddddddgƒtjtd ƒƒx$|jjjƒD]}|jƒqKWd S( sD Remove all files that are produced by compilation. s.logs.auxs.tocs.lofs.lots.outs.glos.cbscleaning additional files...N(tremove_suffixesRRRRRURVtclean(R#RX((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRcás cCs[xT|D]L}|j|}tjj|ƒrtjtdƒ|ƒtj|ƒqqWdS(sk Remove all files derived from the main source with one of the specified suffixes. s removing %sN(R,R(R)R2RRRtunlink(R#tlisttsuffixtfile((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRbïs   cCs'|js|jjƒS|jjƒSdS(N(RRt get_errors(R#((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRhús  cCsüg}x2|jjƒD]!}|j|d|dfƒqWtt|ƒƒ}|jƒxž|D]–}y|djdƒ}Wn|djdƒ}nXt|ƒdkrÕtj dt |ƒ|d|dfƒq^tj d|d|dfƒq^Wd S( sl Sort the characters not handled by the selected font, and print them as a warning. tuchartfontitutf8tlatin1is$Character U+%X (%s) not in font '%s'sCharacter '%s' not in font '%s'N( Rt get_misscharsRIRetsettsorttdecodeR;Rtwarntord(R#t missed_charstctmRi((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pytprint_misscharss   "N(t__name__t __module__R R&R/R-R7R6R RCRFRERGRKRLRJRcRbRhRv(((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyRs"      !  "    (t__doc__R(tsysRNR]RRtutilRt logparserRt texparserRtpluginsRR$RR(((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/latex.pyts