<s> """<STR_LIT>""" <EOL> import os <EOL> from os import path <EOL> import warnings <EOL> from six import iteritems <EOL> from docutils import nodes <EOL> from docutils . io import FileOutput <EOL> from docutils . utils import new_document <EOL> from docutils . frontend import OptionParser <EOL> from sphinx import package_dir , addnodes <EOL> from sphinx . util import texescape <EOL> from sphinx . errors import SphinxError <EOL> from sphinx . locale import _ <EOL> from sphinx . builders import Builder <EOL> from sphinx . environment import NoUri <EOL> from sphinx . util . nodes import inline_all_toctrees <EOL> from sphinx . util . osutil import SEP , copyfile <EOL> from sphinx . util . console import bold , darkgreen <EOL> from sphinx . writers . latex import LaTeXWriter <EOL> class LaTeXBuilder ( Builder ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> format = '<STR_LIT>' <EOL> supported_image_types = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> usepackages = [ ] <EOL> def init ( self ) : <EOL> self . docnames = [ ] <EOL> self . document_data = [ ] <EOL> texescape . init ( ) <EOL> self . check_options ( ) <EOL> def check_options ( self ) : <EOL> if self . config . latex_toplevel_sectioning not in ( None , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . warn ( '<STR_LIT>' % <EOL> self . config . latex_top_sectionlevel ) <EOL> self . config . latex_top_sectionlevel = None <EOL> if self . config . latex_use_parts : <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> if self . config . latex_toplevel_sectioning : <EOL> self . warn ( '<STR_LIT>' ) <EOL> def get_outdated_docs ( self ) : <EOL> return '<STR_LIT>' <EOL> def get_target_uri ( self , docname , typ = None ) : <EOL> if docname not in self . docnames : <EOL> raise NoUri <EOL> else : <EOL> return '<STR_LIT:%>' + docname <EOL> def get_relative_uri ( self , from_ , to , typ = None ) : <EOL> return self . get_target_uri ( to , typ ) <EOL> def init_document_data ( self ) : <EOL> preliminary_document_data = [ list ( x ) for x in self . config . latex_documents ] <EOL> if not preliminary_document_data : <EOL> self . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return <EOL> self . titles = [ ] <EOL> for entry in preliminary_document_data : <EOL> docname = entry [ <NUM_LIT:0> ] <EOL> if docname not in self . env . all_docs : <EOL> self . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' % docname ) <EOL> continue <EOL> self . document_data . append ( entry ) <EOL> if docname . endswith ( SEP + '<STR_LIT:index>' ) : <EOL> docname = docname [ : - <NUM_LIT:5> ] <EOL> self . titles . append ( ( docname , entry [ <NUM_LIT:2> ] ) ) <EOL> def write ( self , * ignored ) : <EOL> docwriter = LaTeXWriter ( self ) <EOL> docsettings = OptionParser ( <EOL> defaults = self . env . settings , <EOL> components = ( docwriter , ) , <EOL> read_config_files = True ) . get_default_values ( ) <EOL> self . init_document_data ( ) <EOL> for entry in self . document_data : <EOL> docname , targetname , title , author , docclass = entry [ : <NUM_LIT:5> ] <EOL> toctree_only = False <EOL> if len ( entry ) > <NUM_LIT:5> : <EOL> toctree_only = entry [ <NUM_LIT:5> ] <EOL> destination = FileOutput ( <EOL> destination_path = path . join ( self . outdir , targetname ) , <EOL> encoding = '<STR_LIT:utf-8>' ) <EOL> self . info ( "<STR_LIT>" + targetname + "<STR_LIT>" , nonl = <NUM_LIT:1> ) <EOL> toctrees = self . env . get_doctree ( docname ) . traverse ( addnodes . toctree ) <EOL> if toctrees : <EOL> if toctrees [ <NUM_LIT:0> ] . get ( '<STR_LIT>' ) > <NUM_LIT:0> : <EOL> tocdepth = toctrees [ <NUM_LIT:0> ] . get ( '<STR_LIT>' ) <EOL> else : <EOL> tocdepth = None <EOL> else : <EOL> tocdepth = None <EOL> doctree = self . assemble_doctree ( <EOL> docname , toctree_only , <EOL> appendices = ( ( docclass != '<STR_LIT>' ) and self . config . latex_appendices or [ ] ) ) <EOL> doctree [ '<STR_LIT>' ] = tocdepth <EOL> self . post_process_images ( doctree ) <EOL> self . info ( "<STR_LIT>" , nonl = <NUM_LIT:1> ) <EOL> doctree . settings = docsettings <EOL> doctree . settings . author = author <EOL> doctree . settings . title = title <EOL> doctree . settings . contentsname = self . get_contentsname ( docname ) <EOL> doctree . settings . docname = docname <EOL> doctree . settings . docclass = docclass <EOL> docwriter . write ( doctree , destination ) <EOL> self . info ( "<STR_LIT>" ) <EOL> def get_contentsname ( self , indexfile ) : <EOL> tree = self . env . get_doctree ( indexfile ) <EOL> contentsname = None <EOL> for toctree in tree . traverse ( addnodes . toctree ) : <EOL> if toctree [ '<STR_LIT>' ] : <EOL> contentsname = toctree [ '<STR_LIT>' ] <EOL> break <EOL> return contentsname <EOL> def assemble_doctree ( self , indexfile , toctree_only , appendices ) : <EOL> self . docnames = set ( [ indexfile ] + appendices ) <EOL> self . info ( darkgreen ( indexfile ) + "<STR_LIT:U+0020>" , nonl = <NUM_LIT:1> ) <EOL> tree = self . env . get_doctree ( indexfile ) <EOL> tree [ '<STR_LIT>' ] = indexfile <EOL> if toctree_only : <EOL> new_tree = new_document ( '<STR_LIT>' ) <EOL> new_sect = nodes . section ( ) <EOL> new_sect += nodes . title ( u'<STR_LIT>' , <EOL> u'<STR_LIT>' ) <EOL> new_tree += new_sect <EOL> for node in tree . traverse ( addnodes . toctree ) : <EOL> new_sect += node <EOL> tree = new_tree <EOL> largetree = inline_all_toctrees ( self , self . docnames , indexfile , tree , <EOL> darkgreen , [ indexfile ] ) <EOL> largetree [ '<STR_LIT>' ] = indexfile <EOL> for docname in appendices : <EOL> appendix = self . env . get_doctree ( docname ) <EOL> appendix [ '<STR_LIT>' ] = docname <EOL> largetree . append ( appendix ) <EOL> self . info ( ) <EOL> self . info ( "<STR_LIT>" ) <EOL> self . env . resolve_references ( largetree , indexfile , self ) <EOL> for pendingnode in largetree . traverse ( addnodes . pending_xref ) : <EOL> docname = pendingnode [ '<STR_LIT>' ] <EOL> sectname = pendingnode [ '<STR_LIT>' ] <EOL> newnodes = [ nodes . emphasis ( sectname , sectname ) ] <EOL> for subdir , title in self . titles : <EOL> if docname . startswith ( subdir ) : <EOL> newnodes . append ( nodes . Text ( _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' ) ) ) <EOL> newnodes . append ( nodes . emphasis ( title , title ) ) <EOL> newnodes . append ( nodes . Text ( '<STR_LIT:)>' , '<STR_LIT:)>' ) ) <EOL> break <EOL> else : <EOL> pass <EOL> pendingnode . replace_self ( newnodes ) <EOL> return largetree <EOL> def finish ( self ) : <EOL> if self . images : <EOL> self . info ( bold ( '<STR_LIT>' ) , nonl = <NUM_LIT:1> ) <EOL> for src , dest in iteritems ( self . images ) : <EOL> self . info ( '<STR_LIT:U+0020>' + src , nonl = <NUM_LIT:1> ) <EOL> copyfile ( path . join ( self . srcdir , src ) , <EOL> path . join ( self . outdir , dest ) ) <EOL> self . info ( ) <EOL> self . info ( bold ( '<STR_LIT>' ) ) <EOL> staticdirname = path . join ( package_dir , '<STR_LIT>' ) <EOL> for filename in os . listdir ( staticdirname ) : <EOL> if not filename . startswith ( '<STR_LIT:.>' ) : <EOL> copyfile ( path . join ( staticdirname , filename ) , <EOL> path . join ( self . outdir , filename ) ) <EOL> if self . config . latex_additional_files : <EOL> self . info ( bold ( '<STR_LIT>' ) , nonl = <NUM_LIT:1> ) <EOL> for filename in self . config . latex_additional_files : <EOL> self . info ( '<STR_LIT:U+0020>' + filename , nonl = <NUM_LIT:1> ) <EOL> copyfile ( path . join ( self . confdir , filename ) , <EOL> path . join ( self . outdir , path . basename ( filename ) ) ) <EOL> self . info ( ) <EOL> if self . config . latex_logo : <EOL> logobase = path . basename ( self . config . latex_logo ) <EOL> logotarget = path . join ( self . outdir , logobase ) <EOL> if not path . isfile ( path . join ( self . confdir , self . config . latex_logo ) ) : <EOL> raise SphinxError ( '<STR_LIT>' % self . config . latex_logo ) <EOL> elif not path . isfile ( logotarget ) : <EOL> copyfile ( path . join ( self . confdir , self . config . latex_logo ) , logotarget ) <EOL> self . info ( '<STR_LIT>' ) </s>
