Skip to content

Commit

Permalink
add psycopg2 support (#198)
Browse files Browse the repository at this point in the history
* drop psycopg2 install

* re-enable psycopg2 support
  • Loading branch information
3nids authored Apr 9, 2024
1 parent 0566693 commit 3581781
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
3 changes: 0 additions & 3 deletions plugin/.docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ RUN apt-get update && \
apt-get -y install openjdk-8-jre curl locales postgresql-client python3-geoalchemy2 \
&& rm -rf /var/lib/apt/lists/*

# remove when https://github.com/qgis/qgis-docker/pull/95 is merged
RUN pip install psycopg

RUN printf '[postgres]\ndbname=postgres\nuser=postgres\n' >> /etc/postgresql-common/pg_service.conf
RUN printf '[pg_tww]\ndbname=tww\nuser=postgres\n' >> /etc/postgresql-common/pg_service.conf

Expand Down
20 changes: 17 additions & 3 deletions plugin/teksi_wastewater/interlis/interlis_importer_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
import os
import tempfile

import psycopg
try:
import psycopg

PSYCOPG_VERSION = 3
DEFAULTS_CONN_ARG = {"autocommit": True}
except ImportError:
import psycopg2 as psycopg

PSYCOPG_VERSION = 2
DEFAULTS_CONN_ARG = {}

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication

Expand Down Expand Up @@ -233,7 +243,9 @@ def _import_from_intermediate_schema(self, import_model):
return interlisImporterToIntermediateSchema.session_tww

def _import_update_main_cover_and_refresh_mat_views(self):
connection = psycopg.connect(get_pgconf_as_psycopg_dsn(), autocommit=True)
connection = psycopg.connect(get_pgconf_as_psycopg_dsn(), **DEFAULTS_CONN_ARG)
if PSYCOPG_VERSION == 2:
connection.set_session(autocommit=True)
cursor = connection.cursor()

logger.info("Update wastewater structure fk_main_cover")
Expand Down Expand Up @@ -385,7 +397,9 @@ def _export_xtf_files(self, file_name_base, export_models):
def _clear_ili_schema(self, recreate_schema=False):
logger.info("CONNECTING TO DATABASE...")

connection = psycopg.connect(get_pgconf_as_psycopg_dsn(), autocommit=True)
connection = psycopg.connect(get_pgconf_as_psycopg_dsn(), **DEFAULTS_CONN_ARG)
if PSYCOPG_VERSION == 2:
connection.set_session(autocommit=True)
cursor = connection.cursor()

if not recreate_schema:
Expand Down
5 changes: 4 additions & 1 deletion plugin/teksi_wastewater/processing_provider/TwwSwmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
import subprocess
from datetime import datetime, timedelta

import psycopg
try:
import psycopg
except ImportError:
import psycopg2 as psycopg

MEASURING_POINT_KIND = "Diverse kind of SWMM simulation parameters"
MEASURING_DEVICE_REMARK = "SWMM Simulation"
Expand Down

0 comments on commit 3581781

Please sign in to comment.