#NEWLINE# def get_persistent_store_engine( app_name , persistent_store_name ) : #NEWLINE# #INDENT# '\n    Creates an SQLAlchemy engine object for the app and persistent store given.\n\n    Args:\n      app_name(string): Name of the app to which the persistent store belongs. More specifically, the app package name.\n      persistent_store_name(string): Name of the persistent store for which to retrieve the engine.\n\n    Returns:\n      object: An SQLAlchemy engine object for the persistent store requested.\n    ' #NEWLINE# print ( 'DEPRECTATION WARNING: The ".utilities.get_persistent_store" method has been deprecated. Use the "get_persistent_store" method on the App Class instead (e.g.: MyApp.get_persistent_store("name") ).' ) #NEWLINE# unique_store_name = '_' . join ( [ app_name , persistent_store_name ] ) #NEWLINE# database_manager_db = settings . TETHYS_DATABASES [ 'tethys_db_manager' ] #NEWLINE# database_manager_url = 'postgresql://{0}:{1}@{2}:{3}/{4}' . format ( ( database_manager_db [ 'USER' ] if ( 'USER' in database_manager_db ) else 'tethys_db_manager' ) , ( database_manager_db [ 'PASSWORD' ] if ( 'PASSWORD' in database_manager_db ) else 'pass' ) , ( database_manager_db [ 'HOST' ] if ( 'HOST' in database_manager_db ) else '127.0.0.1' ) , ( database_manager_db [ 'PORT' ] if ( 'PORT' in database_manager_db ) else '5435' ) , ( database_manager_db [ 'NAME' ] if ( 'NAME' in database_manager_db ) else 'tethys_db_manager' ) ) #NEWLINE# engine = create_engine ( database_manager_url ) #NEWLINE# connection = engine . connect ( ) #NEWLINE# existing_dbs_statement = '\n                             SELECT d.datname as name\n                             FROM pg_catalog.pg_database d\n                             LEFT JOIN pg_catalog.pg_user u ON d.datdba = u.usesysid\n                             ORDER BY 1;\n                             ' #NEWLINE# existing_dbs = connection . execute ( existing_dbs_statement ) #NEWLINE# existing_db_names = [ ] #NEWLINE# for existing_db in existing_dbs : #NEWLINE# #INDENT# existing_db_names . append ( existing_db . name ) #NEWLINE# #UNINDENT# if ( unique_store_name in existing_db_names ) : #NEWLINE# #INDENT# database_manager_db = settings . TETHYS_DATABASES [ 'tethys_db_manager' ] #NEWLINE# persistent_store_url = 'postgresql://{0}:{1}@{2}:{3}/{4}' . format ( ( database_manager_db [ 'USER' ] if ( 'USER' in database_manager_db ) else 'tethys_db_manager' ) , ( database_manager_url [ 'PASSWORD' ] if ( 'PASSWORD' in database_manager_db ) else 'pass' ) , ( database_manager_db [ 'HOST' ] if ( 'HOST' in database_manager_db ) else '127.0.0.1' ) , ( database_manager_db [ 'PORT' ] if ( 'PORT' in database_manager_db ) else '5435' ) , unique_store_name ) #NEWLINE# return create_engine ( persistent_store_url ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise DatabaseError ( 'No persistent store "{0}" for app "{1}". Make sure you register the persistent store in app.py and reinstall app.' . format ( persistent_store_name , app_name ) )