ka-uts-com 1.0.0.240823__py3-none-any.whl → 2.0.0.250407__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.
Files changed (59) hide show
  1. build/lib/ka_uts_com/__version__.py +1 -1
  2. build/lib/ka_uts_com/base/app_.py +50 -0
  3. build/lib/ka_uts_com/base/cfg_.py +35 -0
  4. build/lib/ka_uts_com/base/exit_.py +37 -0
  5. build/lib/ka_uts_com/base/log_.py +131 -0
  6. build/lib/ka_uts_com/com.py +91 -192
  7. build/lib/ka_uts_com/data/log.std.yml +107 -0
  8. build/lib/ka_uts_com/data/{log.standard.yml → log.usr.yml} +47 -27
  9. build/lib/ka_uts_com/decorators/dec.py +13 -0
  10. build/lib/ka_uts_com/fnc.py +29 -24
  11. build/lib/ka_uts_com/ioc/jinja2_.py +42 -0
  12. build/lib/ka_uts_com/ioc/yaml_.py +30 -0
  13. build/lib/ka_uts_com/log.py +48 -25
  14. build/lib/ka_uts_com/timer.py +24 -27
  15. build/lib/ka_uts_com/utils/aoeqstmt.py +37 -0
  16. build/lib/ka_uts_com/{date.py → utils/date.py} +4 -4
  17. build/lib/ka_uts_com/utils/doeq.py +99 -0
  18. build/lib/ka_uts_com/utils/pacmod.py +123 -0
  19. build/lib/ka_uts_com/{str.py → utils/str.py} +36 -39
  20. ka_uts_com/__version__.py +1 -1
  21. ka_uts_com/base/app_.py +50 -0
  22. ka_uts_com/base/cfg_.py +35 -0
  23. ka_uts_com/base/exit_.py +37 -0
  24. ka_uts_com/base/log_.py +131 -0
  25. ka_uts_com/com.py +91 -192
  26. ka_uts_com/data/log.std.yml +107 -0
  27. ka_uts_com/data/{log.standard.yml → log.usr.yml} +47 -27
  28. ka_uts_com/decorators/dec.py +13 -0
  29. ka_uts_com/fnc.py +29 -24
  30. ka_uts_com/ioc/jinja2_.py +42 -0
  31. ka_uts_com/ioc/yaml_.py +30 -0
  32. ka_uts_com/log.py +48 -25
  33. ka_uts_com/timer.py +24 -27
  34. ka_uts_com/utils/aoeqstmt.py +37 -0
  35. ka_uts_com/{date.py → utils/date.py} +4 -4
  36. ka_uts_com/utils/doeq.py +99 -0
  37. ka_uts_com/utils/pacmod.py +123 -0
  38. ka_uts_com/{str.py → utils/str.py} +36 -39
  39. ka_uts_com-2.0.0.250407.dist-info/METADATA +1611 -0
  40. ka_uts_com-2.0.0.250407.dist-info/RECORD +49 -0
  41. {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-2.0.0.250407.dist-info}/WHEEL +1 -1
  42. {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-2.0.0.250407.dist-info/licenses}/LICENSE.txt +1 -2
  43. build/lib/dist/ka_uts_com-1.0.0.240823-py3-none-any.whl +0 -0
  44. build/lib/dist/ka_uts_com-1.0.0.240823.tar.gz +0 -0
  45. build/lib/ka_uts_com/aeq.py +0 -87
  46. build/lib/ka_uts_com/argv.py +0 -49
  47. build/lib/ka_uts_com/data/log.personal.yml +0 -93
  48. build/lib/ka_uts_com/ioc.py +0 -57
  49. build/lib/ka_uts_com/pacmod.py +0 -111
  50. dist/ka_uts_com-1.0.0.240823-py3-none-any.whl +0 -0
  51. dist/ka_uts_com-1.0.0.240823.tar.gz +0 -0
  52. ka_uts_com/aeq.py +0 -87
  53. ka_uts_com/argv.py +0 -49
  54. ka_uts_com/data/log.personal.yml +0 -93
  55. ka_uts_com/ioc.py +0 -57
  56. ka_uts_com/pacmod.py +0 -111
  57. ka_uts_com-1.0.0.240823.dist-info/METADATA +0 -943
  58. ka_uts_com-1.0.0.240823.dist-info/RECORD +0 -41
  59. {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-2.0.0.250407.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,123 @@
1
+ # coding=utf-8
2
+ from typing import Any
3
+
4
+ from os import path as os_path
5
+ # import pkg_resources
6
+ import importlib.resources as resources
7
+
8
+ TyArr = list[Any]
9
+ TyDic = dict[Any, Any]
10
+ TyPath = str
11
+
12
+ TnDic = None | TyDic
13
+ TnPath = None | TyPath
14
+
15
+
16
+ class PacMod:
17
+ """ Package Module Management
18
+ """
19
+ @staticmethod
20
+ def sh_d_pacmod(cls) -> TyDic:
21
+ """ Show Pacmod Dictionary
22
+ """
23
+ a_pacmod: TyArr = cls.__module__.split(".")
24
+ return {'package': a_pacmod[0], 'module': a_pacmod[1]}
25
+
26
+ @staticmethod
27
+ def sh_path_module_yaml(d_pacmod: TyDic) -> str:
28
+ """ show directory
29
+ """
30
+ # def sh_path_cfg_yaml(d_pacmod: TyDic) -> str:
31
+ package = d_pacmod['package']
32
+ module = d_pacmod['module']
33
+ filename = f"{module}.yml"
34
+ file = resources.files(f"{package}.data")
35
+ print("sh_path_module_yaml files = {files}")
36
+ path: TyPath = file.joinpath(filename)
37
+ return path
38
+
39
+ @staticmethod
40
+ def sh_path_keys(
41
+ d_pacmod: TyDic, filename: str = 'keys.yml') -> TyPath:
42
+ """ show directory
43
+ """
44
+ package = d_pacmod['package']
45
+ files = resources.files(f"{package}.data")
46
+ print("sh_path_keys files = {files}")
47
+ path: TyPath = files.joinpath(filename)
48
+ return path
49
+
50
+ # @staticmethod
51
+ # def sh_path_log_cfg(com) -> TyPath:
52
+ # """ show directory
53
+ # """
54
+ # package = com.d_app_pacmod['package']
55
+ # path = resources.files(package).joinpath(f"data/log.{com.log_type}.yml")
56
+ # if path.is_file():
57
+ # return path
58
+ # package = com.d_com_pacmod['package']
59
+ # path = resources.files(package).joinpath(f"data/log.{com.log_type}.yml")
60
+ # if path.is_file():
61
+ # return path
62
+ # raise ModuleNotFoundError
63
+
64
+ @staticmethod
65
+ def sh_path_cfg(com) -> TyPath:
66
+ """ show directory
67
+ """
68
+ filename = 'cfg.yml'
69
+ package = com.d_app_pacmod['package']
70
+ files = resources.files(f"{package}.data")
71
+ print(f"sh_path_cfg files = {files}")
72
+ path: TyPath = files.joinpath(filename)
73
+ return path
74
+
75
+ # @staticmethod
76
+ # def sh_path_type(d_pacmod: TyDic, type_: str) -> str:
77
+ # """ show Data File Path
78
+ # """
79
+ # # def sh_pacmod_type(d_pacmod: TyDic, type_: str) -> str:
80
+ # package = d_pacmod['package']
81
+ # module = d_pacmod['module']
82
+ # return f"/data/{package}/{module}/{type_}"
83
+
84
+ # @classmethod
85
+ # def sh_file_path(
86
+ # cls, d_pacmod: TyDic, type_: str, suffix: str,
87
+ # pid: Any, ts: Any, **kwargs) -> str:
88
+ # """ show type specific path
89
+ # """
90
+ # filename_ = kwargs.get('filename', type_)
91
+ # sw_run_pid_ts = kwargs.get('sw_run_pid_ts', True)
92
+ # if sw_run_pid_ts is None:
93
+ # sw_run_pid_ts = True
94
+ #
95
+ # _dir: str = cls.sh_pacmod_type(d_pacmod, type_)
96
+ # if sw_run_pid_ts:
97
+ # file_path = os_path.join(
98
+ # _dir, f"{filename_}_{pid}_{ts}.{suffix}")
99
+ # else:
100
+ # file_path = os_path.join(_dir, f"{filename_}.{suffix}")
101
+ # return file_path
102
+
103
+ @staticmethod
104
+ def sh_dir_type(com, type_: str) -> str:
105
+ """Show run_dir
106
+ """
107
+ dir_dat: str = com.dir_dat
108
+ tenant: str = com.tenant
109
+ package: str = com.d_app_pacmod['package']
110
+ module: str = com.d_app_pacmod['module']
111
+ if not tenant:
112
+ return f"{dir_dat}/{tenant}/{package}/{module}/{type_}"
113
+ else:
114
+ return f"{dir_dat}/{package}/{module}/{type_}"
115
+
116
+ @classmethod
117
+ def sh_path_pattern(
118
+ cls, com, filename, type_: str, suffix: str) -> str:
119
+ """ show type specific path
120
+ """
121
+ _dir: str = cls.sh_dir_type(com, type_)
122
+ path: TyPath = os_path.join(_dir, f"{filename}*.{suffix}")
123
+ return path
@@ -1,37 +1,36 @@
1
1
  # coding=utf-8
2
+ from typing import Any
3
+ import traceback
2
4
 
3
5
  from datetime import datetime
4
6
  import re
5
7
  import orjson
6
8
  import simplejson
7
- import traceback
8
9
 
9
- from typing import Any, List, Dict
10
+ TyArr = list[Any]
11
+ TyDic = dict[Any, Any]
12
+ TyAoA = list[TyArr]
10
13
 
11
- T_Arr = List[Any]
12
- T_Dic = Dict[Any, Any]
13
- T_AoA = List[T_Arr]
14
-
15
- TN_Int = None | int
16
- TN_Float = None | float
17
- TN_Str = None | str
18
- TN_AoA = None | T_AoA
19
- TN_Arr = None | T_Arr
20
- TN_Dic = None | T_Dic
21
- TN_Datetime = None | datetime
14
+ TnInt = None | int
15
+ TnFloat = None | float
16
+ TnStr = None | str
17
+ TnAoA = None | TyAoA
18
+ TnArr = None | TyArr
19
+ TnDic = None | TyDic
20
+ TnDatetime = None | datetime
22
21
 
23
22
 
24
23
  class Str:
25
24
  """ Manage String Class
26
25
  """
27
26
  @staticmethod
28
- def sh_date(string: str, fmt: TN_Str = None) -> TN_Datetime:
27
+ def sh_date(string: str, fmt: TnStr = None) -> TnDatetime:
29
28
  """ show string as date using the format string
30
29
  """
31
30
  try:
32
31
  if fmt is None:
33
32
  fmt = "%m/%d/%Y"
34
- _date: TN_Datetime = datetime.strptime(string, fmt)
33
+ _date: TnDatetime = datetime.strptime(string, fmt)
35
34
  return _date
36
35
  except Exception:
37
36
  print(traceback.format_exc())
@@ -69,8 +68,7 @@ class Str:
69
68
  if int(string) % 2 == 0:
70
69
  return False
71
70
  return True
72
- else:
73
- return False
71
+ return False
74
72
 
75
73
  @staticmethod
76
74
  def is_integer(string: str) -> bool:
@@ -89,7 +87,7 @@ class Str:
89
87
  return False
90
88
 
91
89
  @staticmethod
92
- def is_undefined(string: TN_Str) -> bool:
90
+ def is_undefined(string: TnStr) -> bool:
93
91
  """ check if string is undefined (None or empty)
94
92
  """
95
93
  if string is None or string == '':
@@ -97,7 +95,7 @@ class Str:
97
95
  return False
98
96
 
99
97
  @staticmethod
100
- def nvl(string: TN_Str) -> TN_Str:
98
+ def nvl(string: TnStr) -> TnStr:
101
99
  """ nvl function similar to SQL NVL function
102
100
  """
103
101
  if string is None:
@@ -111,7 +109,7 @@ class Str:
111
109
  return string.replace('\n', ' ').strip()
112
110
 
113
111
  @staticmethod
114
- def remove(string: str, a_to_remove: T_Arr) -> str:
112
+ def remove(string: str, a_to_remove: TyArr) -> str:
115
113
  """ remove all character of a list
116
114
  """
117
115
  for to_remove in a_to_remove:
@@ -122,15 +120,16 @@ class Str:
122
120
  def sh_boolean(string: str) -> bool:
123
121
  """ Show string as boolean if string is a boolean
124
122
  """
125
- if string.lower() == 'true':
126
- return True
127
- elif string.lower() == 'false':
128
- return False
129
- else:
130
- raise ValueError
123
+ match string.lower():
124
+ case 'true':
125
+ return True
126
+ case 'false':
127
+ return False
128
+ case _:
129
+ raise ValueError
131
130
 
132
131
  @staticmethod
133
- def sh_float(string: str) -> TN_Float:
132
+ def sh_float(string: str) -> TnFloat:
134
133
  """ Returns Float if string is of Type Float
135
134
  otherwise None
136
135
  """
@@ -141,7 +140,7 @@ class Str:
141
140
  return None
142
141
 
143
142
  @staticmethod
144
- def sh_int(string: str) -> TN_Int:
143
+ def sh_int(string: str) -> TnInt:
145
144
  """ Returns Int if string is of Type Int
146
145
  otherwise None
147
146
  """
@@ -151,23 +150,21 @@ class Str:
151
150
  return None
152
151
 
153
152
  @staticmethod
154
- def sh_dic(string: str, sw_decimal=False) -> TN_Dic:
153
+ def sh_dic(string: str, sw_decimal=False) -> Any:
155
154
  """ Returns Dic if string is of Type Json-String
156
155
  otherwise None
157
156
  """
158
157
  try:
159
158
  if sw_decimal:
160
- dic = simplejson.loads(string, use_decimal=True)
159
+ return simplejson.loads(string, use_decimal=True)
161
160
  else:
162
- dic = orjson.loads(string)
163
- return dic
161
+ return orjson.loads(string)
164
162
  except Exception:
165
- # print(f"string = {string}")
166
163
  print(traceback.format_exc())
167
164
  return None
168
165
 
169
166
  @staticmethod
170
- def sh_arr(string: str) -> TN_Arr:
167
+ def sh_arr(string: str) -> Any:
171
168
  """ Show valid Array string as Array
172
169
  """
173
170
  try:
@@ -177,7 +174,7 @@ class Str:
177
174
  return None
178
175
 
179
176
  @staticmethod
180
- def sh_aoa(string: str) -> TN_AoA:
177
+ def sh_aoa(string: str) -> Any:
181
178
  """ Show valid Array string as Array
182
179
  """
183
180
  try:
@@ -193,7 +190,7 @@ class Str:
193
190
  return string.split()[0]
194
191
 
195
192
  @classmethod
196
- def sh_a_int(cls, string: str, sep: str) -> T_Arr:
193
+ def sh_a_int(cls, string: str, sep: str) -> TyArr:
197
194
  """ Show first substring of string
198
195
  """
199
196
  # arr = string.split(sep)
@@ -210,7 +207,7 @@ class Str:
210
207
 
211
208
  @classmethod
212
209
  def sh_a_str(
213
- cls, string: str, sep: str, a_exclude: TN_Arr = None) -> Any:
210
+ cls, string: str, sep: str, a_exclude: TnArr = None) -> Any:
214
211
  """ Show first substring of string
215
212
  """
