<s> """<STR_LIT>""" <EOL> from __future__ import print_function , unicode_literals <EOL> import os <EOL> w = lambda f , s , * a , ** kw : print ( s . format ( * a , ** kw ) , file = f ) <EOL> def rst_for_module ( toc_path ) : <EOL> """<STR_LIT>""" <EOL> f = open ( toc_path + '<STR_LIT>' , '<STR_LIT>' ) <EOL> heading = "<STR_LIT>" . format ( os . path . basename ( toc_path ) ) <EOL> dotted = toc_path . replace ( '<STR_LIT:/>' , '<STR_LIT:.>' ) <EOL> w ( f , heading ) <EOL> w ( f , "<STR_LIT:=>" * len ( heading ) ) <EOL> w ( f , "<STR_LIT>" , dotted ) <EOL> return f <EOL> def rst_for_package ( root , dirs , files ) : <EOL> """<STR_LIT>""" <EOL> doc_path = root [ <NUM_LIT:3> : ] <EOL> if not os . path . isdir ( doc_path ) : <EOL> os . mkdir ( doc_path ) <EOL> f = rst_for_module ( doc_path ) <EOL> w ( f , "<STR_LIT>" ) <EOL> def toc ( doc_path , name ) : <EOL> parent = os . path . dirname ( doc_path ) <EOL> toc_path = os . path . join ( doc_path [ len ( parent ) : ] . lstrip ( '<STR_LIT:/>' ) , name ) <EOL> if toc_path . endswith ( '<STR_LIT>' ) : <EOL> toc_path = toc_path [ : - len ( '<STR_LIT>' ) ] <EOL> w ( f , "<STR_LIT>" , toc_path ) <EOL> return os . path . join ( parent , toc_path ) <EOL> for name in sorted ( dirs + files ) : <EOL> if name in dirs : <EOL> toc ( doc_path , name ) <EOL> else : <EOL> if not name . endswith ( '<STR_LIT>' ) : continue <EOL> if name == '<STR_LIT>' : continue <EOL> toc_path = toc ( doc_path , name ) <EOL> rst_for_module ( toc_path ) <EOL> def main ( ) : <EOL> library_root = os . environ [ '<STR_LIT>' ] <EOL> for root , dirs , files in os . walk ( library_root ) : <EOL> rst_for_package ( root , dirs , files ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
