<s> from __future__ import print_function <EOL> import sys <EOL> import os <EOL> import shutil <EOL> import inspect <EOL> import getopt <EOL> from collections import defaultdict <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> throot = os . path . abspath ( <EOL> os . path . join ( sys . path [ <NUM_LIT:0> ] , os . pardir , os . pardir ) ) <EOL> options = defaultdict ( bool ) <EOL> opts , args = getopt . getopt ( <EOL> sys . argv [ <NUM_LIT:1> : ] , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' ] ) <EOL> options . update ( dict ( [ x , y or True ] for x , y in opts ) ) <EOL> if options [ '<STR_LIT>' ] : <EOL> print ( '<STR_LIT>' % sys . argv [ <NUM_LIT:0> ] ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if not ( options [ '<STR_LIT>' ] or options [ '<STR_LIT>' ] ) : <EOL> options [ '<STR_LIT>' ] = True <EOL> def mkdir ( path ) : <EOL> try : <EOL> os . mkdir ( path ) <EOL> except OSError : <EOL> pass <EOL> outdir = options [ '<STR_LIT>' ] or ( throot + '<STR_LIT>' ) <EOL> files = None <EOL> if len ( args ) != <NUM_LIT:0> : <EOL> files = [ os . path . abspath ( f ) for f in args ] <EOL> currentdir = os . getcwd ( ) <EOL> mkdir ( outdir ) <EOL> os . chdir ( outdir ) <EOL> pythonpath = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> pythonpath = os . pathsep . join ( [ throot , pythonpath ] ) <EOL> sys . path [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ throot ] <EOL> def call_sphinx ( builder , workdir ) : <EOL> import sphinx <EOL> if options [ '<STR_LIT>' ] : <EOL> extraopts = [ '<STR_LIT>' ] <EOL> else : <EOL> extraopts = [ ] <EOL> if not options [ '<STR_LIT>' ] and files is None : <EOL> extraopts . append ( '<STR_LIT>' ) <EOL> docpath = os . path . join ( throot , '<STR_LIT>' ) <EOL> inopt = [ docpath , workdir ] <EOL> if files is not None : <EOL> inopt . extend ( files ) <EOL> ret = sphinx . build_main ( [ '<STR_LIT>' , '<STR_LIT>' , builder ] + extraopts + inopt ) <EOL> if ret != <NUM_LIT:0> : <EOL> sys . exit ( ret ) <EOL> if options [ '<STR_LIT>' ] or options [ '<STR_LIT>' ] : <EOL> mkdir ( "<STR_LIT>" ) <EOL> sys . path [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ os . path . join ( throot , '<STR_LIT>' ) ] <EOL> call_sphinx ( '<STR_LIT:html>' , '<STR_LIT:.>' ) <EOL> if not options [ '<STR_LIT>' ] : <EOL> import tempfile <EOL> workdir = tempfile . mkdtemp ( ) <EOL> call_sphinx ( '<STR_LIT>' , workdir ) <EOL> os . chdir ( workdir ) <EOL> os . system ( '<STR_LIT>' ) <EOL> try : <EOL> shutil . copy ( os . path . join ( workdir , '<STR_LIT>' ) , outdir ) <EOL> os . chdir ( outdir ) <EOL> shutil . rmtree ( workdir ) <EOL> except OSError as e : <EOL> print ( '<STR_LIT>' , e ) <EOL> except IOError as e : <EOL> print ( '<STR_LIT>' , e ) <EOL> if options [ '<STR_LIT>' ] : <EOL> mkdir ( "<STR_LIT>" ) <EOL> sys . path [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ os . path . join ( throot , '<STR_LIT>' ) ] <EOL> call_sphinx ( '<STR_LIT>' , '<STR_LIT:.>' ) <EOL> os . chdir ( currentdir ) </s>
