<s> import os <EOL> import shutil <EOL> from optparse import OptionParser <EOL> from os . path import abspath , dirname , join , normpath <EOL> from subprocess import call <EOL> from sys import exit <EOL> class GenerateApiDocs ( object ) : <EOL> BUILD_DIR = abspath ( dirname ( __file__ ) ) <EOL> AUTODOC_DIR = join ( BUILD_DIR , '<STR_LIT>' ) <EOL> ROOT = normpath ( join ( BUILD_DIR , '<STR_LIT:..>' , '<STR_LIT:..>' ) ) <EOL> ROBOT_DIR = join ( ROOT , '<STR_LIT:src>' , '<STR_LIT>' ) <EOL> JAVA_SRC = join ( ROOT , '<STR_LIT:src>' , '<STR_LIT>' ) <EOL> JAVA_TARGET = join ( BUILD_DIR , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self ) : <EOL> try : <EOL> import sphinx as _ <EOL> except ImportError : <EOL> exit ( '<STR_LIT>' ) <EOL> self . options = GeneratorOptions ( ) <EOL> def run ( self ) : <EOL> self . create_autodoc ( ) <EOL> if self . options . javadoc : <EOL> self . create_javadoc ( ) <EOL> orig_dir = abspath ( os . curdir ) <EOL> os . chdir ( self . BUILD_DIR ) <EOL> rc = call ( [ '<STR_LIT>' , '<STR_LIT:html>' ] , shell = os . name == '<STR_LIT>' ) <EOL> os . chdir ( orig_dir ) <EOL> print abspath ( join ( self . BUILD_DIR , '<STR_LIT>' , '<STR_LIT:html>' , '<STR_LIT>' ) ) <EOL> exit ( rc ) <EOL> def create_autodoc ( self ) : <EOL> print '<STR_LIT>' <EOL> self . _clean_directory ( self . AUTODOC_DIR ) <EOL> command = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , self . AUTODOC_DIR , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:2>' , <EOL> '<STR_LIT>' , <EOL> self . ROBOT_DIR ] <EOL> print '<STR_LIT:U+0020>' . join ( command ) <EOL> call ( command ) <EOL> def create_javadoc ( self ) : <EOL> print '<STR_LIT>' <EOL> self . _clean_directory ( self . JAVA_TARGET ) <EOL> command = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . JAVA_SRC , <EOL> '<STR_LIT>' , self . JAVA_TARGET , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> print '<STR_LIT:U+0020>' . join ( command ) <EOL> call ( command ) <EOL> def _clean_directory ( self , dirname ) : <EOL> if os . path . exists ( dirname ) : <EOL> print '<STR_LIT>' , dirname <EOL> shutil . rmtree ( dirname ) <EOL> class GeneratorOptions ( ) : <EOL> usage = '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> self . _parser = OptionParser ( self . usage ) <EOL> self . _add_options ( ) <EOL> self . _options , _ = self . _parser . parse_args ( ) <EOL> if not self . _options . _javadoc : <EOL> self . _prompt_for_generation ( '<STR_LIT>' ) <EOL> @ property <EOL> def javadoc ( self ) : <EOL> return self . _options . _javadoc <EOL> def _add_options ( self ) : <EOL> self . _parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> def _prompt_for_generation ( self , attr_name ) : <EOL> selection = raw_input ( '<STR_LIT>' <EOL> '<STR_LIT>' % attr_name . title ( ) ) <EOL> if len ( selection ) > <NUM_LIT:0> and selection [ <NUM_LIT:0> ] . lower ( ) == '<STR_LIT:y>' : <EOL> setattr ( self . _options , '<STR_LIT>' % attr_name , True ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> GenerateApiDocs ( ) . run ( ) </s>
