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.
Files changed (61) hide show
  1. build/lib/dist/ka_uts_com-1.0.1.250131-py3-none-any.whl +0 -0
  2. build/lib/dist/ka_uts_com-1.0.1.250131.tar.gz +0 -0
  3. build/lib/ka_uts_com/__version__.py +1 -1
  4. build/lib/ka_uts_com/base/app_.py +51 -0
  5. build/lib/ka_uts_com/base/cfg_.py +27 -0
  6. build/lib/ka_uts_com/base/exit_.py +37 -0
  7. build/lib/ka_uts_com/base/log_.py +115 -0
  8. build/lib/ka_uts_com/com.py +42 -192
  9. build/lib/ka_uts_com/data/{log.standard.yml → log.std.yml} +3 -3
  10. build/lib/ka_uts_com/data/{log.personal.yml → log.usr.yml} +34 -42
  11. build/lib/ka_uts_com/decorators/dec.py +13 -0
  12. build/lib/ka_uts_com/fnc.py +29 -24
  13. build/lib/ka_uts_com/ioc/jinja2_.py +42 -0
  14. build/lib/ka_uts_com/ioc/yaml_.py +30 -0
  15. build/lib/ka_uts_com/log.py +32 -20
  16. build/lib/ka_uts_com/timer.py +17 -24
  17. build/lib/ka_uts_com/utils/aoeqstmt.py +39 -0
  18. build/lib/ka_uts_com/{date.py → utils/date.py} +4 -4
  19. build/lib/ka_uts_com/utils/doeq.py +99 -0
  20. {ka_uts_com → build/lib/ka_uts_com/utils}/pacmod.py +30 -34
  21. build/lib/ka_uts_com/utils/py.typed +0 -0
  22. build/lib/ka_uts_com/{str.py → utils/str.py} +36 -39
  23. dist/ka_uts_com-1.0.1.250131-py3-none-any.whl +0 -0
  24. dist/ka_uts_com-1.0.1.250131.tar.gz +0 -0
  25. ka_uts_com/__version__.py +1 -1
  26. ka_uts_com/base/app_.py +51 -0
  27. ka_uts_com/base/cfg_.py +27 -0
  28. ka_uts_com/base/exit_.py +37 -0
  29. ka_uts_com/base/log_.py +115 -0
  30. ka_uts_com/com.py +42 -192
  31. ka_uts_com/data/{log.standard.yml → log.std.yml} +3 -3
  32. ka_uts_com/data/{log.personal.yml → log.usr.yml} +34 -42
  33. ka_uts_com/decorators/dec.py +13 -0
  34. ka_uts_com/fnc.py +29 -24
  35. ka_uts_com/ioc/jinja2_.py +42 -0
  36. ka_uts_com/ioc/yaml_.py +30 -0
  37. ka_uts_com/log.py +32 -20
  38. ka_uts_com/timer.py +17 -24
  39. ka_uts_com/utils/aoeqstmt.py +39 -0
  40. ka_uts_com/{date.py → utils/date.py} +4 -4
  41. ka_uts_com/utils/doeq.py +99 -0
  42. {build/lib/ka_uts_com → ka_uts_com/utils}/pacmod.py +30 -34
  43. ka_uts_com/utils/py.typed +0 -0
  44. ka_uts_com/{str.py → utils/str.py} +36 -39
  45. ka_uts_com-1.0.1.250131.dist-info/METADATA +1628 -0
  46. ka_uts_com-1.0.1.250131.dist-info/RECORD +55 -0
  47. {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-1.0.1.250131.dist-info}/WHEEL +1 -1
  48. build/lib/dist/ka_uts_com-1.0.0.240823-py3-none-any.whl +0 -0
  49. build/lib/dist/ka_uts_com-1.0.0.240823.tar.gz +0 -0
  50. build/lib/ka_uts_com/aeq.py +0 -87
  51. build/lib/ka_uts_com/argv.py +0 -49
  52. build/lib/ka_uts_com/ioc.py +0 -57
  53. dist/ka_uts_com-1.0.0.240823-py3-none-any.whl +0 -0
  54. dist/ka_uts_com-1.0.0.240823.tar.gz +0 -0
  55. ka_uts_com/aeq.py +0 -87
  56. ka_uts_com/argv.py +0 -49
  57. ka_uts_com/ioc.py +0 -57
  58. ka_uts_com-1.0.0.240823.dist-info/METADATA +0 -943
  59. ka_uts_com-1.0.0.240823.dist-info/RECORD +0 -41
  60. {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-1.0.1.250131.dist-info/licenses}/LICENSE.txt +0 -0
  61. {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-1.0.1.250131.dist-info}/top_level.txt +0 -0
@@ -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()
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.0.240823'
4
+ __version__ = '1.0.1.250131'
5
5
  __build__ = 0x022200
6
6
  __author__ = 'Bernd Stroehle'
7
7
  __author_email__ = 'bernd.stroehle@gmail.com'
