20 |
|
|
21 |
from data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT, RAW_WKT |
from data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT, RAW_WKT |
22 |
|
|
23 |
|
def has_postgis_support(): |
24 |
|
"""Return whether this Thuban instance supports PostGIS connections |
25 |
|
|
26 |
|
Having PostGIS support means that the psycopg module can be |
27 |
|
imported. |
28 |
|
""" |
29 |
|
return psycopg is not None |
30 |
|
|
31 |
|
def psycopg_version(): |
32 |
|
return psycopg.__version__ |
33 |
|
|
34 |
if psycopg is not None: |
if psycopg is not None: |
35 |
type_map = [(psycopg.STRING, table.FIELDTYPE_STRING), |
type_map = [(psycopg.STRING, table.FIELDTYPE_STRING), |
58 |
self.user = user |
self.user = user |
59 |
self.password = password |
self.password = password |
60 |
self.dbtype = dbtype |
self.dbtype = dbtype |
61 |
|
self.connect() |
62 |
|
|
63 |
|
def connect(self): |
64 |
|
"""Internal: Establish the database connection""" |
65 |
params = [] |
params = [] |
66 |
for name in ("host", "port", "dbname", "user", "password"): |
for name in ("host", "port", "dbname", "user", "password"): |
67 |
val = getattr(self, name) |
val = getattr(self, name) |
81 |
else: |
else: |
82 |
raise ValueError("Can't determine postgres type of geometries") |
raise ValueError("Can't determine postgres type of geometries") |
83 |
|
|
84 |
|
def BriefDescription(self): |
85 |
|
"""Return a brief, one-line description of the connection |
86 |
|
|
87 |
|
The return value is suitable for a list box of all database |
88 |
|
connections. |
89 |
|
""" |
90 |
|
return ("postgis://%(user)s@%(host)s:%(port)s/%(dbname)s" |
91 |
|
% self.__dict__) |
92 |
|
|
93 |
def Close(self): |
def Close(self): |
94 |
"""Close the database connection""" |
"""Close the database connection""" |
95 |
self.connection.close() |
self.connection.close() |