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 |
if psycopg is not None: |
if psycopg is not None: |
32 |
type_map = [(psycopg.STRING, table.FIELDTYPE_STRING), |
type_map = [(psycopg.STRING, table.FIELDTYPE_STRING), |
55 |
self.user = user |
self.user = user |
56 |
self.password = password |
self.password = password |
57 |
self.dbtype = dbtype |
self.dbtype = dbtype |
58 |
|
self.connect() |
59 |
|
|
60 |
|
def connect(self): |
61 |
|
"""Internal: Establish the database connection""" |
62 |
params = [] |
params = [] |
63 |
for name in ("host", "port", "dbname", "user", "password"): |
for name in ("host", "port", "dbname", "user", "password"): |
64 |
val = getattr(self, name) |
val = getattr(self, name) |
78 |
else: |
else: |
79 |
raise ValueError("Can't determine postgres type of geometries") |
raise ValueError("Can't determine postgres type of geometries") |
80 |
|
|
81 |
|
def BriefDescription(self): |
82 |
|
"""Return a brief, one-line description of the connection |
83 |
|
|
84 |
|
The return value is suitable for a list box of all database |
85 |
|
connections. |
86 |
|
""" |
87 |
|
return ("postgis://%(user)s@%(host)s:%(port)s/%(dbname)s" |
88 |
|
% self.__dict__) |
89 |
|
|
90 |
def Close(self): |
def Close(self): |
91 |
"""Close the database connection""" |
"""Close the database connection""" |
92 |
self.connection.close() |
self.connection.close() |