ka-uts-com 1.0.1.250131__py3-none-any.whl → 2.1.0.250408__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-2.0.0.250407-py3-none-any.whl +0 -0
- build/lib/dist/ka_uts_com-2.0.0.250407.tar.gz +0 -0
- build/lib/ka_uts_com/__version__.py +1 -1
- build/lib/ka_uts_com/base/app_.py +10 -11
- build/lib/ka_uts_com/base/cfg_.py +14 -5
- build/lib/ka_uts_com/base/log_.py +66 -50
- build/lib/ka_uts_com/com.py +54 -11
- build/lib/ka_uts_com/data/log.std.yml +47 -26
- build/lib/ka_uts_com/data/log.usr.yml +46 -25
- build/lib/ka_uts_com/ioc/jinja2_.py +1 -1
- build/lib/ka_uts_com/ioc/yaml_.py +2 -1
- build/lib/ka_uts_com/log.py +23 -12
- build/lib/ka_uts_com/timer.py +10 -6
- build/lib/ka_uts_com/utils/aoeqstmt.py +0 -2
- build/lib/ka_uts_com/utils/doeq.py +7 -7
- build/lib/ka_uts_com/utils/pac.py +35 -0
- build/lib/ka_uts_com/utils/pacmod.py +74 -72
- dist/ka_uts_com-2.0.0.250407-py3-none-any.whl +0 -0
- dist/ka_uts_com-2.0.0.250407.tar.gz +0 -0
- ka_uts_com/__version__.py +1 -1
- ka_uts_com/base/app_.py +10 -11
- ka_uts_com/base/cfg_.py +14 -5
- ka_uts_com/base/log_.py +66 -50
- ka_uts_com/com.py +54 -11
- ka_uts_com/data/log.std.yml +47 -26
- ka_uts_com/data/log.usr.yml +46 -25
- ka_uts_com/ioc/jinja2_.py +1 -1
- ka_uts_com/ioc/yaml_.py +2 -1
- ka_uts_com/log.py +23 -12
- ka_uts_com/timer.py +10 -6
- ka_uts_com/utils/aoeqstmt.py +0 -2
- ka_uts_com/utils/doeq.py +7 -7
- ka_uts_com/utils/pac.py +35 -0
- ka_uts_com/utils/pacmod.py +74 -72
- {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.1.0.250408.dist-info}/METADATA +389 -406
- ka_uts_com-2.1.0.250408.dist-info/RECORD +55 -0
- {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.1.0.250408.dist-info}/licenses/LICENSE.txt +1 -2
- 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/utils/py.typed +0 -0
- 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/utils/py.typed +0 -0
- ka_uts_com-1.0.1.250131.dist-info/RECORD +0 -55
- {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.1.0.250408.dist-info}/WHEEL +0 -0
- {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.1.0.250408.dist-info}/top_level.txt +0 -0
build/lib/ka_uts_com/log.py
CHANGED
@@ -8,21 +8,25 @@ class Log:
|
|
8
8
|
"""
|
9
9
|
class Eq:
|
10
10
|
|
11
|
-
@classmethod
|
12
|
-
def debug(cls, key: Any, value: Any) -> None:
|
13
|
-
Log.debug(f"{key} = {value}", stacklevel=3)
|
14
|
-
|
15
11
|
@classmethod
|
16
12
|
def error(cls, key: Any, value: Any) -> None:
|
17
13
|
Log.error(f"{key} = {value}", stacklevel=3)
|
18
14
|
|
15
|
+
@classmethod
|
16
|
+
def warning(cls, key: Any, value: Any) -> None:
|
17
|
+
Log.warning(f"{key} = {value}", stacklevel=3)
|
18
|
+
|
19
19
|
@classmethod
|
20
20
|
def info(cls, key: Any, value: Any) -> None:
|
21
21
|
Log.info(f"{key} = {value}", stacklevel=3)
|
22
22
|
|
23
23
|
@classmethod
|
24
|
-
def
|
25
|
-
Log.
|
24
|
+
def log(cls, key: Any, value: Any) -> None:
|
25
|
+
Log.log(f"{key} = {value}", stacklevel=3)
|
26
|
+
|
27
|
+
@classmethod
|
28
|
+
def debug(cls, key: Any, value: Any) -> None:
|
29
|
+
Log.debug(f"{key} = {value}", stacklevel=3)
|
26
30
|
|
27
31
|
class Dic:
|
28
32
|
|
@@ -47,18 +51,18 @@ class Log:
|
|
47
51
|
Log.warning(f"{key} = {value}", stacklevel=3)
|
48
52
|
|
49
53
|
@staticmethod
|
50
|
-
def
|
54
|
+
def error(*args, **kwargs) -> None:
|
51
55
|
if kwargs is None:
|
52
56
|
kwargs = {}
|
53
57
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
54
|
-
Com.Log.
|
58
|
+
Com.Log.error(*args, **kwargs)
|
55
59
|
|
56
60
|
@staticmethod
|
57
|
-
def
|
61
|
+
def warning(*args, **kwargs) -> None:
|
58
62
|
if kwargs is None:
|
59
63
|
kwargs = {}
|
60
64
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
61
|
-
Com.Log.
|
65
|
+
Com.Log.warning(*args, **kwargs)
|
62
66
|
|
63
67
|
@staticmethod
|
64
68
|
def info(*args, **kwargs) -> None:
|
@@ -68,8 +72,15 @@ class Log:
|
|
68
72
|
Com.Log.info(*args, **kwargs)
|
69
73
|
|
70
74
|
@staticmethod
|
71
|
-
def
|
75
|
+
def log(*args, **kwargs) -> None:
|
72
76
|
if kwargs is None:
|
73
77
|
kwargs = {}
|
74
78
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
75
|
-
Com.Log.
|
79
|
+
Com.Log.log(*args, **kwargs)
|
80
|
+
|
81
|
+
@staticmethod
|
82
|
+
def debug(*args, **kwargs) -> None:
|
83
|
+
if kwargs is None:
|
84
|
+
kwargs = {}
|
85
|
+
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
86
|
+
Com.Log.debug(*args, **kwargs)
|
build/lib/ka_uts_com/timer.py
CHANGED
@@ -26,8 +26,12 @@ class Timer:
|
|
26
26
|
""" Timer Management
|
27
27
|
"""
|
28
28
|
@staticmethod
|
29
|
-
def sh_task_id(d_pacmod: TyDic, class_id:
|
30
|
-
"""
|
29
|
+
def sh_task_id(d_pacmod: TyDic, class_id: TyAny, parms: TnAny, sep: TyStr) -> TyStr:
|
30
|
+
"""
|
31
|
+
Show task id, which is created by the concationation of the following items:
|
32
|
+
package, module, class_name and parms if they are defined; the items package
|
33
|
+
and module are get from the package-module directory; the item class_name is
|
34
|
+
the class_id if its a string, otherwise the attribute __qualname__ is used.
|
31
35
|
"""
|
32
36
|
package = d_pacmod.get('package')
|
33
37
|
module = d_pacmod.get('module')
|
@@ -48,16 +52,16 @@ class Timer:
|
|
48
52
|
|
49
53
|
@classmethod
|
50
54
|
def start(cls, class_id: TyAny, parms: TnAny = None, sep: TyStr = ".") -> None:
|
51
|
-
"""
|
55
|
+
""" Start Timer
|
52
56
|
"""
|
53
|
-
task_id = cls.sh_task_id(Com.
|
57
|
+
task_id = cls.sh_task_id(Com.d_app_pacmod, class_id, parms, sep)
|
54
58
|
Com.d_timer[task_id] = datetime.now()
|
55
59
|
|
56
60
|
@classmethod
|
57
61
|
def end(cls, class_id: TyAny, parms: TnAny = None, sep: TyStr = ".") -> None:
|
58
|
-
"""
|
62
|
+
""" End Timer
|
59
63
|
"""
|
60
|
-
task_id = cls.sh_task_id(Com.
|
64
|
+
task_id = cls.sh_task_id(Com.d_app_pacmod, class_id, parms, sep)
|
61
65
|
start = Com.d_timer.get(task_id)
|
62
66
|
end = datetime.now()
|
63
67
|
elapse_time_sec = Timestamp.sh_elapse_time_sec(end, start)
|
@@ -29,11 +29,9 @@ class AoEqStmt:
|
|
29
29
|
def sh_d_eq(cls, a_eqstmt: TyArr, **kwargs) -> TyDic:
|
30
30
|
""" show equates dictionary
|
31
31
|
"""
|
32
|
-
root_cls = kwargs.get('root_cls')
|
33
32
|
d_parms: TnDic = kwargs.get('d_parms')
|
34
33
|
_sh_prof = kwargs.get('sh_prof')
|
35
34
|
d_eq: TyDic = cls.init_d_eq(a_eqstmt)
|
36
35
|
d_eq_new: TyDic = DoEq.verify(d_eq, d_parms)
|
37
|
-
DoEq._set_d_pacmod(d_eq_new, root_cls)
|
38
36
|
DoEq._set_sh_prof(d_eq_new, _sh_prof)
|
39
37
|
return d_eq_new
|
@@ -2,7 +2,7 @@
|
|
2
2
|
from collections.abc import Callable
|
3
3
|
from typing import Any
|
4
4
|
|
5
|
-
from ka_uts_com.utils.pacmod import PacMod
|
5
|
+
# from ka_uts_com.utils.pacmod import PacMod
|
6
6
|
from ka_uts_com.utils.str import Str
|
7
7
|
from ka_uts_com.utils.date import Date
|
8
8
|
|
@@ -55,12 +55,12 @@ class DoEq:
|
|
55
55
|
# print(f"value = {value}, type(value) = {type(value)}")
|
56
56
|
return value
|
57
57
|
|
58
|
-
@staticmethod
|
59
|
-
def _set_d_pacmod(d_eq: TyDic, root_cls) -> None:
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
# @staticmethod
|
59
|
+
# def _set_d_pacmod(d_eq: TyDic, root_cls) -> None:
|
60
|
+
# """ set current pacmod dictionary
|
61
|
+
# """
|
62
|
+
# tenant = d_eq.get('tenant')
|
63
|
+
# d_eq['d_pacmod'] = PacMod.sh_d_pacmod(root_cls, tenant)
|
64
64
|
|
65
65
|
@staticmethod
|
66
66
|
def _set_sh_prof(d_eq: TyDic, sh_prof: TyCall | Any) -> None:
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
import os
|
5
|
+
import importlib.resources as resources
|
6
|
+
|
7
|
+
TyArr = list[Any]
|
8
|
+
TyDic = dict[Any, Any]
|
9
|
+
TyPackage = str
|
10
|
+
TyPackages = list[str]
|
11
|
+
TyPath = str
|
12
|
+
|
13
|
+
|
14
|
+
class Pac:
|
15
|
+
|
16
|
+
@staticmethod
|
17
|
+
def sh_path_by_package(package: TyPackage, path: TyPath) -> Any:
|
18
|
+
""" show directory
|
19
|
+
"""
|
20
|
+
_path = str(resources.files(package).joinpath(path))
|
21
|
+
# if _path.is_file():
|
22
|
+
if _path is not None and _path != '':
|
23
|
+
if os.path.exists(_path):
|
24
|
+
return _path
|
25
|
+
return ''
|
26
|
+
|
27
|
+
@classmethod
|
28
|
+
def sh_path_by_packages(cls, packages: TyPackages, path: TyPath) -> Any:
|
29
|
+
""" show directory
|
30
|
+
"""
|
31
|
+
for _package in packages:
|
32
|
+
_path = cls.sh_path_by_package(_package, path)
|
33
|
+
if _path:
|
34
|
+
return _path
|
35
|
+
return ''
|
@@ -2,106 +2,108 @@
|
|
2
2
|
from typing import Any
|
3
3
|
|
4
4
|
from os import path as os_path
|
5
|
-
|
5
|
+
|
6
|
+
from ka_uts_com.utils.pac import Pac
|
6
7
|
|
7
8
|
TyArr = list[Any]
|
8
9
|
TyDic = dict[Any, Any]
|
9
|
-
|
10
|
+
TyPath = str
|
10
11
|
|
11
12
|
|
12
13
|
class PacMod:
|
13
14
|
""" Package Module Management
|
14
15
|
"""
|
15
16
|
@staticmethod
|
16
|
-
def sh_d_pacmod(
|
17
|
+
def sh_d_pacmod(cls) -> TyDic:
|
17
18
|
""" Show Pacmod Dictionary
|
18
19
|
"""
|
19
|
-
a_pacmod: TyArr =
|
20
|
-
package
|
21
|
-
module = a_pacmod[1]
|
22
|
-
d_pacmod: TyDic = {}
|
23
|
-
d_pacmod['tenant'] = tenant
|
24
|
-
d_pacmod['package'] = package
|
25
|
-
d_pacmod['module'] = module
|
26
|
-
return d_pacmod
|
20
|
+
a_pacmod: TyArr = cls.__module__.split(".")
|
21
|
+
return {'package': a_pacmod[0], 'module': a_pacmod[1]}
|
27
22
|
|
28
|
-
# class Cfg:
|
29
|
-
# """ Configuration Sub Class of Package Module Class
|
30
|
-
# """
|
31
23
|
@staticmethod
|
32
|
-
def
|
24
|
+
def sh_path_module_yaml(d_pacmod: TyDic) -> Any:
|
33
25
|
""" show directory
|
34
26
|
"""
|
35
27
|
package = d_pacmod['package']
|
36
28
|
module = d_pacmod['module']
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# print(f"dir = {dir}")
|
41
|
-
# print(f"package = {package}")
|
42
|
-
# print(f"module = {module}")
|
43
|
-
|
44
|
-
path: str = pkg_resources.resource_filename(directory, f"{module}.yml")
|
45
|
-
return path
|
29
|
+
path = f"{module}/data/{module}.yml"
|
30
|
+
return Pac.sh_path_by_package(package, path)
|
46
31
|
|
47
32
|
@staticmethod
|
48
|
-
def
|
49
|
-
d_pacmod: TyDic, filename: str = 'keys.yml') -> str:
|
33
|
+
def sh_path_keys(d_pacmod: TyDic) -> Any:
|
50
34
|
""" show directory
|
51
35
|
"""
|
52
36
|
package = d_pacmod['package']
|
53
|
-
|
54
|
-
|
55
|
-
return path
|
37
|
+
path = 'data/keys.yml'
|
38
|
+
return Pac.sh_path_by_package(package, path)
|
56
39
|
|
57
|
-
@staticmethod
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
40
|
+
# @staticmethod
|
41
|
+
# def sh_path_log_cfg(com) -> TyPath:
|
42
|
+
# """ show directory
|
43
|
+
# """
|
44
|
+
# package = com.d_app_pacmod['package']
|
45
|
+
# path = resources.files(package).joinpath(f"data/log.{com.log_type}.yml")
|
46
|
+
# if path.is_file():
|
47
|
+
# return path
|
48
|
+
# package = com.d_com_pacmod['package']
|
49
|
+
# path = resources.files(package).joinpath(f"data/log.{com.log_type}.yml")
|
50
|
+
# if path.is_file():
|
51
|
+
# return path
|
52
|
+
# raise ModuleNotFoundError
|
64
53
|
|
65
|
-
@
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
54
|
+
# @staticmethod
|
55
|
+
# def sh_path_cfg(d_pacmod: TyDic) -> Any:
|
56
|
+
# """ show directory
|
57
|
+
# """
|
58
|
+
# package = com.d_app_pacmod['package']
|
59
|
+
# path = 'dat/cfg.yml'
|
60
|
+
# return Pac.sh_path(package, path)
|
61
|
+
|
62
|
+
# @staticmethod
|
63
|
+
# def sh_path_type(d_pacmod: TyDic, type_: str) -> str:
|
64
|
+
# """ show Data File Path
|
65
|
+
# """
|
66
|
+
# # def sh_pacmod_type(d_pacmod: TyDic, type_: str) -> str:
|
67
|
+
# package = d_pacmod['package']
|
68
|
+
# module = d_pacmod['module']
|
69
|
+
# return f"/data/{package}/{module}/{type_}"
|
76
70
|
|
77
|
-
|
78
|
-
|
79
|
-
|
71
|
+
# @classmethod
|
72
|
+
# def sh_file_path(
|
73
|
+
# cls, d_pacmod: TyDic, type_: str, suffix: str,
|
74
|
+
# pid: Any, ts: Any, **kwargs) -> str:
|
75
|
+
# """ show type specific path
|
76
|
+
# """
|
77
|
+
# filename_ = kwargs.get('filename', type_)
|
78
|
+
# sw_run_pid_ts = kwargs.get('sw_run_pid_ts', True)
|
79
|
+
# if sw_run_pid_ts is None:
|
80
|
+
# sw_run_pid_ts = True
|
81
|
+
#
|
82
|
+
# _dir: str = cls.sh_pacmod_type(d_pacmod, type_)
|
83
|
+
# if sw_run_pid_ts:
|
84
|
+
# file_path = os_path.join(
|
85
|
+
# _dir, f"{filename_}_{pid}_{ts}.{suffix}")
|
86
|
+
# else:
|
87
|
+
# file_path = os_path.join(_dir, f"{filename_}.{suffix}")
|
88
|
+
# return file_path
|
80
89
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
90
|
+
@staticmethod
|
91
|
+
def sh_dir_type(com, type_: str) -> TyPath:
|
92
|
+
"""Show run_dir
|
93
|
+
"""
|
94
|
+
dir_dat: str = com.dir_dat
|
95
|
+
tenant: str = com.tenant
|
96
|
+
package: str = com.d_app_pacmod['package']
|
97
|
+
module: str = com.d_app_pacmod['module']
|
98
|
+
if not tenant:
|
99
|
+
return f"{dir_dat}/{tenant}/{package}/{module}/{type_}"
|
85
100
|
else:
|
86
|
-
|
87
|
-
return file_path
|
101
|
+
return f"{dir_dat}/{package}/{module}/{type_}"
|
88
102
|
|
89
103
|
@classmethod
|
90
|
-
def
|
91
|
-
cls,
|
104
|
+
def sh_path_pattern(
|
105
|
+
cls, com, filename, type_: str, suffix: str) -> TyPath:
|
92
106
|
""" show type specific path
|
93
107
|
"""
|
94
|
-
|
95
|
-
|
96
|
-
path = os_path.join(_directory, f"{filename}*.{suffix}")
|
97
|
-
return path
|
98
|
-
|
99
|
-
@staticmethod
|
100
|
-
def sh_path_cfg_log(d_pacmod: TnDic = None, filename: str = 'log.yml'):
|
101
|
-
""" show directory
|
102
|
-
"""
|
103
|
-
if d_pacmod is None:
|
104
|
-
d_pacmod = {'package': 'ka_uts_com', 'module': 'com'}
|
105
|
-
return pkg_resources.resource_filename(
|
106
|
-
f"{d_pacmod['package']}.data", filename
|
107
|
-
)
|
108
|
+
_dir: str = cls.sh_dir_type(com, type_)
|
109
|
+
return os_path.join(_dir, f"{filename}*.{suffix}")
|
Binary file
|
Binary file
|
ka_uts_com/__version__.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
__title__ = 'ka_uts_com'
|
2
2
|
__description__ = 'Communication Utilities.'
|
3
3
|
__url__ = 'https://ka-ut-com.readthedocs.io/en/latest'
|
4
|
-
__version__ = '1.0.
|
4
|
+
__version__ = '2.1.0.250408'
|
5
5
|
__build__ = 0x022200
|
6
6
|
__author__ = 'Bernd Stroehle'
|
7
7
|
__author_email__ = 'bernd.stroehle@gmail.com'
|
ka_uts_com/base/app_.py
CHANGED
@@ -22,30 +22,29 @@ class App_:
|
|
22
22
|
"""Aplication Class
|
23
23
|
"""
|
24
24
|
sw_init: TyBool = False
|
25
|
-
httpmod: TyAny = None
|
26
25
|
sw_replace_keys: TnBool = None
|
27
26
|
keys: TnArr = None
|
27
|
+
httpmod: TyAny = None
|
28
28
|
reqs: TyDic = {}
|
29
29
|
app: TyDic = {}
|
30
30
|
|
31
31
|
@classmethod
|
32
|
-
def init(cls,
|
32
|
+
def init(cls, com, **kwargs) -> None:
|
33
33
|
if cls.sw_init:
|
34
34
|
return
|
35
35
|
cls.sw_init = True
|
36
36
|
cls.httpmod = kwargs.get('httpmod')
|
37
37
|
cls.sw_replace_keys = kwargs.get('sw_replace_keys', False)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
raise
|
38
|
+
if cls.sw_replace_keys:
|
39
|
+
try:
|
40
|
+
cls.keys = Yaml_.read(PacMod.sh_path_keys(com), com.Log)
|
41
|
+
except Exception as exc:
|
42
|
+
com.Log.error(exc, exc_info=True)
|
43
|
+
raise
|
45
44
|
|
46
45
|
@classmethod
|
47
|
-
def sh(cls,
|
46
|
+
def sh(cls, com, **kwargs) -> Any:
|
48
47
|
if cls.sw_init:
|
49
48
|
return cls
|
50
|
-
cls.init(
|
49
|
+
cls.init(com, **kwargs)
|
51
50
|
return cls
|
ka_uts_com/base/cfg_.py
CHANGED
@@ -3,7 +3,6 @@ from typing import Any
|
|
3
3
|
|
4
4
|
from logging import Logger
|
5
5
|
|
6
|
-
from ka_uts_com.utils.pacmod import PacMod
|
7
6
|
from ka_uts_com.ioc.yaml_ import Yaml_
|
8
7
|
|
9
8
|
TyAny = Any
|
@@ -17,11 +16,21 @@ TyLogger = Logger
|
|
17
16
|
class Cfg_:
|
18
17
|
"""Configuration Class
|
19
18
|
"""
|
19
|
+
sw_init: TyBool = False
|
20
20
|
cfg: Any = None
|
21
21
|
|
22
22
|
@classmethod
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
cls.
|
23
|
+
def init(cls, com, **kwargs) -> None:
|
24
|
+
if cls.sw_init:
|
25
|
+
return
|
26
|
+
cls.sw_init = True
|
27
|
+
_path = com.sh_path_cfg()
|
28
|
+
if _path:
|
29
|
+
cls.cfg = Yaml_.read(_path, com.Log)
|
30
|
+
|
31
|
+
@classmethod
|
32
|
+
def sh(cls, com, **kwargs) -> Any:
|
33
|
+
if cls.sw_init:
|
34
|
+
return cls
|
35
|
+
cls.init(com, **kwargs)
|
27
36
|
return cls.cfg
|
ka_uts_com/base/log_.py
CHANGED
@@ -9,7 +9,7 @@ from logging import Logger
|
|
9
9
|
from datetime import datetime
|
10
10
|
import psutil
|
11
11
|
|
12
|
-
from ka_uts_com.
|
12
|
+
# from ka_uts_com.com import Com
|
13
13
|
from ka_uts_com.ioc.jinja2_ import Jinja2_
|
14
14
|
|
15
15
|
TyAny = Any
|
@@ -20,6 +20,7 @@ TyArr = list[Any]
|
|
20
20
|
TyBool = bool
|
21
21
|
TyDic = dict[Any, Any]
|
22
22
|
TyDir = str
|
23
|
+
TyPath = str
|
23
24
|
TyLogger = Logger
|
24
25
|
|
25
26
|
TnAny = None | Any
|
@@ -30,11 +31,6 @@ TnTimeStamp = None | TyTimeStamp
|
|
30
31
|
TnDateTime = None | TyDateTime
|
31
32
|
|
32
33
|
|
33
|
-
class LogStandard:
|
34
|
-
"""Standard Logging
|
35
|
-
"""
|
36
|
-
|
37
|
-
|
38
34
|
class Log_:
|
39
35
|
|
40
36
|
sw_init: bool = False
|
@@ -42,70 +38,90 @@ class Log_:
|
|
42
38
|
username: str = psutil.Process().username()
|
43
39
|
|
44
40
|
@classmethod
|
45
|
-
def
|
41
|
+
def sh_dir_run(cls, com) -> TyDir:
|
46
42
|
"""Show run_dir
|
47
43
|
"""
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
# print(f"sh_dir_run com.dir_dat = {com.dir_dat}")
|
45
|
+
# print(f"sh_dir_run com.cmd = {com.cmd}")
|
46
|
+
# print(f"sh_dir_run com.tenant = {com.tenant}")
|
47
|
+
# print(f"sh_dir_run com = {com}")
|
48
|
+
dir_dat: str = com.dir_dat
|
49
|
+
tenant: str = com.tenant
|
50
|
+
cmd: str = com.cmd
|
51
|
+
package: str = com.d_app_pacmod['package']
|
52
|
+
# module: str = com.d_app_pacmod['module']
|
53
|
+
if tenant is not None:
|
54
|
+
path = f"{dir_dat}/{tenant}/RUN/{package}"
|
55
|
+
else:
|
56
|
+
path = f"{dir_dat}/RUN/{package}"
|
57
|
+
if com.log_type == "usr":
|
58
|
+
path = f"{path}/{cls.username}"
|
59
|
+
if cmd is not None:
|
60
|
+
path = f"{path}/{cmd}"
|
61
|
+
# print(f"sh_dir_run path = {path}")
|
62
|
+
# print("==================================")
|
63
|
+
return path
|
55
64
|
|
56
65
|
@classmethod
|
57
|
-
def
|
66
|
+
def sh_d_log_cfg(cls, com, **kwargs) -> TyDic:
|
58
67
|
"""Read log file path with jinja2
|
59
68
|
"""
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
69
|
+
dir_run = cls.sh_dir_run(com)
|
70
|
+
if kwargs.get('sw_single_dir_run', True):
|
71
|
+
# print("---sw_single_dir_run = True --------------")
|
72
|
+
dir_run_errs = f"{dir_run}/logs"
|
73
|
+
dir_run_wrns = f"{dir_run}/logs"
|
74
|
+
dir_run_infs = f"{dir_run}/logs"
|
75
|
+
dir_run_logs = f"{dir_run}/logs"
|
76
|
+
dir_run_debs = f"{dir_run}/logs"
|
77
|
+
if kwargs.get('sw_mk_dir_run', True):
|
78
|
+
os.makedirs(dir_run_logs, exist_ok=True)
|
79
|
+
else:
|
80
|
+
# print("---sw_single_dir_run = False -------------")
|
81
|
+
dir_run_errs = f"{dir_run}/errs"
|
82
|
+
dir_run_wrns = f"{dir_run}/wrns"
|
83
|
+
dir_run_infs = f"{dir_run}/infs"
|
84
|
+
dir_run_logs = f"{dir_run}/logs"
|
85
|
+
dir_run_debs = f"{dir_run}/debs"
|
86
|
+
if kwargs.get('sw_mk_dir_run', True):
|
87
|
+
os.makedirs(dir_run_errs, exist_ok=True)
|
88
|
+
os.makedirs(dir_run_wrns, exist_ok=True)
|
89
|
+
os.makedirs(dir_run_infs, exist_ok=True)
|
90
|
+
os.makedirs(dir_run_logs, exist_ok=True)
|
91
|
+
os.makedirs(dir_run_debs, exist_ok=True)
|
92
|
+
# path_log_cfg: TyPath = PacMod.sh_path_log_cfg(com)
|
93
|
+
module = com.d_app_pacmod['module']
|
94
|
+
# print(f"sh_d_log_cfg cls.path_log_cfg = {cls.path_log_cfg}")
|
95
|
+
d_log_cfg: TyDic = Jinja2_.read(
|
96
|
+
com.path_log_cfg, com.Log,
|
97
|
+
dir_run_errs=dir_run_errs,
|
98
|
+
dir_run_wrns=dir_run_wrns,
|
99
|
+
dir_run_infs=dir_run_infs,
|
100
|
+
dir_run_logs=dir_run_logs,
|
101
|
+
dir_run_debs=dir_run_debs,
|
102
|
+
module=module,
|
80
103
|
pid=com.pid,
|
81
104
|
ts=com.ts)
|
82
|
-
#
|
105
|
+
# print(f"sh_d_log_cfg d_log_cfg = {d_log_cfg}")
|
83
106
|
sw_debug: TyBool = kwargs.get('sw_debug', False)
|
84
107
|
if sw_debug:
|
85
108
|
level = logging.DEBUG
|
86
109
|
else:
|
87
110
|
level = logging.INFO
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
logger_name = 'person'
|
92
|
-
cfg['handlers'][f"{logger_name}_debug_console"]['level'] = level
|
93
|
-
cfg['handlers'][f"{logger_name}_debug_file"]['level'] = level
|
111
|
+
logger_name = com.log_type
|
112
|
+
d_log_cfg['handlers'][f"{logger_name}_debug_console"]['level'] = level
|
113
|
+
d_log_cfg['handlers'][f"{logger_name}_debug_file"]['level'] = level
|
94
114
|
|
95
|
-
return
|
115
|
+
return d_log_cfg
|
96
116
|
|
97
117
|
@classmethod
|
98
118
|
def init(cls, com, **kwargs) -> None:
|
99
119
|
"""Set static variable log level in log configuration handlers
|
100
120
|
"""
|
101
|
-
log_type = kwargs.get('log_type', 'std')
|
102
121
|
cls.sw_init = True
|
103
|
-
|
104
|
-
logging.config.dictConfig(
|
105
|
-
|
106
|
-
cls.log = logging.getLogger('main')
|
107
|
-
else:
|
108
|
-
cls.log = logging.getLogger(log_type)
|
122
|
+
d_log_cfg = cls.sh_d_log_cfg(com, **kwargs)
|
123
|
+
logging.config.dictConfig(d_log_cfg)
|
124
|
+
cls.log = logging.getLogger(com.log_type)
|
109
125
|
|
110
126
|
@classmethod
|
111
127
|
def sh(cls, com, **kwargs) -> TyLogger:
|