Skip to content

Commit

Permalink
Remove db.PG_CONN
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Feb 27, 2023
1 parent de27b18 commit 8677045
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
10 changes: 0 additions & 10 deletions src/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,4 @@ def password(self):
return self._db_uri.password if self._db_uri else None


# It's expected to be set from another module
# Example:
# PG_CONN = {
# 'host': LAYMAN_PG_HOST,
# 'port': LAYMAN_PG_PORT,
# 'dbname': LAYMAN_PG_DBNAME,
# 'user': LAYMAN_PG_USER,
# 'password': LAYMAN_PG_PASSWORD,
# }
PG_CONN = {}
PG_URI_STR = str()
5 changes: 3 additions & 2 deletions src/db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask import g

import crs as crs_def
from . import PG_CONN, PG_URI_STR
from . import PG_URI_STR
from .error import Error

logger = logging.getLogger(__name__)
Expand All @@ -13,8 +13,9 @@


def create_connection_cursor(db_uri_str=None, encapsulate_exception=True):
db_uri_str = db_uri_str or PG_URI_STR
try:
connection = psycopg2.connect(db_uri_str) if db_uri_str else psycopg2.connect(**PG_CONN)
connection = psycopg2.connect(db_uri_str)
connection.set_session(autocommit=True)
except BaseException as exc:
if encapsulate_exception:
Expand Down
4 changes: 2 additions & 2 deletions src/layman/layer/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from psycopg2 import sql
from psycopg2.errors import InsufficientPrivilege

from db import util as db_util, PG_CONN
from db import util as db_util
from layman.common.language import get_languages_iso639_2
from layman.http import LaymanError
from layman import settings
Expand Down Expand Up @@ -120,7 +120,7 @@ def import_layer_vector_file_to_internal_table(workspace, layername, main_filepa


def create_ogr2ogr_args(*, schema, table_name, main_filepath, crs_id, output):
pg_conn = ' '.join([f"{k}='{v}'" for k, v in PG_CONN.items()])
pg_conn = ' '.join([f"{k}='{v}'" for k, v in settings.PG_CONN.items()])
ogr2ogr_args = [
'ogr2ogr',
'-nln', table_name,
Expand Down
1 change: 0 additions & 1 deletion src/layman_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class EnumOriginalDataSource(Enum):
'user': LAYMAN_PG_USER,
'password': LAYMAN_PG_PASSWORD,
}
db.PG_CONN = PG_CONN
PG_URI_STR = f"postgresql://{LAYMAN_PG_USER}:{LAYMAN_PG_PASSWORD}@{LAYMAN_PG_HOST}:{LAYMAN_PG_PORT}/{LAYMAN_PG_DBNAME}"
db.PG_URI_STR = PG_URI_STR

Expand Down

0 comments on commit 8677045

Please sign in to comment.