ó LzñWc@sîdZddlmZddlZddlZddlTddlZddlZddlZddl m Z m Z ddl m Z ej dƒZej dƒZej d ƒZej d ƒZd e fd „ƒYZd efd„ƒYZdS(s[ BibTeX support for Rubber This module is a special one: it is triggered by the macros \bibliography and \bibliographystyle and not as a package, so the main system knows about it. The module provides the following commands: path = adds to the search path for databases stylepath = adds to the search path for styles iÿÿÿÿ(t generatorsN(t*(t_tmsg(t TexModules\\bibdata{(?P.*)}s\\citation{(?P.*)}s4LaTeX Warning: Citation `(?P.*)' .*undefined.*s=---(line (?P[0-9]+) of|while reading) file (?P.*)tBibTexcBs¡eZdZdd„Zd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„Zd„Zd„ZRS(sÀ This class is the module that handles BibTeX in Rubber. It provides the funcionality required when compiling documents as well as material to parse blg files for diagnostics. cCs¼||_|j|_|s*|j|_n ||_|jd|_|jd|_|jd|_g|_g|_d|_ d|_ d|_ |j dƒi|_d|_d|_dS(sî Initialize the state of the module and register appropriate functions in the main process. The extra arugment 'base' can be used to specify the base name of the aux file, it defaults to the document name. s.bbls.blgs.auxtplainiiN(tdoctenvtsrc_basetbasetbblfiletblgfiletauxfiletbib_pathtbst_pathtNonet undef_citest used_citeststylet set_styletdbtsortedt run_needed(tselfRtdictR ((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyt__init__-s"           cCs |jj|jj|ƒƒdS(N(RtappendRtabspath(Rtpath((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pytdo_pathUscCs |jj|jj|ƒƒdS(N(RRRR(RR((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyt do_stylepathXscCs|dk|_dS(Nttruetyest1(R R!R"(R(Rtmode((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyt do_sorted[scCswxp|jD]e}t||dƒ}t|ƒr ||j|i(t bibtex_neededRR4RR9(R((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyt post_compileòs cCs tjtdƒ|jƒi}t|jƒdkrgtj|jtj ddƒgdƒtj dtstdoutis*There were errors making the bibliography.(RtprogressRR tlenRtstringR%tostgetenvtenvironRt subprocesstcallRfterrorRRR8(RRtrc((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyR9üs & &!   cCsT|jr dStjtdƒddƒ|jƒ\}}|jdk r”|j|kr”tjtdƒddƒ||_||_|jƒ|_ dS||_|jrê||jkrêtjtdƒddƒ||_|jƒ|_ dS||_|j r«|jƒ}|gkr9tjtdƒddƒ||_ qºxF|D]>}||j kr[q@ntjtdƒddƒ||_ dSWtjtd ƒddƒ||_ d Sn|jƒ|_ t |j ƒsætjtd ƒddƒdS|j gkrtjtd ƒddƒd St |j ƒt |j jƒkrPtjtd ƒddƒdSd S(s4 Return true if BibTeX must be run. is!checking if BibTeX must be run...R=R>sthe set of databases changedsthe list of citations changedsno more undefined citationss!there are new undefined citationss"there is no new undefined citationisno BibTeX log filesno undefined citationss'BibTeX's log is older than the main logN(RRR4RR2R3RRR6RR&R R:RR;(RtnewcitesRWtnewRI((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyR`sT             !cCs|jjddgƒdS(Ns.bbls.blg(Rtremove_suffixes(R((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pytcleanZscCs°t|jƒsdSt|jƒ}|jƒ}xq|dkr¡|jdƒr’|jƒdd!|jkr’tjt dƒddƒ|j ƒd Sn|jƒ}q1W|j ƒdS( sÝ Read the log file if it exists and check if the style used is the one specified in the source. This supposes that the style is mentioned on a line with the form 'The style file: foo.bst'. iRcsThe style file: iiüÿÿÿs"the bibliography style was changedR=R>i( R&R R@treadlinet startswithtrstripRRR4RRD(RR4RH((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyREas   ccstt|jƒsdSt|jƒ}d}x;|D]3}tj|ƒ}|r\|jƒdkrntj|ƒ}ntj||jƒ ƒ}|jdƒ}|r«t |ƒ}nidd6dd6|d 6}|j |j ƒƒ|d }|d d kr|d }n|j j |ƒr&|j ||d R=Rotkindttexttfileiüÿÿÿs.bib(R&R R@RBRCtstartRitstripRNtinttupdatet groupdictRR.RD(RR4t last_lineRHR[RytdRz((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyt get_errorsus8     N(t__name__t __module__t__doc__RRRRR$R-RR<R7R2R6RaR9R`RtRER‚(((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyR's" (      # %  I  tModulecBseZdZRS(s+ Module to load to handle a bibtex (RƒR„R…(((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyR†œs(R…t __future__RRjtsystos.pathtreRiRmRRtpluginsRtcompileRORLR_RBRR†(((sB/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/bibtex.pyt s   ÿv