<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> if '<STR_LIT>' not in sys . modules and __name__ == '<STR_LIT:__main__>' : <EOL> import pythonpathsetter <EOL> from robot . utils import Application , seq2str <EOL> from robot . errors import DataError <EOL> from robot . libdocpkg import LibraryDocumentation , ConsoleViewer <EOL> USAGE = """<STR_LIT>""" <EOL> class LibDoc ( Application ) : <EOL> def __init__ ( self ) : <EOL> Application . __init__ ( self , USAGE , arg_limits = ( <NUM_LIT:2> , ) , auto_version = False ) <EOL> def validate ( self , options , arguments ) : <EOL> if ConsoleViewer . handles ( arguments [ <NUM_LIT:1> ] ) : <EOL> ConsoleViewer . validate_command ( arguments [ <NUM_LIT:1> ] , arguments [ <NUM_LIT:2> : ] ) <EOL> elif len ( arguments ) > <NUM_LIT:2> : <EOL> raise DataError ( '<STR_LIT>' ) <EOL> return options , arguments <EOL> def main ( self , args , name = '<STR_LIT>' , version = '<STR_LIT>' , format = None , docformat = None ) : <EOL> lib_or_res , output = args [ : <NUM_LIT:2> ] <EOL> libdoc = LibraryDocumentation ( lib_or_res , name , version , <EOL> self . _get_doc_format ( docformat ) ) <EOL> if ConsoleViewer . handles ( output ) : <EOL> ConsoleViewer ( libdoc ) . view ( output , * args [ <NUM_LIT:2> : ] ) <EOL> else : <EOL> libdoc . save ( output , self . _get_output_format ( format , output ) ) <EOL> self . console ( os . path . abspath ( output ) ) <EOL> def _get_doc_format ( self , format ) : <EOL> if not format : <EOL> return None <EOL> return self . _verify_format ( '<STR_LIT>' , format , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def _get_output_format ( self , format , output ) : <EOL> default = os . path . splitext ( output ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] <EOL> return self . _verify_format ( '<STR_LIT>' , format or default , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def _verify_format ( self , type , format , valid ) : <EOL> format = format . upper ( ) <EOL> if format not in valid : <EOL> raise DataError ( "<STR_LIT>" <EOL> % ( type , seq2str ( valid , lastsep = '<STR_LIT>' ) , format ) ) <EOL> return format <EOL> def libdoc_cli ( arguments ) : <EOL> """<STR_LIT>""" <EOL> LibDoc ( ) . execute_cli ( arguments ) <EOL> def libdoc ( library_or_resource , outfile , name = '<STR_LIT>' , version = '<STR_LIT>' , format = None ) : <EOL> """<STR_LIT>""" <EOL> LibDoc ( ) . execute ( library_or_resource , outfile , name = name , version = version , <EOL> format = format ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> libdoc_cli ( sys . argv [ <NUM_LIT:1> : ] ) </s>
