comparison flys-backend/contrib/shpimporter/shpimporter.py @ 5036:d6860fca89e4 dami

Pull information about the backend into dgm. While the api of cx_oracle and psycopg2 is compatible enough, the query syntax is not :(
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 20 Feb 2013 10:40:07 +0100
parents a5f438895a38
children c5187ab9f571
comparison
equal deleted inserted replaced
5035:1f33012cc02a 5036:d6860fca89e4
143 if config.ogr_connection: 143 if config.ogr_connection:
144 connstr = config.ogr_connection 144 connstr = config.ogr_connection
145 else: 145 else:
146 connstr = 'OCI:%s/%s@%s' % (config.user, config.password, config.host) 146 connstr = 'OCI:%s/%s@%s' % (config.user, config.password, config.host)
147 147
148 oracle = False # Marker if oracle is used.
148 if 'OCI:' in connstr: 149 if 'OCI:' in connstr:
150 oracle = True
149 try: 151 try:
150 import cx_Oracle as dbapi 152 import cx_Oracle as dbapi
151 raw_connstr=connstr.replace("OCI:", "") 153 raw_connstr=connstr.replace("OCI:", "")
152 except ImportErrror: 154 except ImportErrror:
153 logger.error("Module cx_Oracle not found in: %s\n" 155 logger.error("Module cx_Oracle not found in: %s\n"
154 "Neccessary to connect to a Oracle Database.\n" 156 "Neccessary to connect to a Oracle Database.\n"
155 "Please refer to the installation " 157 "Please refer to the installation "
156 "documentation." % sys.path) 158 "documentation." % sys.path)
159 return -1
157 160
158 else: # Currently only support for oracle and postgres 161 else: # Currently only support for oracle and postgres
159 try: 162 try:
160 import psycopg2 as dbapi 163 import psycopg2 as dbapi
161 raw_connstr=connstr.replace("PG:", "") 164 raw_connstr=connstr.replace("PG:", "")
162 except ImportError: 165 except ImportError:
163 logger.error("Module psycopg2 not found in: %s\n" 166 logger.error("Module psycopg2 not found in: %s\n"
164 "Neccessary to connect to a Posgresql Database.\n" 167 "Neccessary to connect to a Posgresql Database.\n"
165 "Please refer to the installation " 168 "Please refer to the installation "
166 "documentation." % sys.path) 169 "documentation." % sys.path)
170 return -1
167 171
168 dbconn_raw = dbapi.connect(raw_connstr) 172 dbconn_raw = dbapi.connect(raw_connstr)
169 dbconn = ogr.Open(connstr) 173 dbconn = ogr.Open(connstr)
170 174
171 if dbconn == None: 175 if dbconn == None:
187 if not config.river_name: 191 if not config.river_name:
188 river_name = utils.getUTF8Path( 192 river_name = utils.getUTF8Path(
189 os.path.basename(os.path.normpath(directory))) 193 os.path.basename(os.path.normpath(directory)))
190 else: 194 else:
191 river_name = config.river_name 195 river_name = config.river_name
192 river_id = utils.getRiverId(dbconn_raw, river_name) 196 river_id = utils.getRiverId(dbconn_raw, river_name, oracle)
193 197
194 if not river_id: 198 if not river_id:
195 logger.info("Could not find river in database. Skipping: %s" 199 logger.info("Could not find river in database. Skipping: %s"
196 % river_name) 200 % river_name)
197 continue 201 continue
227 os.path.isfile(dgmfilename): 231 os.path.isfile(dgmfilename):
228 logger.info("Could not find or access DGM file: %s \n" 232 logger.info("Could not find or access DGM file: %s \n"
229 "Skipping DGM import." % dgmfilename) 233 "Skipping DGM import." % dgmfilename)
230 else: 234 else:
231 logger.info("Inserting DGM meta information in 'dem' table.") 235 logger.info("Inserting DGM meta information in 'dem' table.")
232 insertRiverDgm(dbconn_raw, dgmfilename, river_name, config.dry_run) 236 insertRiverDgm(dbconn_raw, dgmfilename, river_name,
237 config.dry_run, oracle)
233 else: 238 else:
234 logger.info("Skip import of DGM.") 239 logger.info("Skip import of DGM.")
235 240
236 if __name__ == '__main__': 241 if __name__ == '__main__':
237 main() 242 main()

http://dive4elements.wald.intevation.org