ka-uts-com 1.0.0.240823__py3-none-any.whl → 1.0.1.250131__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- build/lib/dist/ka_uts_com-1.0.1.250131-py3-none-any.whl +0 -0
- build/lib/dist/ka_uts_com-1.0.1.250131.tar.gz +0 -0
- build/lib/ka_uts_com/__version__.py +1 -1
- build/lib/ka_uts_com/base/app_.py +51 -0
- build/lib/ka_uts_com/base/cfg_.py +27 -0
- build/lib/ka_uts_com/base/exit_.py +37 -0
- build/lib/ka_uts_com/base/log_.py +115 -0
- build/lib/ka_uts_com/com.py +42 -192
- build/lib/ka_uts_com/data/{log.standard.yml → log.std.yml} +3 -3
- build/lib/ka_uts_com/data/{log.personal.yml → log.usr.yml} +34 -42
- build/lib/ka_uts_com/decorators/dec.py +13 -0
- build/lib/ka_uts_com/fnc.py +29 -24
- build/lib/ka_uts_com/ioc/jinja2_.py +42 -0
- build/lib/ka_uts_com/ioc/yaml_.py +30 -0
- build/lib/ka_uts_com/log.py +32 -20
- build/lib/ka_uts_com/timer.py +17 -24
- build/lib/ka_uts_com/utils/aoeqstmt.py +39 -0
- build/lib/ka_uts_com/{date.py → utils/date.py} +4 -4
- build/lib/ka_uts_com/utils/doeq.py +99 -0
- {ka_uts_com → build/lib/ka_uts_com/utils}/pacmod.py +30 -34
- build/lib/ka_uts_com/utils/py.typed +0 -0
- build/lib/ka_uts_com/{str.py → utils/str.py} +36 -39
- dist/ka_uts_com-1.0.1.250131-py3-none-any.whl +0 -0
- dist/ka_uts_com-1.0.1.250131.tar.gz +0 -0
- ka_uts_com/__version__.py +1 -1
- ka_uts_com/base/app_.py +51 -0
- ka_uts_com/base/cfg_.py +27 -0
- ka_uts_com/base/exit_.py +37 -0
- ka_uts_com/base/log_.py +115 -0
- ka_uts_com/com.py +42 -192
- ka_uts_com/data/{log.standard.yml → log.std.yml} +3 -3
- ka_uts_com/data/{log.personal.yml → log.usr.yml} +34 -42
- ka_uts_com/decorators/dec.py +13 -0
- ka_uts_com/fnc.py +29 -24
- ka_uts_com/ioc/jinja2_.py +42 -0
- ka_uts_com/ioc/yaml_.py +30 -0
- ka_uts_com/log.py +32 -20
- ka_uts_com/timer.py +17 -24
- ka_uts_com/utils/aoeqstmt.py +39 -0
- ka_uts_com/{date.py → utils/date.py} +4 -4
- ka_uts_com/utils/doeq.py +99 -0
- {build/lib/ka_uts_com → ka_uts_com/utils}/pacmod.py +30 -34
- ka_uts_com/utils/py.typed +0 -0
- ka_uts_com/{str.py → utils/str.py} +36 -39
- ka_uts_com-1.0.1.250131.dist-info/METADATA +1628 -0
- ka_uts_com-1.0.1.250131.dist-info/RECORD +55 -0
- {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-1.0.1.250131.dist-info}/WHEEL +1 -1
- build/lib/dist/ka_uts_com-1.0.0.240823-py3-none-any.whl +0 -0
- build/lib/dist/ka_uts_com-1.0.0.240823.tar.gz +0 -0
- build/lib/ka_uts_com/aeq.py +0 -87
- build/lib/ka_uts_com/argv.py +0 -49
- build/lib/ka_uts_com/ioc.py +0 -57
- dist/ka_uts_com-1.0.0.240823-py3-none-any.whl +0 -0
- dist/ka_uts_com-1.0.0.240823.tar.gz +0 -0
- ka_uts_com/aeq.py +0 -87
- ka_uts_com/argv.py +0 -49
- ka_uts_com/ioc.py +0 -57
- ka_uts_com-1.0.0.240823.dist-info/METADATA +0 -943
- ka_uts_com-1.0.0.240823.dist-info/RECORD +0 -41
- {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-1.0.1.250131.dist-info/licenses}/LICENSE.txt +0 -0
- {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-1.0.1.250131.dist-info}/top_level.txt +0 -0
ka_uts_com/com.py
CHANGED
@@ -1,205 +1,52 @@
|
|
1
1
|
# coding=utf-8
|
2
|
+
from typing import Any
|
2
3
|
|
4
|
+
import os
|
5
|
+
import time
|
3
6
|
import calendar
|
4
7
|
import logging
|
5
8
|
import logging.config
|
6
9
|
from logging import Logger
|
7
|
-
|
8
|
-
import os
|
9
|
-
import time
|
10
10
|
from datetime import datetime
|
11
11
|
|
12
|
-
from ka_uts_com.
|
13
|
-
from ka_uts_com.
|
14
|
-
from ka_uts_com.
|
15
|
-
|
16
|
-
from
|
12
|
+
from ka_uts_com.utils.aoeqstmt import AoEqStmt
|
13
|
+
from ka_uts_com.base.app_ import App_
|
14
|
+
from ka_uts_com.base.cfg_ import Cfg_
|
15
|
+
from ka_uts_com.base.exit_ import Exit_
|
16
|
+
from ka_uts_com.base.log_ import Log_
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
TyAny = Any
|
19
|
+
TyDateTime = datetime
|
20
|
+
TyTimeStamp = int
|
21
|
+
TyArr = list[Any]
|
22
|
+
TyBool = bool
|
23
|
+
TyDic = dict[Any, Any]
|
24
|
+
TyLogger = Logger
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
class LogStandard:
|
30
|
-
"""Standard Logging
|
31
|
-
"""
|
32
|
-
sw_init: bool = False
|
33
|
-
cfg: T_Dic = {}
|
34
|
-
log: Logger = logging.getLogger('dummy_logger')
|
35
|
-
logfile: str = 'log.standard.yml'
|
36
|
-
|
37
|
-
@staticmethod
|
38
|
-
def read(pacmod: T_Dic, filename: str) -> Any:
|
39
|
-
"""Read log file path with jinja2
|
40
|
-
"""
|
41
|
-
# path: str = Pacmod.Path.Log.sh_cfg(filename=filename)
|
42
|
-
path: str = Pacmod.sh_path_cfg_log(filename=filename)
|
43
|
-
tenant: str = pacmod['tenant']
|
44
|
-
package: str = pacmod['package']
|
45
|
-
module: str = pacmod['module']
|
46
|
-
pid = Com.pid
|
47
|
-
ts: TN_DT = Com.ts_start
|
48
|
-
cfg = Jinja2.read(
|
49
|
-
path, tenant=tenant,
|
50
|
-
package=package, module=module,
|
51
|
-
pid=pid, ts=ts)
|
52
|
-
return cfg
|
53
|
-
|
54
|
-
@classmethod
|
55
|
-
def set_level(cls, sw_debug: bool) -> None:
|
56
|
-
"""Set static variable log level in log configuration handlers
|
57
|
-
"""
|
58
|
-
if sw_debug:
|
59
|
-
level = logging.DEBUG
|
60
|
-
else:
|
61
|
-
level = logging.INFO
|
62
|
-
cls.cfg['handlers']['main_debug_console']['level'] = level
|
63
|
-
cls.cfg['handlers']['main_debug_file']['level'] = level
|
64
|
-
|
65
|
-
@classmethod
|
66
|
-
def init(
|
67
|
-
cls, **kwargs) -> None:
|
68
|
-
cls.sw_init = True
|
69
|
-
cls.cfg = cls.read(Com.pacmod_curr, cls.logfile)
|
70
|
-
sw_debug: Any = kwargs.get('sw_debug')
|
71
|
-
cls.set_level(sw_debug)
|
72
|
-
logging.config.dictConfig(cls.cfg)
|
73
|
-
cls.log = logging.getLogger('main')
|
74
|
-
|
75
|
-
@classmethod
|
76
|
-
def sh(cls, **kwargs) -> Any:
|
77
|
-
if cls.sw_init:
|
78
|
-
return cls.log
|
79
|
-
cls.init(**kwargs)
|
80
|
-
return cls.log
|
81
|
-
|
82
|
-
|
83
|
-
class LogPersonal:
|
84
|
-
"""Personal Logging
|
85
|
-
"""
|
86
|
-
sw_init: bool = False
|
87
|
-
cfg: T_Dic = {}
|
88
|
-
logfile = 'log.person.yml'
|
89
|
-
log: Logger = logging.getLogger('dummy_logger')
|
90
|
-
|
91
|
-
@classmethod
|
92
|
-
def read(cls, pacmod: T_Dic, person: Any, filename: str) -> Any:
|
93
|
-
path: str = Pacmod.sh_path_cfg_log(filename=filename)
|
94
|
-
package: str = pacmod['package']
|
95
|
-
module: str = pacmod['module']
|
96
|
-
return Jinja2.read(
|
97
|
-
path, package=package, module=module, person=person,
|
98
|
-
pid=Com.pid, ts=Com.ts_start)
|
99
|
-
|
100
|
-
@classmethod
|
101
|
-
def set_level(cls, person: str, sw_debug: bool) -> None:
|
102
|
-
if sw_debug:
|
103
|
-
level = logging.DEBUG
|
104
|
-
else:
|
105
|
-
level = logging.INFO
|
106
|
-
cls.cfg['handlers'][f'{person}_debug_console']['level'] = level
|
107
|
-
cls.cfg['handlers'][f'{person}_debug_file']['level'] = level
|
108
|
-
|
109
|
-
@classmethod
|
110
|
-
def init(cls, pacmod: T_Dic, person: str, sw_debug: bool) -> None:
|
111
|
-
cls.cfg = cls.read(pacmod, person, cls.logfile)
|
112
|
-
cls.set_level(person, sw_debug)
|
113
|
-
logging.config.dictConfig(cls.cfg)
|
114
|
-
cls.log = logging.getLogger(person)
|
115
|
-
|
116
|
-
@classmethod
|
117
|
-
def sh(cls, **kwargs) -> Any:
|
118
|
-
if cls.sw_init:
|
119
|
-
return cls.log
|
120
|
-
cls.init(**kwargs)
|
121
|
-
return cls.log
|
122
|
-
|
123
|
-
|
124
|
-
class Cfg:
|
125
|
-
"""Configuration Class
|
126
|
-
"""
|
127
|
-
@classmethod
|
128
|
-
def init(cls, pacmod: T_Dic) -> TN_Dic:
|
129
|
-
""" the package data directory has to contain a __init__.py
|
130
|
-
file otherwise the objects notation {package}.data to
|
131
|
-
locate the package data directory is invalid
|
132
|
-
"""
|
133
|
-
_dic: TN_Dic = Yaml.read(Pacmod.sh_path_cfg_yaml(pacmod))
|
134
|
-
return _dic
|
135
|
-
|
136
|
-
|
137
|
-
class Mgo:
|
138
|
-
"""Mongo DB Class
|
139
|
-
"""
|
140
|
-
client = None
|
141
|
-
|
142
|
-
|
143
|
-
class App:
|
144
|
-
"""Aplication Class
|
145
|
-
"""
|
146
|
-
sw_init: T_Bool = False
|
147
|
-
httpmod: T_Any = None
|
148
|
-
sw_replace_keys: TN_Bool = None
|
149
|
-
keys: TN_Arr = None
|
150
|
-
reqs: T_Dic = {}
|
151
|
-
app: T_Dic = {}
|
152
|
-
|
153
|
-
@classmethod
|
154
|
-
def init(cls, **kwargs) -> Any:
|
155
|
-
cls.sw_init = True
|
156
|
-
cls.httpmod = kwargs.get('httpmod')
|
157
|
-
cls.sw_replace_keys = kwargs.get('sw_replace_keys', False)
|
158
|
-
try:
|
159
|
-
if cls.sw_replace_keys:
|
160
|
-
pacmod = kwargs.get('pacmod_curr')
|
161
|
-
# cls.keys = Yaml.read(Pacmod.Pmd.sh_path_keys(pacmod))
|
162
|
-
cls.keys = Yaml.read(Pacmod.sh_path_keys_yaml(pacmod))
|
163
|
-
except Exception as e:
|
164
|
-
if Com.Log is not None:
|
165
|
-
fnc_error: Callable = Com.Log.error
|
166
|
-
fnc_error(e, exc_info=True)
|
167
|
-
raise
|
168
|
-
return cls
|
169
|
-
|
170
|
-
@classmethod
|
171
|
-
def sh(cls, **kwargs) -> Any:
|
172
|
-
if cls.sw_init:
|
173
|
-
return cls
|
174
|
-
cls.init(**kwargs)
|
175
|
-
return cls
|
176
|
-
|
177
|
-
|
178
|
-
class Exit:
|
179
|
-
"""Exit Class
|
180
|
-
"""
|
181
|
-
sw_critical: bool = False
|
182
|
-
sw_stop: bool = False
|
183
|
-
sw_interactive: bool = False
|
26
|
+
TnAny = None | Any
|
27
|
+
TnArr = None | TyArr
|
28
|
+
TnDic = None | TyDic
|
29
|
+
TnTimeStamp = None | TyTimeStamp
|
30
|
+
TnDateTime = None | TyDateTime
|
184
31
|
|
185
32
|
|
186
33
|
class Com:
|
187
34
|
"""Communication Class
|
188
35
|
"""
|
189
36
|
sw_init: bool = False
|
190
|
-
cfg:
|
37
|
+
cfg: TnDic = None
|
191
38
|
pid = None
|
192
|
-
|
39
|
+
d_pacmod: TyDic = {}
|
193
40
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
41
|
+
ts: TnTimeStamp
|
42
|
+
ts_start: TnDateTime = None
|
43
|
+
ts_end: TnDateTime = None
|
44
|
+
ts_etime: TnDateTime = None
|
45
|
+
d_timer: TyDic = {}
|
198
46
|
|
199
|
-
# Log = None
|
200
47
|
Log: Logger = logging.getLogger('dummy_logger')
|
201
|
-
App = None
|
202
|
-
Exit =
|
48
|
+
App: Any = None
|
49
|
+
Exit: Any = None
|
203
50
|
|
204
51
|
@classmethod
|
205
52
|
def init(cls, **kwargs):
|
@@ -208,15 +55,18 @@ class Com:
|
|
208
55
|
if cls.sw_init:
|
209
56
|
return
|
210
57
|
cls.sw_init = True
|
211
|
-
|
212
|
-
cls.
|
213
|
-
cls.ts_start = calendar.timegm(time.gmtime())
|
58
|
+
cls.d_pacmod = kwargs.get('d_pacmod', {})
|
59
|
+
cls.ts = calendar.timegm(time.gmtime())
|
214
60
|
cls.pid = os.getpid()
|
215
61
|
|
216
|
-
cls.
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
62
|
+
cls.Log = Log_.sh(cls, **kwargs)
|
63
|
+
cls.cfg = Cfg_.sh(cls.Log, cls.d_pacmod)
|
64
|
+
cls.App = App_.sh(cls.Log, **kwargs)
|
65
|
+
cls.Exit = Exit_.sh(**kwargs)
|
66
|
+
|
67
|
+
@classmethod
|
68
|
+
def sh_kwargs(cls, root_cls, d_parms, *args) -> TyDic:
|
69
|
+
_kwargs: TyDic = AoEqStmt.sh_d_eq(
|
70
|
+
*args, d_parms=d_parms, root_cls=root_cls)
|
71
|
+
cls.init(**_kwargs)
|
72
|
+
return _kwargs
|
@@ -42,21 +42,21 @@ handlers:
|
|
42
42
|
class: 'logging.FileHandler'
|
43
43
|
level: DEBUG
|
44
44
|
formatter: main_error
|
45
|
-
filename: '
|
45
|
+
filename: '{{debug_dir}}/debs_{{pid}}_{{ts}}.log'
|
46
46
|
mode: 'a'
|
47
47
|
|
48
48
|
main_info_file:
|
49
49
|
class: 'logging.FileHandler'
|
50
50
|
level: INFO
|
51
51
|
formatter: main_info
|
52
|
-
filename: '
|
52
|
+
filename: '{{info_dir}}/logs_{{pid}}_{{ts}}.log'
|
53
53
|
mode: 'a'
|
54
54
|
|
55
55
|
main_error_file:
|
56
56
|
class: 'logging.FileHandler'
|
57
57
|
level: ERROR
|
58
58
|
formatter: main_error
|
59
|
-
filename: '
|
59
|
+
filename: '{{error_dir}}/errs_{{pid}}_{{ts}}.log'
|
60
60
|
mode: 'a'
|
61
61
|
|
62
62
|
main_critical_mail:
|
@@ -1,49 +1,33 @@
|
|
1
1
|
version: 1
|
2
|
-
|
3
2
|
disable_existing_loggers: False
|
4
3
|
|
5
|
-
root:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
# root:
|
5
|
+
# level: DEBUG
|
6
|
+
# handlers:
|
7
|
+
# - debug_console
|
8
|
+
# - debug_file
|
10
9
|
|
11
10
|
loggers:
|
12
11
|
|
13
|
-
# main logger
|
14
|
-
main:
|
15
|
-
level: 'NOTSET'
|
16
|
-
handlers:
|
17
|
-
- debug_console
|
18
|
-
- debug_file
|
19
|
-
- info_file
|
20
|
-
- error_file
|
21
|
-
|
22
12
|
# person logger
|
23
13
|
person:
|
24
|
-
level: NOTSET
|
14
|
+
# level: NOTSET
|
15
|
+
level: DEBUG
|
25
16
|
handlers:
|
26
|
-
-
|
27
|
-
-
|
28
|
-
-
|
29
|
-
-
|
17
|
+
- person_debug_console
|
18
|
+
- person_debug_file
|
19
|
+
- person_info_file
|
20
|
+
- person_error_file
|
30
21
|
|
31
22
|
handlers:
|
32
23
|
|
33
|
-
|
24
|
+
person_debug_console:
|
34
25
|
class: 'logging.StreamHandler'
|
35
26
|
level: DEBUG
|
36
|
-
formatter:
|
27
|
+
formatter: person_debug
|
37
28
|
stream: 'ext://sys.stderr'
|
38
29
|
|
39
|
-
|
40
|
-
class: 'logging.FileHandler'
|
41
|
-
level: DEBUG
|
42
|
-
formatter: error
|
43
|
-
filename: 'debug.log'
|
44
|
-
mode: 'a'
|
45
|
-
|
46
|
-
# info_rotating_file_handler:
|
30
|
+
# person_info_rotating_file_handler:
|
47
31
|
# class: 'logging.handlers.RotatingFileHandler'
|
48
32
|
# level: INFO
|
49
33
|
# formatter: info
|
@@ -53,24 +37,31 @@ handlers:
|
|
53
37
|
# backupCount: 10
|
54
38
|
# encoding: utf8
|
55
39
|
|
56
|
-
|
40
|
+
person_debug_file:
|
41
|
+
class: 'logging.FileHandler'
|
42
|
+
level: DEBUG
|
43
|
+
formatter: person_error
|
44
|
+
filename: '{{debug_dir}}/debs_{{pid}}_{{ts}}.log'
|
45
|
+
mode: 'a'
|
46
|
+
|
47
|
+
person_info_file:
|
57
48
|
class: 'logging.FileHandler'
|
58
49
|
level: INFO
|
59
|
-
formatter:
|
60
|
-
filename: '
|
50
|
+
formatter: person_info
|
51
|
+
filename: '{{info_dir}}/logs_{{pid}}_{{ts}}.log'
|
61
52
|
mode: 'a'
|
62
53
|
|
63
|
-
|
54
|
+
person_error_file:
|
64
55
|
class: 'logging.FileHandler'
|
65
56
|
level: ERROR
|
66
|
-
formatter:
|
67
|
-
filename: '
|
57
|
+
formatter: person_error
|
58
|
+
filename: '{{error_dir}}/errs_{{pid}}_{{ts}}.log'
|
68
59
|
mode: 'a'
|
69
60
|
|
70
|
-
|
61
|
+
person_critical_mail:
|
71
62
|
class: 'logging.handlers.SMTPHandler'
|
72
63
|
level: CRITICAL
|
73
|
-
formatter:
|
64
|
+
formatter: person_critical
|
74
65
|
mailhost : localhost
|
75
66
|
fromaddr: 'monitoring@domain.com'
|
76
67
|
toaddrs:
|
@@ -78,16 +69,17 @@ handlers:
|
|
78
69
|
- 'qa@domain.com'
|
79
70
|
subject: 'Critical error with application name'
|
80
71
|
|
72
|
+
|
81
73
|
formatters:
|
82
74
|
|
83
|
-
|
75
|
+
person_info:
|
84
76
|
format: '%(asctime)s-%(levelname)s-%(name)s::%(module)s|%(lineno)s:: %(message)s'
|
85
|
-
|
77
|
+
person_debug:
|
86
78
|
format: '%(asctime)-15s %(levelname)s-%(name)s-%(process)d::%(module)s.%(funcName)s|%(lineno)s:: %(message)s'
|
87
79
|
datefmt: '%Y-%m-%d %H:%M:%S'
|
88
|
-
|
80
|
+
person_error:
|
89
81
|
format: '%(asctime)-15s %(levelname)s-%(name)s-%(process)d::%(module)s.%(funcName)s|%(lineno)s:: %(message)s'
|
90
82
|
datefmt: '%Y-%m-%d %H:%M:%S'
|
91
|
-
|
83
|
+
person_critical:
|
92
84
|
format: '%(asctime)-15s %(levelname)s-%(name)s-%(process)d::%(module)s.%(funcName)s|%(lineno)s:: %(message)s'
|
93
85
|
datefmt: '%Y-%m-%d %H:%M:%S'
|
ka_uts_com/fnc.py
CHANGED
@@ -1,37 +1,42 @@
|
|
1
1
|
# coding=utf-8
|
2
|
+
from collections.abc import Callable
|
3
|
+
from typing import Any
|
2
4
|
|
3
|
-
|
5
|
+
TyArr = list[Any]
|
6
|
+
TyCallable = Callable[..., Any]
|
7
|
+
TyDic = dict[Any, Any]
|
8
|
+
TyArrDic = TyArr | TyDic
|
9
|
+
TyDoC = dict[str, TyCallable]
|
10
|
+
TyMsg = str
|
4
11
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
TN_Str = None | str
|
9
|
-
TN_Callable = None | Callable
|
12
|
+
TnStr = None | str
|
13
|
+
TnDoC = None | TyDoC
|
14
|
+
TnCallable = None | TyCallable
|
10
15
|
|
11
16
|
|
12
17
|
class Fnc:
|
13
|
-
"""
|
18
|
+
"""
|
19
|
+
Functions
|
14
20
|
"""
|
15
21
|
@staticmethod
|
16
|
-
def
|
17
|
-
|
18
|
-
msg = f"key {key} is None or empty string"
|
19
|
-
raise Exception(msg)
|
20
|
-
_fnc: TN_Callable = d_key2fnc.get(key)
|
21
|
-
if not _fnc:
|
22
|
-
msg = f"key {key} is not defined in function table {d_key2fnc}"
|
23
|
-
raise Exception(msg)
|
24
|
-
else:
|
25
|
-
return _fnc
|
22
|
+
def identity(obj: Any) -> Any:
|
23
|
+
return obj
|
26
24
|
|
27
25
|
@staticmethod
|
28
|
-
def
|
26
|
+
def sh(doc: TnDoC, key: TnStr) -> TyCallable:
|
27
|
+
if not doc:
|
28
|
+
msg = f"function table: {doc} is not defined"
|
29
|
+
raise Exception(msg)
|
29
30
|
if not key:
|
30
|
-
msg = f"key {key} is
|
31
|
+
msg = f"key: {key} is not defined"
|
31
32
|
raise Exception(msg)
|
32
|
-
|
33
|
-
if not
|
34
|
-
msg = f"key {key} is not defined in function table {
|
33
|
+
fnc: TnCallable = doc.get(key)
|
34
|
+
if not fnc:
|
35
|
+
msg = f"key: {key} is not defined in function table: {doc}"
|
35
36
|
raise Exception(msg)
|
36
|
-
|
37
|
-
|
37
|
+
return fnc
|
38
|
+
|
39
|
+
@classmethod
|
40
|
+
def ex(cls, doc: TnDoC, key: TnStr, args_kwargs: TyArrDic) -> Any:
|
41
|
+
fnc: TyCallable = cls.sh(doc, key)
|
42
|
+
return fnc(args_kwargs)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
# from collections.abc import Callable
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
import os
|
6
|
+
import yaml
|
7
|
+
import jinja2
|
8
|
+
# import logging
|
9
|
+
# import logging.config
|
10
|
+
from logging import Logger
|
11
|
+
|
12
|
+
TyAny = Any
|
13
|
+
TyDic = dict[Any, Any]
|
14
|
+
TyLogger = Logger
|
15
|
+
|
16
|
+
TnDic = None | TyDic
|
17
|
+
|
18
|
+
|
19
|
+
class Jinja2_:
|
20
|
+
|
21
|
+
""" Manage Object to Json file affilitation
|
22
|
+
"""
|
23
|
+
@staticmethod
|
24
|
+
def read_template(path: str) -> Any:
|
25
|
+
directory, file = os.path.split(path)
|
26
|
+
env = jinja2.Environment(loader=jinja2.FileSystemLoader(directory))
|
27
|
+
return env.get_template(file)
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def read(cls, path: str, log: TyLogger, **kwargs) -> Any:
|
31
|
+
try:
|
32
|
+
# read jinja template from file
|
33
|
+
template = cls.read_template(path)
|
34
|
+
# render template as yaml string
|
35
|
+
template_rendered = template.render(kwargs)
|
36
|
+
# load yaml string into object
|
37
|
+
obj: Any = yaml.safe_load(template_rendered)
|
38
|
+
return obj
|
39
|
+
except IOError as exc:
|
40
|
+
log.error(exc, exc_info=True)
|
41
|
+
# log.error(f"No such file or directory: {path}")
|
42
|
+
raise
|
ka_uts_com/ioc/yaml_.py
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
import yaml
|
3
|
+
|
4
|
+
from typing import Any
|
5
|
+
TyAny = Any
|
6
|
+
TyArr = list[Any]
|
7
|
+
TyDic = dict[Any, Any]
|
8
|
+
|
9
|
+
TnAny = None | Any
|
10
|
+
|
11
|
+
|
12
|
+
class Yaml_:
|
13
|
+
""" Manage Object to Yaml file affilitation
|
14
|
+
"""
|
15
|
+
@staticmethod
|
16
|
+
def read(path: str, log) -> TnAny:
|
17
|
+
try:
|
18
|
+
with open(path) as fd:
|
19
|
+
# The Loader parameter handles the conversion from YAML
|
20
|
+
# scalar values to Python object format
|
21
|
+
obj = yaml.load(fd, Loader=yaml.SafeLoader)
|
22
|
+
return obj
|
23
|
+
except FileNotFoundError:
|
24
|
+
log.error(f"No such file or directory: {path}")
|
25
|
+
except IOError:
|
26
|
+
# if Com.Log is not None:
|
27
|
+
# fnc_error = Com.Log.error
|
28
|
+
# fnc_error(exc, exc_info=True)
|
29
|
+
raise
|
30
|
+
return None
|
ka_uts_com/log.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
from ka_uts_com.com import Com
|
2
|
-
|
3
|
-
|
2
|
+
from typing import Any
|
3
|
+
TyDic = dict[Any, Any]
|
4
4
|
|
5
5
|
|
6
6
|
class Log:
|
@@ -8,56 +8,68 @@ class Log:
|
|
8
8
|
"""
|
9
9
|
class Eq:
|
10
10
|
|
11
|
-
@staticmethod
|
12
|
-
def sh(key: Any, value: Any) -> str:
|
13
|
-
""" Show Key, Value as Equate
|
14
|
-
"""
|
15
|
-
return f"{key} = {value}"
|
16
|
-
|
17
11
|
@classmethod
|
18
12
|
def debug(cls, key: Any, value: Any) -> None:
|
19
|
-
Log.debug(
|
13
|
+
Log.debug(f"{key} = {value}", stacklevel=3)
|
20
14
|
|
21
15
|
@classmethod
|
22
16
|
def error(cls, key: Any, value: Any) -> None:
|
23
|
-
Log.error(
|
17
|
+
Log.error(f"{key} = {value}", stacklevel=3)
|
24
18
|
|
25
19
|
@classmethod
|
26
20
|
def info(cls, key: Any, value: Any) -> None:
|
27
|
-
Log.info(
|
21
|
+
Log.info(f"{key} = {value}", stacklevel=3)
|
28
22
|
|
29
23
|
@classmethod
|
30
24
|
def warning(cls, key: Any, value: Any) -> None:
|
31
|
-
Log.warning(
|
25
|
+
Log.warning(f"{key} = {value}", stacklevel=3)
|
26
|
+
|
27
|
+
class Dic:
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def debug(cls, dic: TyDic) -> None:
|
31
|
+
for key, value in dic.items():
|
32
|
+
Log.debug(f"{key} = {value}", stacklevel=3)
|
33
|
+
|
34
|
+
@classmethod
|
35
|
+
def error(cls, dic: TyDic) -> None:
|
36
|
+
for key, value in dic.items():
|
37
|
+
Log.error(f"{key} = {value}", stacklevel=3)
|
38
|
+
|
39
|
+
@classmethod
|
40
|
+
def info(cls, dic: TyDic) -> None:
|
41
|
+
for key, value in dic.items():
|
42
|
+
Log.info(f"{key} = {value}", stacklevel=3)
|
43
|
+
|
44
|
+
@classmethod
|
45
|
+
def warning(cls, dic: TyDic) -> None:
|
46
|
+
for key, value in dic.items():
|
47
|
+
Log.warning(f"{key} = {value}", stacklevel=3)
|
32
48
|
|
33
49
|
@staticmethod
|
34
50
|
def debug(*args, **kwargs) -> None:
|
35
51
|
if kwargs is None:
|
36
52
|
kwargs = {}
|
37
53
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
38
|
-
|
39
|
-
fnc_debug(*args, **kwargs)
|
54
|
+
Com.Log.debug(*args, **kwargs)
|
40
55
|
|
41
56
|
@staticmethod
|
42
57
|
def error(*args, **kwargs) -> None:
|
43
58
|
if kwargs is None:
|
44
59
|
kwargs = {}
|
45
60
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
46
|
-
|
47
|
-
fnc_error(*args, **kwargs)
|
61
|
+
Com.Log.error(*args, **kwargs)
|
48
62
|
|
49
63
|
@staticmethod
|
50
64
|
def info(*args, **kwargs) -> None:
|
51
65
|
if kwargs is None:
|
52
66
|
kwargs = {}
|
53
67
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
54
|
-
|
55
|
-
fnc_info(*args, **kwargs)
|
68
|
+
Com.Log.info(*args, **kwargs)
|
56
69
|
|
57
70
|
@staticmethod
|
58
71
|
def warning(*args, **kwargs) -> None:
|
59
72
|
if kwargs is None:
|
60
73
|
kwargs = {}
|
61
74
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
62
|
-
|
63
|
-
fnc_warning(*args, **kwargs)
|
75
|
+
Com.Log.warning(*args, **kwargs)
|