@@ -0,0 +1,51 @@
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
+ httpmod: TyAny = None
26
+ sw_replace_keys: TnBool = None
27
+ keys: TnArr = None
28
+ reqs: TyDic = {}
29
+ app: TyDic = {}
30
+
31
+ @classmethod
32
+ def init(cls, log: TyLogger, **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
+ try:
39
+ if cls.sw_replace_keys:
40
+ d_pacmod: TyDic = kwargs.get('d_pacmod', {})
41
+ cls.keys = Yaml_.read(PacMod.sh_path_keys_yaml(d_pacmod), log)
42
+ except Exception as exc:
43
+ log.error(exc, exc_info=True)
44
+ raise
45
+
46
+ @classmethod
47
+ def sh(cls, log: TyLogger, **kwargs) -> Any:
48
+ if cls.sw_init:
49
+ return cls
50
+ cls.init(log, **kwargs)
51
+ return cls
@@ -0,0 +1,27 @@
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
+ cfg: Any = None
21
+
22
+ @classmethod
23
+ def sh(cls, log: TyLogger, d_pacmod: TyDic) -> Any:
24
+ """ show configuration
25
+ """
26
+ cls.cfg = Yaml_.read(PacMod.sh_path_cfg_yaml(d_pacmod), log)
27
+ 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,115 @@
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.utils.pacmod import PacMod
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
+ TyLogger = Logger
24
+
25
+ TnAny = None | Any
26
+ TnArr = None | TyArr
27
+ TnBool = None | bool
28
+ TnDic = None | TyDic
29
+ TnTimeStamp = None | TyTimeStamp
30
+ TnDateTime = None | TyDateTime
31
+
32
+
33
+ class LogStandard:
34
+ """Standard Logging
35
+ """
36
+
37
+
38
+ class Log_:
39
+
40
+ sw_init: bool = False
41
+ log: TyLogger = logging.getLogger('dummy_logger')
42
+ username: str = psutil.Process().username()
43
+
44
+ @classmethod
45
+ def sh_run_dir(cls, com, **kwargs) -> TyDir:
46
+ """Show run_dir
47
+ """
48
+ tenant: str = com.d_pacmod['tenant']
49
+ package: str = com.d_pacmod['package']
50
+ module: str = com.d_pacmod['module']
51
+ log_type: str = kwargs.get('log_type', 'std')
52
+ if log_type == "std":
53
+ return f"/data/{tenant}/RUN/{package}/{module}"
54
+ return f"/data/{tenant}/RUN/{package}/{module}/{cls.username}"
55
+
56
+ @classmethod
57
+ def sh_cfg(cls, com, **kwargs) -> TyDic:
58
+ """Read log file path with jinja2
59
+ """
60
+ run_dir = kwargs.get('run_dir', cls.sh_run_dir(com, **kwargs))
61
+ run_dir_debug: str = kwargs.get('run_dir_debug', f"{run_dir}/debs")
62
+ run_dir_info: str = kwargs.get('run_dir_info', f"{run_dir}/logs")
63
+ run_dir_error: str = kwargs.get('run_dir_error', f"{run_dir}/errs")
64
+
65
+ if kwargs.get('sw_mklogdirs', True):
66
+ os.makedirs(run_dir_debug, exist_ok=True)
67
+ os.makedirs(run_dir_info, exist_ok=True)
68
+ os.makedirs(run_dir_error, exist_ok=True)
69
+
70
+ log_type = kwargs.get('log_type', 'std')
71
+ logcfg_file = f'log.{log_type}.yml'
72
+ logcfg_path: str = PacMod.sh_path_cfg_log(filename=logcfg_file)
73
+ cfg: TyDic = Jinja2_.read(
74
+ logcfg_path,
75
+ com.Log,
76
+ debug_dir=run_dir_debug,
77
+ info_dir=run_dir_info,
78
+ error_dir=run_dir_error,
79
+ module=com.d_pacmod['module'],
80
+ pid=com.pid,
81
+ ts=com.ts)
82
+ # ts=com.ts_start)
83
+ sw_debug: TyBool = kwargs.get('sw_debug', False)
84
+ if sw_debug:
85
+ level = logging.DEBUG
86
+ else:
87
+ level = logging.INFO
88
+ if log_type == 'std':
89
+ logger_name = 'main'
90
+ else:
91
+ logger_name = 'person'
92
+ cfg['handlers'][f"{logger_name}_debug_console"]['level'] = level
93
+ cfg['handlers'][f"{logger_name}_debug_file"]['level'] = level
94
+
95
+ return cfg
96
+
97
+ @classmethod
98
+ def init(cls, com, **kwargs) -> None:
99
+ """Set static variable log level in log configuration handlers
100
+ """
101
+ log_type = kwargs.get('log_type', 'std')
102
+ cls.sw_init = True
103
+ cfg = cls.sh_cfg(com, **kwargs)
104
+ logging.config.dictConfig(cfg)
105
+ if log_type == "std":
106
+ cls.log = logging.getLogger('main')
107
+ else:
108
+ cls.log = logging.getLogger(log_type)
109
+
110
+ @classmethod
111
+ def sh(cls, com, **kwargs) -> TyLogger:
112
+ if cls.sw_init:
113
+ return cls.log
114
+ cls.init(com, **kwargs)
115
+ return cls.log