#NEWLINE# def main( ) : #NEWLINE# #INDENT# 'Main generation method.' #NEWLINE# request = plugin_pb2 . CodeGeneratorRequest ( ) #NEWLINE# request . ParseFromString ( sys . stdin . read ( ) ) #NEWLINE# response = plugin_pb2 . CodeGeneratorResponse ( ) #NEWLINE# parents = set ( ) #NEWLINE# generateFiles = set ( request . file_to_generate ) #NEWLINE# files = [ ] #NEWLINE# for fileObject in request . proto_file : #NEWLINE# #INDENT# if ( fileObject . name not in generateFiles ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not fileObject . package ) : #NEWLINE# #INDENT# sys . stderr . write ( ( '%s: package definition required, but not found\n' % fileObject . name ) ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# name = fileObject . name . split ( '.' ) [ 0 ] #NEWLINE# files . append ( { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'package' : fileObject . package . lstrip ( '.' ) , #NEWLINE# 'messages' : fileObject . message_type , #NEWLINE# #UNINDENT# } ) #NEWLINE# path = fileObject . package . lstrip ( '.' ) . split ( '.' ) [ : ( - 1 ) ] #NEWLINE# for i in range ( len ( path ) ) : #NEWLINE# #INDENT# filePathParts = path [ : ( i + 1 ) ] #NEWLINE# package = '.' . join ( filePathParts ) #NEWLINE# filePath = os . path . join ( * filePathParts ) #NEWLINE# if ( package not in parents ) : #NEWLINE# #INDENT# initPy = response . file . add ( ) #NEWLINE# initPy . name = os . path . join ( 'src' , filePath , '__init__.py' ) #NEWLINE# initPy . content = ( "\nimport pkg_resources\npkg_resources.declare_namespace('%s')\n" % package ) #NEWLINE# parents . add ( package ) #NEWLINE# #UNINDENT# #UNINDENT# writeCFile ( response , name , fileObject ) #NEWLINE# #UNINDENT# writeSetupPy ( response , files , parents ) #NEWLINE# writeTests ( response , files ) #NEWLINE# writeManifest ( response , files ) #NEWLINE# sys . stdout . write ( response . SerializeToString ( ) )