Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 10, 2024
1 parent 12d705a commit 83ca29b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
4 changes: 2 additions & 2 deletions plugin/teksi_wastewater/teksi_wastewater_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
from .tools.twwnetwork import TwwGraphManager
from .utils.plugin_utils import plugin_root_path
from .utils.translation import setup_i18n
from .utils.tww_validity_check import tww_check_oid_prefix
from .utils.twwlayermanager import TwwLayerManager, TwwLayerNotifier
from .utils.twwlogging import TwwQgsLogHandler
from .utils.tww_validity_check import tww_check_oid_prefix,tww_check_fk_defaults

LOGFORMAT = "%(asctime)s:%(levelname)s:%(module)s:%(message)s"

Expand Down Expand Up @@ -329,7 +329,7 @@ def tww_validity_check(self):
msg,
level=Qgis.Critical,
)

def unload(self):
"""
Called when unloading
Expand Down
45 changes: 19 additions & 26 deletions plugin/teksi_wastewater/utils/tww_validity_check.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import logging
import os
from ..interlis import config
from .interlis.utils.various import (
CmdException,
LoggingHandlerContext,
get_pgconf_as_psycopg_dsn,
logger,
make_log_path,
)
from .interlis.utils.various import get_pgconf_as_psycopg_dsn, logger

try:
import psycopg
Expand All @@ -20,46 +11,48 @@
PSYCOPG_VERSION = 2
DEFAULTS_CONN_ARG = {}


def tww_check_oid_prefix(pgservice):
"""Check whether the oid_prefix is set up for production
"""
"""Check whether the oid_prefix is set up for production"""
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("Checking setup of oid prefix")
cursor.execute("SELECT prefix FROM tww_sys.oid_prefixes WHERE active;")
prefixes=cursor.fetchall()
active_pref=prefixes[0].prefix
msgtxt=[]
prefixes = cursor.fetchall()
active_pref = prefixes[0].prefix
msgtxt = []
if len(prefixes) > 1:
msgtxt.append("more than one oid_prefix set to active. Generation of Object-ID will not work")
if active_pref == 'ch000000':
msgtxt.append(
"more than one oid_prefix set to active. Generation of Object-ID will not work"
)
if active_pref == "ch000000":
msgtxt.append("OID prefix set to 'ch000000'. Database not safe for production")

connection.commit()
connection.close()
return msgtxt


def tww_check_fk_defaults(pgservice):
"""Check whether the database is set up for production
"""
"""Check whether the database is set up for production"""
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("Checking setup of default_values")
cursor.execute("SELECT fieldname,value_obj_id from tww_od.default_values;")
defaults=[item["fieldname"] for item in cursor.fetchall()]
vals =[item["value_obj_id"] for item in cursor.fetchall()]
msgtxt=[]
defaults = [item["fieldname"] for item in cursor.fetchall()]
vals = [item["value_obj_id"] for item in cursor.fetchall()]
msgtxt = []
if None in vals:
msgtxt.append("There is an undefined default value in tww_od.default_values")
elif not all(x in defaults for x in ['fk_provider', 'fk_dataowner']) :
elif not all(x in defaults for x in ["fk_provider", "fk_dataowner"]):
msgtxt.append("'fk_provider' or 'fk_dataowner' not set in tww_od.default_values")

connection.commit()
connection.close()
return msgtxt
return msgtxt

0 comments on commit 83ca29b

Please sign in to comment.