#NEWLINE# def get_ogr_db_string( ) : #NEWLINE# #INDENT# '\n    Construct the DB string that GDAL will use to inspect the database.\n    GDAL will create its own connection to the database, so we re-use the\n    connection settings from the Django test.\n    ' #NEWLINE# db = connections . databases [ 'default' ] #NEWLINE# drivers = { #NEWLINE# #INDENT# 'django.contrib.gis.db.backends.postgis' : ( 'PostgreSQL' , "PG:dbname='%(db_name)s'" , ' ' ) , #NEWLINE# 'django.contrib.gis.db.backends.mysql' : ( 'MySQL' , 'MYSQL:"%(db_name)s"' , ',' ) , #NEWLINE# 'django.contrib.gis.db.backends.spatialite' : ( 'SQLite' , '%(db_name)s' , '' ) , #NEWLINE# #UNINDENT# } #NEWLINE# ( drv_name , db_str , param_sep ) = drivers [ db [ 'ENGINE' ] ] #NEWLINE# try : #NEWLINE# #INDENT# Driver ( drv_name ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if ( db [ 'NAME' ] == ':memory:' ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# params = [ ( db_str % { #NEWLINE# #INDENT# 'db_name' : db [ 'NAME' ] , #NEWLINE# #UNINDENT# } ) ] #NEWLINE# def add( key , template ) : #NEWLINE# #INDENT# value = db . get ( key , None ) #NEWLINE# if value : #NEWLINE# #INDENT# params . append ( ( template % value ) ) #NEWLINE# #UNINDENT# #UNINDENT# add ( 'HOST' , "host='%s'" ) #NEWLINE# add ( 'PORT' , "port='%s'" ) #NEWLINE# add ( 'USER' , "user='%s'" ) #NEWLINE# add ( 'PASSWORD' , "password='%s'" ) #NEWLINE# return param_sep . join ( params )