changeset 4871:890eaa0a5162

Add ogr_connection parameter to allow directly setting the ogr connection. This allows the importer to connect with all supported and not just OCI
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 23 Jan 2013 11:51:14 +0100
parents 2dac0e5b927e
children a563e9f58f93
files flys-backend/contrib/shpimporter/importer.py flys-backend/contrib/shpimporter/shpimporter.py flys-backend/doc/documentation/de/importer-geodaesie.tex
diffstat 3 files changed, 26 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/importer.py	Mon Jan 28 00:46:46 2013 +0100
+++ b/flys-backend/contrib/shpimporter/importer.py	Wed Jan 23 11:51:14 2013 +0100
@@ -5,7 +5,10 @@
 
     def __init__(self, config):
         self.config = config
-        self.dbconn   = 'OCI:%s/%s@%s' % (config.user, config.password, config.host)
+        if config.ogr_connection:
+            self.dbconn = '%s' % config.ogr_connection
+        else:
+            self.dbconn = 'OCI:%s/%s@%s' % (config.user, config.password, config.host)
         self.river_id = config.river_id
         self.dest_srs = osr.SpatialReference()
         self.dest_srs.ImportFromEPSG(config.target_srs)
@@ -84,6 +87,10 @@
 
     def shape2Database(self, srcLayer, name, path):
         table     = ogr.Open(self.dbconn)
+        if not table:
+            shpimporter.ERROR("Could not connect to database %s" % self.dbconn)
+            return -1
+
         destLayer = table.GetLayerByName(self.getTablename())
 
         if srcLayer is None:
--- a/flys-backend/contrib/shpimporter/shpimporter.py	Mon Jan 28 00:46:46 2013 +0100
+++ b/flys-backend/contrib/shpimporter/shpimporter.py	Wed Jan 23 11:51:14 2013 +0100
@@ -63,6 +63,7 @@
     parser.add_option("--river_id", type="int")
     parser.add_option("--verbose", type="int", default=1)
     parser.add_option("--dry_run", type="int", default=0)
+    parser.add_option("--ogr_connection", type="string")
     parser.add_option("--skip_axis", type="int")
     parser.add_option("--skip_hydr_boundaries", type="int")
     parser.add_option("--skip_buildings", type="int")
@@ -80,16 +81,17 @@
     if config.directory == None:
         ERROR("No river directory specified!")
         raise Exception("Invalid config")
-    elif config.host == None:
-        ERROR("No database host specified!")
-        raise Exception("Invalid config")
-    elif config.user == None:
-        ERROR("No databaser user specified!")
-        raise Exception("Invalid config")
-    elif config.password == None:
-        ERROR("No password specified!")
-        raise Exception("Invalid config")
-    elif config.river_id == None:
+    if not config.ogr_connection:
+        if not config.host:
+            ERROR("No database host specified!")
+            raise Exception("Invalid config")
+        if not config.user:
+            ERROR("No databaser user specified!")
+            raise Exception("Invalid config")
+        if not config.password:
+            ERROR("No password specified!")
+            raise Exception("Invalid config")
+    if config.river_id == None:
         ERROR("No river id specified!")
         raise Exception("Invalid config")
 
--- a/flys-backend/doc/documentation/de/importer-geodaesie.tex	Mon Jan 28 00:46:46 2013 +0100
+++ b/flys-backend/doc/documentation/de/importer-geodaesie.tex	Wed Jan 23 11:51:14 2013 +0100
@@ -297,6 +297,12 @@
 `2` werden sämtliche Ausgaben des Programms geschrieben. Dieser
 Modus ist hauptsächlich für die Entwicklung gedacht.
 
+\textbf{OGR\_CONNECTION}
+\\Hiermit kann direkt ein beliebiger Verbindungs string angegegeben
+werden, welcher die host, user und passwort werde überschreibt.
+Dieser Option wird direkt an die OGR Bibliothek weitergegeben und ermöglicht
+verbesserte Tests und Entwicklung mit verschiedenen Daten Backends.
+
 \textbf{SKIP\_AXIS}
 \\Bei gesetztem Wert `1` werden keine Flussachsen importiert.
 

http://dive4elements.wald.intevation.org