#NEWLINE# def api_from_models( ) : #NEWLINE# #INDENT# if ( 'model-based' in _cached_apis ) : #NEWLINE# #INDENT# return _cached_apis [ 'model-based' ] #NEWLINE# #UNINDENT# from opencenter import backends #NEWLINE# from opencenter.db import models #NEWLINE# from opencenter.db import inmemory #NEWLINE# backends . load ( ) #NEWLINE# new_api = OpenCenterApi ( ) #NEWLINE# for d in dir ( models ) : #NEWLINE# #INDENT# abst = None #NEWLINE# model_name = d . lower ( ) #NEWLINE# model = getattr ( models , d ) #NEWLINE# if ( ( type ( models . Nodes ) == type ( getattr ( models , d ) ) ) and ( d != 'Base' ) ) : #NEWLINE# #INDENT# abst = abstraction . SqlAlchemyAbstraction ( new_api , model , model_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( getattr ( models , d ) , type ) and issubclass ( model , inmemory . InMemoryBase ) and ( d != 'Primitives' ) ) : #NEWLINE# #INDENT# abst = abstraction . InMemoryAbstraction ( new_api , model , d , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( d == 'Primitives' ) : #NEWLINE# #INDENT# abst = abstraction . InMemoryAbstraction ( new_api , model , d , backends . backend_primitives ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( abst is not None ) : #NEWLINE# #INDENT# new_api . add_model ( d , abst ) #NEWLINE# #UNINDENT# #UNINDENT# if use_cached_api : #NEWLINE# #INDENT# cached_api = cached_api_from_api ( new_api ) #NEWLINE# _cached_apis [ 'model-based' ] = cached_api #NEWLINE# return cached_api #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _cached_apis [ 'model-based' ] = new_api #NEWLINE# return new_api