Mercurial > dive4elements > river
diff flys-backend/contrib/shpimporter/shpimporter.py @ 4872:a563e9f58f93
Improve error handling and unify dbconn for all importers
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 23 Jan 2013 15:30:09 +0100 |
parents | 890eaa0a5162 |
children | 63f82bdd45f8 |
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/shpimporter.py Wed Jan 23 11:51:14 2013 +0100 +++ b/flys-backend/contrib/shpimporter/shpimporter.py Wed Jan 23 15:30:09 2013 +0100 @@ -1,4 +1,7 @@ -import ogr +try: + from osgeo import ogr +except ImportErrror: + import ogr import utils, optparse @@ -35,21 +38,21 @@ print "ERROR: %s" % msg -def getImporters(config): +def getImporters(config, dbconn): return [ - Axis(config), - KM(config), - CrosssectionTrack(config), - Line(config), - Fixpoint(config), - Building(config), - Floodplain(config), - HydrBoundary(config), - HydrBoundaryPoly(config), - HWS(config), - GaugeLocation(config), - Catchment(config), - UESG(config) + Axis(config, dbconn), + KM(config, dbconn), + CrosssectionTrack(config, dbconn), + Line(config, dbconn), + Fixpoint(config, dbconn), + Building(config, dbconn), + Floodplain(config, dbconn), + HydrBoundary(config, dbconn), + HydrBoundaryPoly(config, dbconn), + HWS(config, dbconn), + GaugeLocation(config, dbconn), + Catchment(config, dbconn), + UESG(config, dbconn) ] @@ -129,12 +132,12 @@ return False -def parse(): +def main(): config=None try: config = getConfig() except: - return + return -1 if config == None: ERROR("Unable to read config from command line!") @@ -143,7 +146,16 @@ if config.dry_run > 0: INFO("You enable 'dry_run'. No database transaction will take place!") - importers = getImporters(config) + if config.ogr_connection: + dbconn = ogr.Open(config.ogr_connection) + else: + dbconn = ogr.Open('OCI:%s/%s@%s' % (config.user, config.password, config.host)) + + if not dbconn: + shpimporter.ERROR("Could not connect to database %s" % self.dbconn) + return -1 + + importers = getImporters(config, dbconn) types = {} for importer in importers: @@ -170,4 +182,4 @@ if __name__ == '__main__': - parse() + main()