-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
29 lines (24 loc) · 1.07 KB
/
Copy pathsettings.py
File metadata and controls
29 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import sys
import keyring
from dotenv import load_dotenv
base_path = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname(__file__)
load_dotenv(dotenv_path=os.path.join(base_path, '.env'))
APP_SECRET = os.getenv('APP_SECRET')
APP_NAME = "Interface SQL - By Itsuki"
VERSION = os.getenv("APP_VERSION", "0.0")
DB_AUTO_CONNECT = os.getenv('DB_AUTO_CONNECT', 'False').lower() == 'true'
KEYRING_SERVICE = f"{APP_NAME}"
def MAJ_DB_CONFIG(user=None, password=None):
"""
Retourne la config BDD avec user/pass potentiellement fournis à la main,
le reste est récupéré via keyring.
"""
return {
'dbname': keyring.get_password(KEYRING_SERVICE, 'DBNAME'),
'user': user if user is not None else keyring.get_password(KEYRING_SERVICE, 'USER'),
'password': password if password is not None else keyring.get_password(KEYRING_SERVICE, 'PASSWORD'),
'host': keyring.get_password(KEYRING_SERVICE, 'HOST'),
'port': keyring.get_password(KEYRING_SERVICE, 'PORT') or '5432',
}
DB_CONFIG = MAJ_DB_CONFIG()