def importPostgis(appdef, progress): progress.setText("Importing into PostGIS") progress.setProgress(0) host = appdef["Deploy"]["PostGIS host"] port = appdef["Deploy"]["PostGIS port"] username = appdef["Deploy"]["PostGIS username"] password = appdef["Deploy"]["PostGIS password"] dbname = appdef["Deploy"]["PostGIS database"] schema = appdef["Deploy"]["PostGIS schema"] uri = QgsDataSourceURI() uri.setConnection(host, port, dbname, username, password) connector = PostGisDBConnector(uri) schemas = connector.getSchemas() schemaExists = schema in [s[1] for s in schemas] for i, layer in enumerate(appdef["Layers"]): if layer.method in [METHOD_WFS_POSTGIS, METHOD_WMS_POSTGIS]: if not schemaExists: connector.createSchema(schema) schemaExists = True tables = connector.getTables(schema=schema) tablename = safeName(layer.layer.name()) tableExists = tablename in [t[1] for t in tables] if tableExists: connector.deleteTable([schema, tablename]) importLayerIntoPostgis(layer.layer, host, port, username, password, dbname, schema, tablename, appdef["Settings"]["App view CRS"]) progress.setProgress(int(i*100.0/len(appdef["Layers"])))