Commit f37d9b75 authored by Romain Loth's avatar Romain Loth

services: tools exposes our config (incorporate config reading in tools module instead of main)

parent f96eb88d
......@@ -9,10 +9,10 @@ from MySQLdb import connect
if __package__ == 'services':
# when we're run via import
from services.tools import mlog
from services.tools import mlog, REALCONFIG
else:
# when this script is run directly
from tools import mlog
from tools import mlog, REALCONFIG
# sorted columns as declared in DB, as a tuple
......@@ -45,7 +45,7 @@ ORG_COLS = [
("org_city", False, 50)
]
def connect_db(config):
def connect_db(config=REALCONFIG):
"""
Simple connection
......
......@@ -35,7 +35,7 @@ if __package__ == 'services':
print("*** comex services ***")
from services.user import User, login_manager, doors_login
from services.text import keywords
from services.tools import read_config, restparse, mlog, re_hash
from services.tools import restparse, mlog, re_hash, REALCONFIG
from services.db import connect_db, get_or_create_keywords, save_pairs_sch_kw, get_or_create_affiliation, save_scholar
from services.db_to_tina_api.extractDataCustom import MyExtractor as MySQL
else:
......@@ -43,12 +43,12 @@ else:
print("*** comex services (dev server mode) ***")
from user import User, login_manager, doors_login
from text import keywords
from tools import read_config, restparse, mlog, re_hash
from tools import restparse, mlog, re_hash, REALCONFIG
from db import connect_db, get_or_create_keywords, save_pairs_sch_kw, get_or_create_affiliation, save_scholar
from db_to_tina_api.extractDataCustom import MyExtractor as MySQL
# ============= read config ============
config = read_config()
config = REALCONFIG
mlog("DEBUG", "conf\n "+"\n ".join(["%s=%s"%(k,v) for k,v in config.items()]))
......
......@@ -11,6 +11,15 @@ from os import environ, path
from urllib.parse import unquote
from ctypes import c_int32
# ========================== FILL REALCONFIG ===================================
# the main config dict (filled and exposed by this module only)
# --------------------
REALCONFIG = {}
# the expected and default values
CONFIGMENU = [
{"sec": 'main', "var":'LOG_LEVEL', "def": "INFO" },
{"sec": 'main', "var":'COMEX_HOST', "def": '0.0.0.0' },
......@@ -25,9 +34,6 @@ CONFIGMENU = [
{"sec": 'backends', "var":'DOORS_PORT', "def": '8989' }
]
# a copy of the config dict just for this module
REALCONFIG = {}
def home_path():
"""
returns ./../..
......@@ -42,7 +48,8 @@ def read_config():
2) the config file $HOME/parametres_comex.ini
3) hard-coded default values
output is a simple dict (also exposed above as REALCONFIG)
Effect: fills the var REALCONFIG
(no return value)
"""
our_home = home_path()
......@@ -89,9 +96,19 @@ def read_config():
# also add our project home since we have it and we'll need it
REALCONFIG['HOME'] = our_home
return REALCONFIG
# ----------------------------------------
# let's do it now
read_config()
# ok! (REALCONFIG is now ready to export)
# ---------------------------------------
# ============================ other tools =====================================
def re_hash(userinput, salt="verylonverylongverylonverylongverylonverylong"):
"""
Build the captcha's verification hash server side
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment