<s> """<STR_LIT>""" <EOL> import inspect <EOL> import os <EOL> import pkgutil <EOL> import sys <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . abspath ( '<STR_LIT:..>' ) ) <EOL> from libsaas import services <EOL> from libsaas . services import base <EOL> def _title ( title , char ) : <EOL> return '<STR_LIT>' . format ( title , char * len ( title ) ) <EOL> def method_path ( resource , method ) : <EOL> return '<STR_LIT:.>' . join ( ( resource . __module__ , <EOL> resource . __name__ , <EOL> method . __name__ ) ) <EOL> def walk_resource ( resource , rst , top ) : <EOL> for child_name in resource . list_resources ( ) : <EOL> method = getattr ( resource , child_name ) <EOL> path = method_path ( resource , method ) <EOL> section_name = '<STR_LIT:U+002CU+0020>' . join ( [ p . __name__ for p in method . produces ] ) <EOL> rst . write ( _title ( section_name , '<STR_LIT:->' ) ) <EOL> rst . write ( '<STR_LIT>' . format ( path ) ) <EOL> for child_resource in method . produces : <EOL> walk_resource ( child_resource , rst , False ) <EOL> methods = resource . list_methods ( ) <EOL> if not methods : <EOL> return <EOL> if top : <EOL> rst . write ( _title ( '<STR_LIT>' , '<STR_LIT:->' ) ) <EOL> for child_name in methods : <EOL> method = getattr ( resource , child_name ) <EOL> path = method_path ( resource , method ) <EOL> rst . write ( '<STR_LIT>' . format ( path ) ) <EOL> def is_resource ( klass ) : <EOL> return inspect . isclass ( klass ) and issubclass ( klass , base . Resource ) <EOL> def process_package ( importer , modname ) : <EOL> module = importer . find_module ( modname ) . load_module ( modname ) <EOL> klass = inspect . getmembers ( module , is_resource ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> rst = open ( os . path . join ( '<STR_LIT>' , '<STR_LIT>' . format ( modname ) ) , '<STR_LIT:w>' ) <EOL> rst . write ( _title ( klass . __name__ , '<STR_LIT:=>' ) ) <EOL> rst . write ( '<STR_LIT>' . format ( modname , klass . __name__ ) ) <EOL> walk_resource ( klass , rst , True ) <EOL> rst . close ( ) <EOL> def generate_index ( modules ) : <EOL> rst = open ( os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> rst . write ( _title ( '<STR_LIT>' , '<STR_LIT:=>' ) ) <EOL> rst . write ( '<STR_LIT>' ) <EOL> for importer , modname , is_package in modules : <EOL> if not is_package : <EOL> continue <EOL> rst . write ( '<STR_LIT>' . format ( modname ) ) <EOL> rst . close ( ) <EOL> modules = sorted ( pkgutil . iter_modules ( services . __path__ ) , <EOL> key = lambda tup : tup [ <NUM_LIT:1> ] ) <EOL> for importer , modname , is_package in modules : <EOL> if not is_package : <EOL> continue <EOL> process_package ( importer , modname ) <EOL> generate_index ( modules ) </s>
