LzWc@sdZddlZddlTddlZddlZddlZddlZddlmZm Z ddl m Z m Z ddl m Z ddlmZddd YZd dd YZd dd YZde fdYZejdZejdZde fdYZdS(s9 Indexing support with package 'index'. This module handles the processing of the document's indices using a tool like makeindex or xindy. It stores an MD5 sum of the source (.idx) file between two runs, in order to detect modifications. The following directives are provided to specify options for makeindex: tool = Choose which indexing tool should be used. Currently this can be either "makeindex" (by default) or "xindy". language = Choose the language used for sorting the index (xindy only). modules ... = Specify which modules xindy should use for the index. order = Modify the ordering to be used (makeindex only, supported by xindy with warnings). The argument must be a space separated list of: - standard = use default ordering (no options, this is the default) - german = use German ordering (option "-g") - letter = use letter instead of word ordering (option "-l") path = Add the specified directory to the search path for styles. style = Use the specified style file. They all accept an optional argument first, enclosed in parentheses as in "index.path (foo,bar) here/", to specify which index they apply to. Without this argument, they apply to all indices declared at the point where they occur. iN(t*(tPopentPIPE(t_tmsg(t TexModule(tmd5_filetXindycBsneZdZdd d dddZdZdZdZdZdZ dZ d Z d Z RS( s Xindy command wrapper tc Cs||_||_||_||_|p-g|_|p<g|_||_d|_tj j tj j t d} |j | |_tjdtjtjB|_g|_dS(NtXINDY_SEARCHPATHs xindylang.xmlshyperindexformat{\\(.*?)}}{(tdoctidxfilettargett transcripttoptstmodulest index_langtpath_vartostpathtjointdirnamet__file__t map_languagest languagestretcompiletMtDOTALLt_re_hyperindextinvalid_index_ranges( tselfR R R R RRRtstyletmapfile((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt__init__9s      ! cCsti}tjjj|}xH|jdD]7}|jd}|jd}|r+|||t j t d |jj|fd d nd}|rZ|jd|gnx$|jD]}|jd|gqdW|jr|j|jn|j|j|S(Ntxelatextxindys-Mttexindys-Cs-qs page-rangess-os-tsxindy: lang '%s' not foundtpkgtindexsxindy: lang '%s' mapped to '%s's-L(R tprogramtextendtencodingR R RR$RtgetRtwarnRtlogtNoneRRtappendR (RtcmdR$tmod((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pytcommandUs6"         cCshtjd}t|}d}x6|D].}|j|}|r(|jd}Pq(q(W|j|S(Ns%loading module "lang/.*/(latin[^.-]*)Ri(RRtopentsearchtgrouptclose(Rtlognametre_langtlogfileR6tlinetm((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt_find_index_encodings   cCsYt|jd}t}x0|D](}y|jdWqt}PqXqW|j|S(Ntrtutf8(tfileR tTruetdecodetFalseRB(Rtft is_unicodeRF((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt_index_is_unicodes   cCst|jd}|j}|j|jjd|\}}|sMdStjd|t|jd}|j||jdS(NRIs\1}{s.Remove %d unsupported 'hyperindexformat' callstw( RKR treadRBRtsubnRtdebugtwrite(RROtdatatnsub((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt_sanitize_idxfiles   cCs6|js dSt|j}|j}|jxPt|D]B\}}x3|jD](}|j|krU|j||qUqUWq?Wg}x+|jD] }|j|j |j qW|sdSt j d|j|f|j |jx|D] }||=qWt|jd}|j||jdS(Ns0xindy: lines to remove from %s to fix ranges: %sRR(RR?R t readlinesRBt enumeratet index_keytadd_lineR5t skip_linestreinitRRUtsorttreverset writelines(RROtlinestiRFtentryR^tline_num((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt_fix_invalid_rangess0         cCs|jr dStjd|tj}t}xy|D]q}d|krMt}q2|r2tjd|tjtjB}|r|jjt |j dnt}q2q2WdS(Ns(WARNING:|ERROR:)tWARNINGs>Found.*?-range .*Location-reference is \d+ in keyword \((.*)\)i( RRtsplitRRNRLR@RR;t IndexentryRA(RRWtblockstcheck_next_blocktblockRG((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt_detect_invalid_rangess     "c Cs|j|j|j}tjdj|tt|jd}t|d}t |d|dt }|j d}|j }tj rtj j|ntjt|j|j|dkrtjtd|jdS|j||dd kr|jjd kr|js|j|}tt|jd }d d |dd d||jg}tjdj|tj|}|dkrtj||jqqn|S(Nt s xindy.logRRtstdouttstderriiscould not make index %sR1RJsnew.indticonvs-fs-ts-o(RYRgR>RRURRR R?RRt communicatetwaitRpRVR8RtstripRBterrorRnR R6RQRHt subprocesstcallRtrename( RR<RCREtpterrdatatrcR6ttmpindex((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pytruns8        "  N( t__name__t __module__t__doc__R:R"RR>RHRQRYRgRnR~(((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR5s /    RjcBs>eZdZejdejZdZdZdZ RS(sQ Index entry wrapper from idxfile. Its role is to detect range anomalies s%\indexentry{(.*)\|([\(\)]?).*}{(\d+)}cCs1||_g|_d|_d|_t|_dS(Nii(R\R^tlast_range_pagetlast_range_lineRNtlast_range_open(RR\((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR" s     cCs|j|jdS(N(R"R\(R((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR_scCs$|jj|}|sdS|jdjdd}||jkrKdS|jd}t|jd}|dkr||jkr|j|j|g7_n||_||_t |_ n]|dkr||_||_t |_ n3|dkr |j t kr |j|g7_q ndS( Nit!iiit(t)R( t _re_entryR@RARiR\tintRR^RRLRRN(RRft indexentryRGR\t range_statetpage((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR]s*         ( RRRRRRRR"R_R](((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyRjs   t MakeindexcBsAeZdZddddddZdZdZdZRS(s# Makeindex command wrapper Rc CsI||_||_||_||_|p-g|_d|_||_dS(Nt INDEXSTYLE(R R R R RRR ( RR R R R RRRR ((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR"8s     cCsqdd|jg|j}|jr;|jd|jgn|jr]|jd|jgn|j|j|S(Nt makeindexs-os-ts-s(R RR R5R R;R (RR<((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR>Cs  cCsYt|jd}t}x0|D](}y|jdWqt}PqXqW|j|S(NRIRJ(RKR RLRMRNRB(RRORPRF((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyRQLs   cCs|j}tjdj|tj|dtj}|dkrdtjtd|j dS|j r|j j dkr|j stjtdd|_ |jSn|S( NRoRqiscould not make index %siRJs"makeindex on UTF8 failed. Retry...R(R>RRURRwRxRpRvRR R R R6RQR8R~(RR<R|((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR~Xs     N(RRRR:R"R>RQR~(((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR4s tIndexcBsheZdZdZdZdZdZdZdZdZ dZ d Z d Z RS( s/ This class represents a single index. cCs-t|_||_|j|_|jd||_|jd||_|jd||_|jrtj j |jtj krtj j |j|_tj j |j|_ntj j |jrt|j|_n d|_d|_d|_d|_g|_g|_g|_ d|_dS(s Initialize the index, by specifying the source file (generated by LaTeX), the target file (the output of makeindex) and the transcript (e.g. .ilg) file. Transcript is used by glosstex.py. t.RN(RLtparanoidR tsrc_basetpbasetsourceR R RRRtgetcwdtbasenametexistsRtmd5R:ttoolttool_objR$RRR (RR RR R ((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR"ss&   *       cCs ||_dS(N(R$(RR$((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt do_languagescGs|jj|dS(N(RR5(Rtargs((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt do_modulesscGsx{|D]s}|dkr%g|_q|dkrD|jjdq|dkrc|jjdqtjtd|qWdS(Ntstandardtgermans-gtletters-ls'unknown option '%s' for 'makeidx.order'(RR;RR8R(RRtopt((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pytdo_orders    cCs |jj|jj|dS(N(RR;R tabspath(RR((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pytdo_pathscCs ||_dS(N(R (RR ((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pytdo_stylescCs3|dkr&tjtd|n||_dS(NRR0sunknown indexing tool '%s'(RR0(RRvRR(RR((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pytdo_tools cCstjj|js9tjtd|jdddS|jsIdStjtd|j|j s|j dkrt }n|j dkrt }n||j |j|jd|jd |jd |jd |jd |j|_ n|j j}|dkr |Sd |j _dS(s& Run the indexer tool sstrange, there is no %sR2R3isprocessing index %sRR0R RRRR i(RRRRRR9Rt run_neededtprogressRRRRR R R RRR$R R~t must_compile(Rt index_clsR|((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt post_compiles0             cCstjj|jdkr?tjtd|jdddSt|j}tjj|j sp||_ dS|j s||_ tjtd|jdddS|j |krtjtd|jdddS||_ tjtd|jdddS( s Check if makeindex has to be run. This is the case either if the target file does not exist or if the source file has changed. isthe index file %s is emptyR2R3isthe index file %s is newsthe index %s did not changesthe index %s has changed( RRtgetsizeRRR9RRRR R(Rtnew((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyRs"        cCs`xY|j|j|jfD]?}t|rtjtd|ddtj|qqWdS(sB Remove all generated files related to the index. s removing %sR2R3N( RR R RRR9RRR,(RRK((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pytcleans ( RRRR"RRRRRRRRR(((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyRos       " s& *{(?P[^{}]*)} *{(?P[^{}]*)}s\((?P[^()]*)\) *tModulecBsGeZdZdZdZdZdZdZdZRS(cCsT||_i|_g|_i|_|jjd|j|jjd|jdS(s6 Initialize the module with no index. RtnewindexN(R tindicestdefaultstcommandstparsertadd_hookRR(RR tdict((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR"s     cCst|j|||}|j|Rthas_key(RtnametidxtindtilgR3R<((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pytregisters #cCs|jdddddS(s. Register the standard index. tdefaultRRRN(R(RR((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR scCsrtj|d}|sdS|d}|j}|j||d|ddtjtd|dd dS( s' Register a new index. RFNtargRRRsindex %s registeredR2R3(t re_newindextmatcht groupdictRRR9R(RRRGR3td((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyRs  cCs|j}d}t|dkrbtj|d}|rb|jdjd}|d}qbn|dkr|jj||g|j }nx}|D]u}|j |r||j ||dq|j j |r|j |j||gq||gg|j |R(RR<RRtnamesRGR3((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR>s    cCs.x'|jjD]}|jrdSqWdS(Nii(RtvaluesR(RR3((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR.s cCs(x!|jjD]}|jqWdS(Ni(RRR(RR3((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyR4s( RRR"RRRR>RR(((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyRs   ((((RRtos.pathRtstringRwtxml.dom.minidomR&RRRRtpluginsRtutilRRRjRRRRRR(((sA/usr/lib/python2.7/dist-packages/dbtexmf/dblatex/grubber/index.pyt's     -;