1
1
from django .conf import settings
2
2
from django .core .management import call_command
3
3
from django .db import connection
4
- from django .test . utils import _set_autocommit , TEST_DATABASE_PREFIX
4
+ from django .db . backends . creation import TEST_DATABASE_PREFIX
5
5
import os , re , sys
6
6
7
7
def getstatusoutput (cmd ):
@@ -38,9 +38,9 @@ def _create_with_cursor(db_name, verbosity=1, autoclobber=False):
38
38
create_sql = 'CREATE DATABASE %s' % connection .ops .quote_name (db_name )
39
39
if settings .DATABASE_USER :
40
40
create_sql += ' OWNER %s' % settings .DATABASE_USER
41
-
41
+
42
42
cursor = connection .cursor ()
43
- _set_autocommit (connection )
43
+ connection . creation . set_autocommit (connection )
44
44
45
45
try :
46
46
# Trying to create the database first.
@@ -58,12 +58,12 @@ def _create_with_cursor(db_name, verbosity=1, autoclobber=False):
58
58
else :
59
59
raise Exception ('Spatial Database Creation canceled.' )
60
60
foo = _create_with_cursor
61
-
61
+
62
62
created_regex = re .compile (r'^createdb: database creation failed: ERROR: database ".+" already exists' )
63
63
def _create_with_shell (db_name , verbosity = 1 , autoclobber = False ):
64
64
"""
65
- If no spatial database already exists, then using a cursor will not work.
66
- Thus, a `createdb` command will be issued through the shell to bootstrap
65
+ If no spatial database already exists, then using a cursor will not work.
66
+ Thus, a `createdb` command will be issued through the shell to bootstrap
67
67
creation of the spatial database.
68
68
"""
69
69
@@ -83,7 +83,7 @@ def _create_with_shell(db_name, verbosity=1, autoclobber=False):
83
83
if verbosity >= 1 : print 'Destroying old spatial database...'
84
84
drop_cmd = 'dropdb %s%s' % (options , db_name )
85
85
status , output = getstatusoutput (drop_cmd )
86
- if status != 0 :
86
+ if status != 0 :
87
87
raise Exception ('Could not drop database %s: %s' % (db_name , output ))
88
88
if verbosity >= 1 : print 'Creating new spatial database...'
89
89
status , output = getstatusoutput (create_cmd )
@@ -102,10 +102,10 @@ def create_spatial_db(test=False, verbosity=1, autoclobber=False, interactive=Fa
102
102
raise Exception ('Spatial database creation only supported postgresql_psycopg2 platform.' )
103
103
104
104
# Getting the spatial database name
105
- if test :
105
+ if test :
106
106
db_name = get_spatial_db (test = True )
107
107
_create_with_cursor (db_name , verbosity = verbosity , autoclobber = autoclobber )
108
- else :
108
+ else :
109
109
db_name = get_spatial_db ()
110
110
_create_with_shell (db_name , verbosity = verbosity , autoclobber = autoclobber )
111
111
@@ -125,7 +125,7 @@ def create_spatial_db(test=False, verbosity=1, autoclobber=False, interactive=Fa
125
125
126
126
# Syncing the database
127
127
call_command ('syncdb' , verbosity = verbosity , interactive = interactive )
128
-
128
+
129
129
def drop_db (db_name = False , test = False ):
130
130
"""
131
131
Drops the given database (defaults to what is returned from
@@ -151,7 +151,7 @@ def get_cmd_options(db_name):
151
151
152
152
def get_spatial_db (test = False ):
153
153
"""
154
- Returns the name of the spatial database. The 'test' keyword may be set
154
+ Returns the name of the spatial database. The 'test' keyword may be set
155
155
to return the test spatial database name.
156
156
"""
157
157
if test :
@@ -167,13 +167,13 @@ def get_spatial_db(test=False):
167
167
168
168
def load_postgis_sql (db_name , verbosity = 1 ):
169
169
"""
170
- This routine loads up the PostGIS SQL files lwpostgis.sql and
170
+ This routine loads up the PostGIS SQL files lwpostgis.sql and
171
171
spatial_ref_sys.sql.
172
172
"""
173
173
174
174
# Getting the path to the PostGIS SQL
175
175
try :
176
- # POSTGIS_SQL_PATH may be placed in settings to tell GeoDjango where the
176
+ # POSTGIS_SQL_PATH may be placed in settings to tell GeoDjango where the
177
177
# PostGIS SQL files are located. This is especially useful on Win32
178
178
# platforms since the output of pg_config looks like "C:/PROGRA~1/..".
179
179
sql_path = settings .POSTGIS_SQL_PATH
@@ -193,7 +193,7 @@ def load_postgis_sql(db_name, verbosity=1):
193
193
# Getting the psql command-line options, and command format.
194
194
options = get_cmd_options (db_name )
195
195
cmd_fmt = 'psql %s-f "%%s"' % options
196
-
196
+
197
197
# Now trying to load up the PostGIS functions
198
198
cmd = cmd_fmt % lwpostgis_file
199
199
if verbosity >= 1 : print cmd
@@ -211,8 +211,8 @@ def load_postgis_sql(db_name, verbosity=1):
211
211
# Setting the permissions because on Windows platforms the owner
212
212
# of the spatial_ref_sys and geometry_columns tables is always
213
213
# the postgres user, regardless of how the db is created.
214
- if os .name == 'nt' : set_permissions (db_name )
215
-
214
+ if os .name == 'nt' : set_permissions (db_name )
215
+
216
216
def set_permissions (db_name ):
217
217
"""
218
218
Sets the permissions on the given database to that of the user specified
0 commit comments