<s> import copy <EOL> import os <EOL> import subprocess <EOL> import sys <EOL> import os . path as op <EOL> import bento . errors <EOL> from bento . commands . core import Command <EOL> from bento . commands . options import Option <EOL> from bento . utils . utils import extract_exception <EOL> _OUTPUT_DEFAULT = "<STR_LIT:html>" <EOL> _DOC_ROOT = "<STR_LIT>" <EOL> _SOURCE_ROOT = "<STR_LIT:source>" <EOL> def guess_source_dir ( ) : <EOL> for guess in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if not op . isdir ( guess ) : <EOL> continue <EOL> for root , dirnames , filenames in os . walk ( guess ) : <EOL> if '<STR_LIT>' in filenames : <EOL> return root <EOL> return None <EOL> class SphinxCommand ( Command ) : <EOL> long_descr = """<STR_LIT>""" <EOL> short_descr = "<STR_LIT>" <EOL> common_options = Command . common_options + [ Option ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" % _OUTPUT_DEFAULT , <EOL> default = _OUTPUT_DEFAULT ) , <EOL> Option ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) , <EOL> Option ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) , <EOL> ] <EOL> def can_run ( self ) : <EOL> try : <EOL> import sphinx . application <EOL> return True <EOL> except ImportError : <EOL> return False <EOL> except SyntaxError : <EOL> return False <EOL> def run ( self , context ) : <EOL> if not self . can_run ( ) : <EOL> return bento . errors . CommandExecutionFailure ( "<STR_LIT>" ) <EOL> import sphinx . application <EOL> p = context . options_context . parser <EOL> o , a = p . parse_args ( context . command_argv ) <EOL> if o . output_format != "<STR_LIT:html>" : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> builder = "<STR_LIT:html>" <EOL> if o . source_dir is None : <EOL> source_dir = guess_source_dir ( ) <EOL> else : <EOL> source_dir = o . source_dir <EOL> if source_dir is None : <EOL> raise bento . errors . UsageException ( """<STR_LIT>""" ) <EOL> if not op . isabs ( source_dir ) : <EOL> source_dir = op . join ( context . top_node . abspath ( ) , source_dir ) <EOL> sphinx_build = context . build_node . make_node ( "<STR_LIT>" ) <EOL> html_build = sphinx_build . make_node ( o . output_format ) <EOL> doctrees_build = sphinx_build . make_node ( "<STR_LIT>" ) <EOL> doc_html_build = html_build . abspath ( ) <EOL> doc_doctrees_build = doctrees_build . abspath ( ) <EOL> confoverrides = { } <EOL> status_stream = sys . stdout <EOL> fresh_env = False <EOL> force_all = False <EOL> app = sphinx . application . Sphinx ( <EOL> source_dir , source_dir , <EOL> doc_html_build , doc_doctrees_build , <EOL> builder , confoverrides , status_stream , <EOL> freshenv = fresh_env ) <EOL> try : <EOL> app . build ( force_all = force_all ) <EOL> except Exception : <EOL> err = extract_exception ( ) <EOL> raise bento . errors . CommandExecutionFailure ( "<STR_LIT>" % str ( err ) ) </s>
