-
Notifications
You must be signed in to change notification settings - Fork 0
/
APP_srv_cl.py
103 lines (88 loc) · 4.51 KB
/
APP_srv_cl.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/home/sziller/Projects/901_RasPi_SmartHomeServer/_raspi_smarthome_server/venv/bin/python
"""=== App-interface to start SmartHomeMyCastle Server =======================================
Call this python script as:
python3 APP_srv_cl.py
============================================================================ by Sziller ==="""
import os
import inspect
import logging
import config as conf
import config_prv as conf_prv
from dotenv import load_dotenv
from time_format import TimeFormat as TiFo
from shmc_server import serverClass_SHMC
from shmc_api_classes.auth_services import AuthService
# Create a glorified config-type class, with functions in it to be used with Depends()
# This is basically the same exact approach we use in the function-based version.
AuthService.auth_secret_key = os.getenv("AUTH_SECRET_KEY")
AuthService.auth_algo = os.getenv("AUTH_ALGO")
AuthService.auth_token_expire_mins = os.getenv("AUTH_TOKEN_EXPIRE_MINS")
AuthService.db_fullname_auth = os.getenv("DB_FULLNAME_AUTH")
AuthService.db_style_auth = os.getenv("DB_STYLE_AUTH")
def app_server(**data_passed):
"""=== Function name: app_server ===================================================================================
Use this code to run the SHMC server!
============================================================================================== by Sziller ==="""
cfn = inspect.currentframe().f_code.co_name # current class name
lg.info("START: {:>85} <<<".format(cfn))
lg.warning(" : ======================================")
lg.warning({True: " : = LIVE SESSION =",
False: " : = DEV SESSION ="}[conf.isLIVE])
lg.warning(" : ={:^36}=".format(__name__))
lg.info(" : = user languange: {} =".format(data_passed["lng"]))
lg.warning(" : ======================================")
server = serverClass_SHMC.Server()
for param, arg in data_passed.items(): setattr(server, param, arg)
server.process()
server.serve_forever()
pass
if __name__ == "__main__":
# READ BASIC SETTINGS - START -
# from .env:
load_dotenv()
# <server> is the parent scope. You need to run <server> It includes "/" path to serve Static Pages
# do not define logger info!
# log settings:
log_format = conf.LOG_FORMAT
log_level = getattr(logging, conf.LOG_LEVEL)
log_ts = "_{}".format(TiFo.timestamp()) if conf.LOG_TIMED else ""
log_tf = conf.LOG_TIMEFORMAT
path_root = conf.PATH_ROOT
log_path = conf.LOG_PATH.format(path_root)
log_fullfilename = conf.LOG_FILENAME.format(log_path, log_ts)
# Setting up logger - START -
if not os.path.exists(log_path): os.mkdir(log_path)
lg = logging.getLogger("shmc")
# Using config.py data - configurate logger:
logging.basicConfig(filename=log_fullfilename,
level=log_level,
format=log_format,
datefmt=log_tf,
filemode="w")
# initial sz_messages
lg.warning("FILE: {:>86} <<<".format(__file__))
lg.warning("LOGGER namespace: {:>74} <<<".format(__name__))
lg.debug("listing : config settings:")
for k, v in {param: arg for param, arg in vars(conf).items() if not param.startswith('__')}.items():
lg.debug("{:>20}: {}".format(k, v))
# Setting up logger - ENDED -
kwargs_server = {
"app_path": conf.APP_PATH,
"srv_ip": os.getenv("SRV_IP"),
"srv_port": int(os.getenv("SRV_PORT")),
"session_name_shmc": os.getenv("DB_FULLNAME_SHMC"),
"session_style_shmc": os.getenv("DB_STYLE_SHMC"),
"session_name_auth": os.getenv("DB_FULLNAME_AUTH"),
"session_style_auth": os.getenv("DB_STYLE_AUTH"),
"default_user_list": conf_prv.DEFAULT_USER_LIST,
"lng": conf.LANGUAGE_CODE,
"fsh_dir_info": conf.NECESSARY_DIRECTORIES,
"path_root": conf.PATH_ROOT,
"path_err_msg": conf.PATH_ERROR_MSG.format(conf.PATH_ROOT),
"path_app_doc": conf.PATH_APP_INFO.format(conf.PATH_ROOT),
"path_mount_static_from": conf.PATH_STATIC_FROM,
"path_mount_static_to": conf.PATH_STATIC_TO,
"router_info": conf.APP_ROUTER_INFO,
'auth_service': AuthService
}
app_server(**kwargs_server)