Needed for the previous commit. oops.
Signed-off-by: Thomas Petazzoni <[email protected]>
---
www/maposmatic/gisdb.py | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
create mode 100644 www/maposmatic/gisdb.py
diff --git a/www/maposmatic/gisdb.py b/www/maposmatic/gisdb.py
new file mode 100644
index 0000000..e631b18
--- /dev/null
+++ b/www/maposmatic/gisdb.py
@@ -0,0 +1,23 @@
+import psycopg2
+import www.settings
+
+db = None
+
+def get():
+ global db
+ if db:
+ return db
+
+ try:
+ db = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s'
port='%s'" %
+ (www.settings.GIS_DATABASE_NAME,
+ www.settings.GIS_DATABASE_USER,
+ www.settings.GIS_DATABASE_HOST,
+ www.settings.GIS_DATABASE_PASSWORD,
+ www.settings.GIS_DATABASE_PORT))
+ except psycopg2.OperationalError, e:
+ l.warning("Could not connect to the PostGIS database: %s" %
+ str(e)[:-1])
+ return None
+
+ return db
--
1.7.4.1