216
213
  # arr = string.split(sep)
@@ -238,7 +235,7 @@ class Str:
238
235
 
239
236
  @classmethod
240
237
  def sh_a_obj(
241
- cls, string: str, sep: str, a_exclude: TN_Arr = None) -> Any:
238
+ cls, string: str, sep: str, a_exclude: TnArr = None) -> Any:
242
239
  """ Show first substring of string
243
240
  """
244
241
  # arr = string.split(sep)
@@ -253,7 +250,7 @@ class Str:
253
250
  if _item not in a_exclude:
254
251
  _arr.append(_item)
255
252
 
256
- arr_new: T_Arr = []
253
+ arr_new: TyArr = []
257
254
  for item in _arr:
258
255
  if isinstance(item, str):
259
256
  _item = item.strip()
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.0.240823'
4
+ __version__ = '2.0.0.250407'
5
5
  __build__ = 0x022200
6
6
  __author__ = 'Bernd Stroehle'
7
7
  __author_email__ = 'bernd.stroehle@gmail.com'
@@ -0,0 +1,50 @@
1
+ # coding=utf-8
2
+ from typing import Any
3
+
4
+ from logging import Logger
5
+
6
+ from ka_uts_com.utils.pacmod import PacMod
7
+ from ka_uts_com.ioc.yaml_ import Yaml_
8
+
9
+ TyAny = Any
10
+ TyArr = list[Any]
11
+ TyBool = bool
12
+ TyDic = dict[Any, Any]
13
+ TyLogger = Logger
14
+
15
+ TnAny = None | Any
16
+ TnArr = None | TyArr
17
+ TnBool = None | bool
18
+ TnDic = None | TyDic
19
+
20
+
21
+ class App_:
22
+ """Aplication Class
23
+ """
24
+ sw_init: TyBool = False
25
+ sw_replace_keys: TnBool = None
26
+ keys: TnArr = None
27
+ httpmod: TyAny = None
28
+ reqs: TyDic = {}
29
+ app: TyDic = {}
30
+
31
+ @classmethod
32
+ def init(cls, com, **kwargs) -> None:
33
+ if cls.sw_init:
34
+ return
35
+ cls.sw_init = True
36
+ cls.httpmod = kwargs.get('httpmod')
37
+ cls.sw_replace_keys = kwargs.get('sw_replace_keys', False)
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
44
+
45
+ @classmethod
46
+ def sh(cls, com, **kwargs) -> Any:
47
+ if cls.sw_init:
48
+ return cls
49
+ cls.init(com, **kwargs)
50
+ return cls
@@ -0,0 +1,35 @@
1
+ # coding=utf-8
2
+ from typing import Any
3
+
4
+ from logging import Logger
5
+
6
+ from ka_uts_com.utils.pacmod import PacMod
7
+ from ka_uts_com.ioc.yaml_ import Yaml_
8
+
9
+ TyAny = Any
10
+ TyTimeStamp = int
11
+ TyArr = list[Any]
12
+ TyBool = bool
13
+ TyDic = dict[Any, Any]
14
+ TyLogger = Logger
15
+
16
+
17
+ class Cfg_:
18
+ """Configuration Class
19
+ """
20
+ sw_init: TyBool = False
21
+ cfg: Any = None
22
+
23
+ @classmethod
24
+ def init(cls, com, **kwargs) -> None:
25
+ if cls.sw_init:
26
+ return
27
+ cls.sw_init = True
28
+ cls.cfg = Yaml_.read(PacMod.sh_path_cfg(com), com.Log)
29
+
30
+ @classmethod
31
+ def sh(cls, com, **kwargs) -> Any:
32
+ if cls.sw_init:
33
+ return cls
34
+ cls.init(com, **kwargs)
35
+ return cls.cfg
@@ -0,0 +1,37 @@
1
+ # coding=utf-8
2
+ from typing import Any
3
+
4
+ TyAny = Any
5
+ TyArr = list[Any]
6
+ TyBool = bool
7
+ TyDic = dict[Any, Any]
8
+
9
+ TnAny = None | Any
10
+ TnArr = None | TyArr
11
+ TnBool = None | bool
12
+ TnDic = None | TyDic
13
+
14
+
15
+ class Exit_:
16
+ """Exit Class
17
+ """
18
+ sw_init: TyBool = False
19
+ sw_critical: bool = False
20
+ sw_stop: bool = False
21
+ sw_interactive: bool = False
22
+
23
+ @classmethod
24
+ def init(cls, **kwargs) -> None:
25
+ if cls.sw_init:
26
+ return
27
+ cls.sw_init = True
28
+ cls.sw_critical = kwargs.get('sw_critical', False)
29
+ cls.sw_stop = kwargs.get('sw_stop', False)
30
+ cls.sw_interactive = kwargs.get('sw_interactive', False)
31
+
32
+ @classmethod
33
+ def sh(cls, **kwargs) -> Any:
34
+ if cls.sw_init:
35
+ return cls
36
+ cls.init(**kwargs)
37
+ return cls
@@ -0,0 +1,131 @@
1
+ # coding=utf-8
2
+ from collections.abc import Callable
3
+ from typing import Any
4
+
5
+ import os
6
+ import logging
7
+ import logging.config
8
+ from logging import Logger
9
+ from datetime import datetime
10
+ import psutil
11
+
12
+ # from ka_uts_com.com import Com
13
+ from ka_uts_com.ioc.jinja2_ import Jinja2_
14
+
15
+ TyAny = Any
16
+ TyCallable = Callable[..., Any]
17
+ TyDateTime = datetime
18
+ TyTimeStamp = int
19
+ TyArr = list[Any]
20
+ TyBool = bool
21
+ TyDic = dict[Any, Any]
22
+ TyDir = str
23
+ TyPath = str
24
+ TyLogger = Logger
25
+
26
+ TnAny = None | Any
27
+ TnArr = None | TyArr
28
+ TnBool = None | bool
29
+ TnDic = None | TyDic
30
+ TnTimeStamp = None | TyTimeStamp
31
+ TnDateTime = None | TyDateTime
32
+
33
+
34
+ class Log_:
35
+
36
+ sw_init: bool = False
37
+ log: TyLogger = logging.getLogger('dummy_logger')
38
+ username: str = psutil.Process().username()
39
+
40
+ @classmethod
41
+ def sh_dir_run(cls, com) -> TyDir:
42
+ """Show run_dir
43
+ """
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
64
+
65
+ @classmethod
66
+ def sh_d_log_cfg(cls, com, **kwargs) -> TyDic:
67
+ """Read log file path with jinja2
68
+ """
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,
103
+ pid=com.pid,
104
+ ts=com.ts)
105
+ # print(f"sh_d_log_cfg d_log_cfg = {d_log_cfg}")
106
+ sw_debug: TyBool = kwargs.get('sw_debug', False)
107
+ if sw_debug:
108
+ level = logging.DEBUG
109
+ else:
110
+ level = logging.INFO
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
114
+
115
+ return d_log_cfg
116
+
117
+ @classmethod
118
+ def init(cls, com, **kwargs) -> None:
119
+ """Set static variable log level in log configuration handlers
120
+ """
121
+ cls.sw_init = True
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)
125
+
126
+ @classmethod
127
+ def sh(cls, com, **kwargs) -> TyLogger:
128
+ if cls.sw_init:
129
+ return cls.log
130
+ cls.init(com, **kwargs)
131
+ return cls.log