ka-uts-com 1.0.0.240823__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.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/__init__.py +0 -0
- build/lib/ka_uts_com/__version__.py +10 -0
- build/lib/ka_uts_com/aeq.py +87 -0
- build/lib/ka_uts_com/argv.py +49 -0
- build/lib/ka_uts_com/com.py +222 -0
- build/lib/ka_uts_com/data/__init__.py +0 -0
- build/lib/ka_uts_com/data/log.personal.yml +93 -0
- build/lib/ka_uts_com/data/log.standard.yml +86 -0
- build/lib/ka_uts_com/date.py +15 -0
- build/lib/ka_uts_com/fnc.py +37 -0
- build/lib/ka_uts_com/ioc.py +57 -0
- build/lib/ka_uts_com/log.py +63 -0
- build/lib/ka_uts_com/pacmod.py +111 -0
- build/lib/ka_uts_com/py.typed +0 -0
- build/lib/ka_uts_com/str.py +268 -0
- build/lib/ka_uts_com/timer.py +72 -0
- 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/__init__.py +0 -0
- ka_uts_com/__version__.py +10 -0
- ka_uts_com/aeq.py +87 -0
- ka_uts_com/argv.py +49 -0
- ka_uts_com/com.py +222 -0
- ka_uts_com/data/__init__.py +0 -0
- ka_uts_com/data/log.personal.yml +93 -0
- ka_uts_com/data/log.standard.yml +86 -0
- ka_uts_com/date.py +15 -0
- ka_uts_com/fnc.py +37 -0
- ka_uts_com/ioc.py +57 -0
- ka_uts_com/log.py +63 -0
- ka_uts_com/pacmod.py +111 -0
- ka_uts_com/py.typed +0 -0
- ka_uts_com/str.py +268 -0
- ka_uts_com/timer.py +72 -0
- ka_uts_com-1.0.0.240823.dist-info/LICENSE.txt +19 -0
- ka_uts_com-1.0.0.240823.dist-info/METADATA +943 -0
- ka_uts_com-1.0.0.240823.dist-info/RECORD +41 -0
- ka_uts_com-1.0.0.240823.dist-info/WHEEL +5 -0
- ka_uts_com-1.0.0.240823.dist-info/top_level.txt +4 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
from ka_uts_com.com import Com
|
2
|
+
|
3
|
+
from typing import Any, Callable
|
4
|
+
|
5
|
+
|
6
|
+
class Log:
|
7
|
+
"""Logging Class
|
8
|
+
"""
|
9
|
+
class Eq:
|
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
|
+
@classmethod
|
18
|
+
def debug(cls, key: Any, value: Any) -> None:
|
19
|
+
Log.debug(cls.sh(key, value), stacklevel=3)
|
20
|
+
|
21
|
+
@classmethod
|
22
|
+
def error(cls, key: Any, value: Any) -> None:
|
23
|
+
Log.error(cls.sh(key, value), stacklevel=3)
|
24
|
+
|
25
|
+
@classmethod
|
26
|
+
def info(cls, key: Any, value: Any) -> None:
|
27
|
+
Log.info(cls.sh(key, value), stacklevel=3)
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def warning(cls, key: Any, value: Any) -> None:
|
31
|
+
Log.warning(cls.sh(key, value), stacklevel=3)
|
32
|
+
|
33
|
+
@staticmethod
|
34
|
+
def debug(*args, **kwargs) -> None:
|
35
|
+
if kwargs is None:
|
36
|
+
kwargs = {}
|
37
|
+
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
38
|
+
fnc_debug: Callable = Com.Log.debug
|
39
|
+
fnc_debug(*args, **kwargs)
|
40
|
+
|
41
|
+
@staticmethod
|
42
|
+
def error(*args, **kwargs) -> None:
|
43
|
+
if kwargs is None:
|
44
|
+
kwargs = {}
|
45
|
+
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
46
|
+
fnc_error: Callable = Com.Log.error
|
47
|
+
fnc_error(*args, **kwargs)
|
48
|
+
|
49
|
+
@staticmethod
|
50
|
+
def info(*args, **kwargs) -> None:
|
51
|
+
if kwargs is None:
|
52
|
+
kwargs = {}
|
53
|
+
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
54
|
+
fnc_info: Callable = Com.Log.info
|
55
|
+
fnc_info(*args, **kwargs)
|
56
|
+
|
57
|
+
@staticmethod
|
58
|
+
def warning(*args, **kwargs) -> None:
|
59
|
+
if kwargs is None:
|
60
|
+
kwargs = {}
|
61
|
+
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
62
|
+
fnc_warning: Callable = Com.Log.warning
|
63
|
+
fnc_warning(*args, **kwargs)
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
|
3
|
+
from os import path as os_path
|
4
|
+
import pkg_resources
|
5
|
+
|
6
|
+
from typing import Any, Dict, List
|
7
|
+
|
8
|
+
T_Arr = List[Any]
|
9
|
+
T_Dic = Dict[Any, Any]
|
10
|
+
|
11
|
+
TN_Dic = None | T_Dic
|
12
|
+
|
13
|
+
|
14
|
+
class Pacmod:
|
15
|
+
""" Package Module Management
|
16
|
+
"""
|
17
|
+
def sh_d_pacmod(root_cls, tenant: Any) -> T_Dic:
|
18
|
+
""" Show Pacmod Dictionary
|
19
|
+
"""
|
20
|
+
a_pacmod: T_Arr = root_cls.__module__.split(".")
|
21
|
+
package = a_pacmod[0]
|
22
|
+
module = a_pacmod[1]
|
23
|
+
d_pacmod: T_Dic = {}
|
24
|
+
d_pacmod['tenant'] = tenant
|
25
|
+
d_pacmod['package'] = package
|
26
|
+
d_pacmod['module'] = module
|
27
|
+
return d_pacmod
|
28
|
+
|
29
|
+
# class Cfg:
|
30
|
+
# """ Configuration Sub Class of Package Module Class
|
31
|
+
# """
|
32
|
+
@staticmethod
|
33
|
+
def sh_path_cfg_yaml(pacmod: T_Dic) -> str:
|
34
|
+
""" show directory
|
35
|
+
"""
|
36
|
+
package = pacmod['package']
|
37
|
+
module = pacmod['module']
|
38
|
+
|
39
|
+
dir: str = f"{package}.data"
|
40
|
+
|
41
|
+
# print(f"dir = {dir}")
|
42
|
+
# print(f"package = {package}")
|
43
|
+
# print(f"module = {module}")
|
44
|
+
|
45
|
+
path = pkg_resources.resource_filename(dir, f"{module}.yml")
|
46
|
+
return path
|
47
|
+
|
48
|
+
@staticmethod
|
49
|
+
def sh_path_keys_yaml(
|
50
|
+
pacmod: Any, filename: str = 'keys.yml') -> str:
|
51
|
+
""" show directory
|
52
|
+
"""
|
53
|
+
package = pacmod['package']
|
54
|
+
dir = f"{package}.data"
|
55
|
+
path = pkg_resources.resource_filename(dir, filename)
|
56
|
+
return path
|
57
|
+
|
58
|
+
@staticmethod
|
59
|
+
def sh_pacmod_type(pacmod: Dict, type_: str) -> str:
|
60
|
+
""" show Data File Path
|
61
|
+
"""
|
62
|
+
package = pacmod['package']
|
63
|
+
module = pacmod['module']
|
64
|
+
return f"/data/{package}/{module}/{type_}"
|
65
|
+
|
66
|
+
@classmethod
|
67
|
+
def sh_file_path(
|
68
|
+
cls, pacmod: T_Dic, type_: str, suffix: str,
|
69
|
+
pid: Any, ts: Any, **kwargs) -> str:
|
70
|
+
""" show type specific path
|
71
|
+
"""
|
72
|
+
filename = kwargs.get('filename')
|
73
|
+
if filename is not None:
|
74
|
+
filename_ = filename
|
75
|
+
else:
|
76
|
+
filename_ = type_
|
77
|
+
|
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.Data.Dir.sh(pacmod, type)
|
83
|
+
_dir: str = cls.sh_pacmod_type(pacmod, type_)
|
84
|
+
if sw_run_pid_ts:
|
85
|
+
# pid = str(Com.pid)
|
86
|
+
# ts = str(Com.ts_start)
|
87
|
+
file_path = os_path.join(
|
88
|
+
_dir, f"{filename_}_{pid}_{ts}.{suffix}")
|
89
|
+
else:
|
90
|
+
file_path = os_path.join(_dir, f"{filename_}.{suffix}")
|
91
|
+
return file_path
|
92
|
+
|
93
|
+
@classmethod
|
94
|
+
def sh_pattern(
|
95
|
+
cls, pacmod: T_Dic, type_: str, suffix: str, **kwargs) -> str:
|
96
|
+
""" show type specific path
|
97
|
+
"""
|
98
|
+
filename = kwargs.get('filename')
|
99
|
+
_dir: str = cls.sh_pacmod_type(pacmod, type_)
|
100
|
+
path = os_path.join(_dir, f"{filename}*.{suffix}")
|
101
|
+
return path
|
102
|
+
|
103
|
+
@staticmethod
|
104
|
+
def sh_path_cfg_log(pacmod: TN_Dic = None, filename: str = 'log.yml'):
|
105
|
+
""" show directory
|
106
|
+
"""
|
107
|
+
if pacmod is None:
|
108
|
+
pacmod = {'package': 'ka_uts_com', 'module': 'com'}
|
109
|
+
return pkg_resources.resource_filename(
|
110
|
+
f"{pacmod['package']}.data", filename
|
111
|
+
)
|
File without changes
|
@@ -0,0 +1,268 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
|
3
|
+
from datetime import datetime
|
4
|
+
import re
|
5
|
+
import orjson
|
6
|
+
import simplejson
|
7
|
+
import traceback
|
8
|
+
|
9
|
+
from typing import Any, List, Dict
|
10
|
+
|
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
|
22
|
+
|
23
|
+
|
24
|
+
class Str:
|
25
|
+
""" Manage String Class
|
26
|
+
"""
|
27
|
+
@staticmethod
|
28
|
+
def sh_date(string: str, fmt: TN_Str = None) -> TN_Datetime:
|
29
|
+
""" show string as date using the format string
|
30
|
+
"""
|
31
|
+
try:
|
32
|
+
if fmt is None:
|
33
|
+
fmt = "%m/%d/%Y"
|
34
|
+
_date: TN_Datetime = datetime.strptime(string, fmt)
|
35
|
+
return _date
|
36
|
+
except Exception:
|
37
|
+
print(traceback.format_exc())
|
38
|
+
return None
|
39
|
+
|
40
|
+
@staticmethod
|
41
|
+
def lchop(string: str, prefix: str) -> str:
|
42
|
+
""" return substring of string which starts at the
|
43
|
+
end of the contained prefix
|
44
|
+
"""
|
45
|
+
if string.startswith(prefix):
|
46
|
+
return string[len(prefix):]
|
47
|
+
return string
|
48
|
+
|
49
|
+
@staticmethod
|
50
|
+
def rchop(string: str, suffix: str) -> str:
|
51
|
+
""" return substring of string which ends at the
|
52
|
+
beginning of the contained suffix
|
53
|
+
"""
|
54
|
+
if suffix and string.endswith(suffix):
|
55
|
+
return string[:-len(suffix)]
|
56
|
+
return string
|
57
|
+
|
58
|
+
@staticmethod
|
59
|
+
def strip_multiple_chars(string: str, chars: str) -> str:
|
60
|
+
""" replace multiple characters in string
|
61
|
+
"""
|
62
|
+
return string.translate(str.maketrans("", "", chars))
|
63
|
+
|
64
|
+
@staticmethod
|
65
|
+
def is_odd(string: str) -> bool:
|
66
|
+
""" check if string is odd number
|
67
|
+
"""
|
68
|
+
if string.isnumeric():
|
69
|
+
if int(string) % 2 == 0:
|
70
|
+
return False
|
71
|
+
return True
|
72
|
+
else:
|
73
|
+
return False
|
74
|
+
|
75
|
+
@staticmethod
|
76
|
+
def is_integer(string: str) -> bool:
|
77
|
+
""" check if string is integer
|
78
|
+
"""
|
79
|
+
if string[0] in ('-', '+'):
|
80
|
+
return string[1:].isdigit()
|
81
|
+
return string.isdigit()
|
82
|
+
|
83
|
+
@staticmethod
|
84
|
+
def is_boolean(string: str) -> bool:
|
85
|
+
""" check if string is boolean
|
86
|
+
"""
|
87
|
+
if string.strip().lower() in ['true', 'false']:
|
88
|
+
return True
|
89
|
+
return False
|
90
|
+
|
91
|
+
@staticmethod
|
92
|
+
def is_undefined(string: TN_Str) -> bool:
|
93
|
+
""" check if string is undefined (None or empty)
|
94
|
+
"""
|
95
|
+
if string is None or string == '':
|
96
|
+
return True
|
97
|
+
return False
|
98
|
+
|
99
|
+
@staticmethod
|
100
|
+
def nvl(string: TN_Str) -> TN_Str:
|
101
|
+
""" nvl function similar to SQL NVL function
|
102
|
+
"""
|
103
|
+
if string is None:
|
104
|
+
return ''
|
105
|
+
return string
|
106
|
+
|
107
|
+
@staticmethod
|
108
|
+
def strip_n(string: str) -> str:
|
109
|
+
""" Replace new line characters by Blanks and strip Blanks
|
110
|
+
"""
|
111
|
+
return string.replace('\n', ' ').strip()
|
112
|
+
|
113
|
+
@staticmethod
|
114
|
+
def remove(string: str, a_to_remove: T_Arr) -> str:
|
115
|
+
""" remove all character of a list
|
116
|
+
"""
|
117
|
+
for to_remove in a_to_remove:
|
118
|
+
string = string.replace(to_remove, '')
|
119
|
+
return string
|
120
|
+
|
121
|
+
@staticmethod
|
122
|
+
def sh_boolean(string: str) -> bool:
|
123
|
+
""" Show string as boolean if string is a boolean
|
124
|
+
"""
|
125
|
+
if string.lower() == 'true':
|
126
|
+
return True
|
127
|
+
elif string.lower() == 'false':
|
128
|
+
return False
|
129
|
+
else:
|
130
|
+
raise ValueError
|
131
|
+
|
132
|
+
@staticmethod
|
133
|
+
def sh_float(string: str) -> TN_Float:
|
134
|
+
""" Returns Float if string is of Type Float
|
135
|
+
otherwise None
|
136
|
+
"""
|
137
|
+
try:
|
138
|
+
return float(string)
|
139
|
+
except Exception:
|
140
|
+
print(traceback.format_exc())
|
141
|
+
return None
|
142
|
+
|
143
|
+
@staticmethod
|
144
|
+
def sh_int(string: str) -> TN_Int:
|
145
|
+
""" Returns Int if string is of Type Int
|
146
|
+
otherwise None
|
147
|
+
"""
|
148
|
+
try:
|
149
|
+
return int(string)
|
150
|
+
except ValueError:
|
151
|
+
return None
|
152
|
+
|
153
|
+
@staticmethod
|
154
|
+
def sh_dic(string: str, sw_decimal=False) -> TN_Dic:
|
155
|
+
""" Returns Dic if string is of Type Json-String
|
156
|
+
otherwise None
|
157
|
+
"""
|
158
|
+
try:
|
159
|
+
if sw_decimal:
|
160
|
+
dic = simplejson.loads(string, use_decimal=True)
|
161
|
+
else:
|
162
|
+
dic = orjson.loads(string)
|
163
|
+
return dic
|
164
|
+
except Exception:
|
165
|
+
# print(f"string = {string}")
|
166
|
+
print(traceback.format_exc())
|
167
|
+
return None
|
168
|
+
|
169
|
+
@staticmethod
|
170
|
+
def sh_arr(string: str) -> TN_Arr:
|
171
|
+
""" Show valid Array string as Array
|
172
|
+
"""
|
173
|
+
try:
|
174
|
+
return orjson.loads(string)
|
175
|
+
except Exception:
|
176
|
+
print(traceback.format_exc())
|
177
|
+
return None
|
178
|
+
|
179
|
+
@staticmethod
|
180
|
+
def sh_aoa(string: str) -> TN_AoA:
|
181
|
+
""" Show valid Array string as Array
|
182
|
+
"""
|
183
|
+
try:
|
184
|
+
return orjson.loads(string)
|
185
|
+
except Exception:
|
186
|
+
print(traceback.format_exc())
|
187
|
+
return None
|
188
|
+
|
189
|
+
@staticmethod
|
190
|
+
def sh_first_item(string: str) -> Any:
|
191
|
+
""" Show first substring of string
|
192
|
+
"""
|
193
|
+
return string.split()[0]
|
194
|
+
|
195
|
+
@classmethod
|
196
|
+
def sh_a_int(cls, string: str, sep: str) -> T_Arr:
|
197
|
+
""" Show first substring of string
|
198
|
+
"""
|
199
|
+
# arr = string.split(sep)
|
200
|
+
arr = re.split(sep, string)
|
201
|
+
arr_new = []
|
202
|
+
for item in arr:
|
203
|
+
_item = item.strip()
|
204
|
+
if not isinstance(_item, str):
|
205
|
+
continue
|
206
|
+
if not _item.isdigit():
|
207
|
+
continue
|
208
|
+
arr_new.append(cls.sh_int(_item))
|
209
|
+
return arr_new
|
210
|
+
|
211
|
+
@classmethod
|
212
|
+
def sh_a_str(
|
213
|
+
cls, string: str, sep: str, a_exclude: TN_Arr = None) -> Any:
|
214
|
+
""" Show first substring of string
|
215
|
+
"""
|
216
|
+
# arr = string.split(sep)
|
217
|
+
arr = re.split(sep, string)
|
218
|
+
|
219
|
+
if a_exclude is None:
|
220
|
+
_arr = arr
|
221
|
+
else:
|
222
|
+
_arr = []
|
223
|
+
for item in arr:
|
224
|
+
_item = item.strip()
|
225
|
+
if _item not in a_exclude:
|
226
|
+
_arr.append(_item)
|
227
|
+
|
228
|
+
arr_new = []
|
229
|
+
for item in _arr:
|
230
|
+
if isinstance(item, str):
|
231
|
+
arr_new.append(item.strip())
|
232
|
+
elif isinstance(item, int):
|
233
|
+
arr_new.append(str(item))
|
234
|
+
else:
|
235
|
+
arr_new.append(item)
|
236
|
+
|
237
|
+
return arr_new
|
238
|
+
|
239
|
+
@classmethod
|
240
|
+
def sh_a_obj(
|
241
|
+
cls, string: str, sep: str, a_exclude: TN_Arr = None) -> Any:
|
242
|
+
""" Show first substring of string
|
243
|
+
"""
|
244
|
+
# arr = string.split(sep)
|
245
|
+
arr = re.split(sep, string)
|
246
|
+
|
247
|
+
if a_exclude is None:
|
248
|
+
_arr = arr
|
249
|
+
else:
|
250
|
+
_arr = []
|
251
|
+
for item in arr:
|
252
|
+
_item = item.strip()
|
253
|
+
if _item not in a_exclude:
|
254
|
+
_arr.append(_item)
|
255
|
+
|
256
|
+
arr_new: T_Arr = []
|
257
|
+
for item in _arr:
|
258
|
+
if isinstance(item, str):
|
259
|
+
_item = item.strip()
|
260
|
+
if _item.isdigit():
|
261
|
+
_item = cls.sh_int(_item)
|
262
|
+
arr_new.append(_item)
|
263
|
+
else:
|
264
|
+
arr_new.append(_item)
|
265
|
+
else:
|
266
|
+
arr_new.append(item)
|
267
|
+
|
268
|
+
return arr_new
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
|
3
|
+
from datetime import datetime
|
4
|
+
|
5
|
+
from ka_uts_com.com import Com
|
6
|
+
from ka_uts_com.log import Log
|
7
|
+
|
8
|
+
from typing import Any, List
|
9
|
+
|
10
|
+
T_Any = Any
|
11
|
+
T_Arr = List[Any]
|
12
|
+
T_Str = str
|
13
|
+
|
14
|
+
TN_Any = None | T_Any
|
15
|
+
TN_Str = None | T_Str
|
16
|
+
|
17
|
+
|
18
|
+
class Timestamp:
|
19
|
+
|
20
|
+
@staticmethod
|
21
|
+
def sh_elapse_time_sec(
|
22
|
+
end: Any, start: TN_Any) -> TN_Any:
|
23
|
+
if start is None:
|
24
|
+
return None
|
25
|
+
return end.timestamp()-start.timestamp()
|
26
|
+
|
27
|
+
|
28
|
+
class Timer:
|
29
|
+
""" Timer Management
|
30
|
+
"""
|
31
|
+
@staticmethod
|
32
|
+
def sh_task_id(
|
33
|
+
class_id: Any, parms: TN_Any, separator: T_Str) -> T_Str:
|
34
|
+
""" start Timer
|
35
|
+
"""
|
36
|
+
package = Com.pacmod_curr['package']
|
37
|
+
module = Com.pacmod_curr['module']
|
38
|
+
if isinstance(class_id, str):
|
39
|
+
class_name = class_id
|
40
|
+
else:
|
41
|
+
class_name = class_id.__qualname__
|
42
|
+
if not parms:
|
43
|
+
parms = ""
|
44
|
+
else:
|
45
|
+
parms = f" {parms}"
|
46
|
+
arr: T_Arr = []
|
47
|
+
for item in [package, module, class_name, parms]:
|
48
|
+
if not item:
|
49
|
+
continue
|
50
|
+
arr.append(item)
|
51
|
+
return separator.join(arr)
|
52
|
+
|
53
|
+
@classmethod
|
54
|
+
def start(
|
55
|
+
cls, class_id: T_Any,
|
56
|
+
parms: TN_Any = None, separator: T_Str = ".") -> None:
|
57
|
+
""" start Timer
|
58
|
+
"""
|
59
|
+
task_id = cls.sh_task_id(class_id, parms, separator)
|
60
|
+
Com.d_timer[task_id] = datetime.now()
|
61
|
+
|
62
|
+
@classmethod
|
63
|
+
def end(cls, class_id: T_Any,
|
64
|
+
parms: TN_Any = None, separator: T_Str = ".") -> None:
|
65
|
+
""" end Timer
|
66
|
+
"""
|
67
|
+
task_id = cls.sh_task_id(class_id, parms, separator)
|
68
|
+
start = Com.d_timer.get(task_id)
|
69
|
+
end = datetime.now()
|
70
|
+
elapse_time_sec = Timestamp.sh_elapse_time_sec(end, start)
|
71
|
+
msg = f"{task_id} elapse time [sec] = {elapse_time_sec}"
|
72
|
+
Log.info(msg, stacklevel=2)
|
Binary file
|
Binary file
|
ka_uts_com/__init__.py
ADDED
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
__title__ = 'ka_uts_com'
|
2
|
+
__description__ = 'Communication Utilities.'
|
3
|
+
__url__ = 'https://ka-ut-com.readthedocs.io/en/latest'
|
4
|
+
__version__ = '1.0.0.240823'
|
5
|
+
__build__ = 0x022200
|
6
|
+
__author__ = 'Bernd Stroehle'
|
7
|
+
__author_email__ = 'bernd.stroehle@gmail.com'
|
8
|
+
__license__ = 'Apache-2.0'
|
9
|
+
__copyright__ = 'Copyright 2024 Bernd Stroehle'
|
10
|
+
__cake__ = u'\u2728 \U0001f370 \u2728'
|
ka_uts_com/aeq.py
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
|
3
|
+
# import orjson
|
4
|
+
# import traceback
|
5
|
+
|
6
|
+
from ka_uts_com.date import Date
|
7
|
+
from ka_uts_com.str import Str
|
8
|
+
|
9
|
+
from typing import Any, Dict, List
|
10
|
+
|
11
|
+
TN_Date = None | Any
|
12
|
+
|
13
|
+
T_Arr = List[Any]
|
14
|
+
T_Dic = Dict[Any, Any]
|
15
|
+
|
16
|
+
TN_Arr = None | T_Arr
|
17
|
+
TN_Dic = None | T_Dic
|
18
|
+
TN_Str = None | str
|
19
|
+
|
20
|
+
|
21
|
+
class Aeq:
|
22
|
+
""" Dictionary of Equates
|
23
|
+
"""
|
24
|
+
@classmethod
|
25
|
+
def sh_value(cls, key: str, value: Any, d_valid_parms: TN_Dic) -> Any:
|
26
|
+
|
27
|
+
# print(f"key = {key}, type(key) = {type(key)}")
|
28
|
+
# print(f"value = {value}, type(value) = {type(value)}")
|
29
|
+
if not d_valid_parms:
|
30
|
+
return value
|
31
|
+
_type: TN_Str = d_valid_parms.get(key)
|
32
|
+
# print(f"_type = {_type}")
|
33
|
+
if not _type:
|
34
|
+
return value
|
35
|
+
if isinstance(_type, str):
|
36
|
+
match _type:
|
37
|
+
case 'int':
|
38
|
+
value = int(value)
|
39
|
+
case 'bool':
|
40
|
+
value = Str.sh_boolean(value)
|
41
|
+
case 'dict':
|
42
|
+
value = Str.sh_dic(value)
|
43
|
+
case 'list':
|
44
|
+
value = Str.sh_arr(value)
|
45
|
+
case '%Y-%m-%d':
|
46
|
+
value = Date.sh(value, _type)
|
47
|
+
case '_':
|
48
|
+
match _type[0]:
|
49
|
+
case '[', '{':
|
50
|
+
_obj = Str.sh_dic(_type)
|
51
|
+
if value not in _obj:
|
52
|
+
msg = (f"parameter={key} value={value} is invalid; "
|
53
|
+
f"valid values are={_obj}")
|
54
|
+
raise Exception(msg)
|
55
|
+
|
56
|
+
# print(f"value = {value}, type(value) = {type(value)}")
|
57
|
+
return value
|
58
|
+
|
59
|
+
@classmethod
|
60
|
+
def sh_d_eq(cls, a_s_eq: T_Arr, d_valid_parms: TN_Dic) -> T_Dic:
|
61
|
+
|
62
|
+
d_eq = {}
|
63
|
+
_d_valid_parms = d_valid_parms
|
64
|
+
for s_eq in a_s_eq[1:]:
|
65
|
+
a_eq = s_eq.split('=')
|
66
|
+
if len(a_eq) == 1:
|
67
|
+
key = 'cmd'
|
68
|
+
value = a_eq[0]
|
69
|
+
if _d_valid_parms is not None:
|
70
|
+
if value in _d_valid_parms:
|
71
|
+
_d_valid_parms = _d_valid_parms[value]
|
72
|
+
else:
|
73
|
+
_valid_commands = list(_d_valid_parms.keys())
|
74
|
+
msg = (f"Wrong command: {value}; "
|
75
|
+
f"valid commands are: {_valid_commands}")
|
76
|
+
else:
|
77
|
+
key = a_eq[0]
|
78
|
+
value = a_eq[1]
|
79
|
+
|
80
|
+
if _d_valid_parms is not None:
|
81
|
+
if key not in _d_valid_parms:
|
82
|
+
msg = (f"Wrong parameter: {key}; "
|
83
|
+
f"valid parameters are: {_d_valid_parms}")
|
84
|
+
raise Exception(msg)
|
85
|
+
value = cls.sh_value(key, value, _d_valid_parms)
|
86
|
+
d_eq[key] = value
|
87
|
+
return d_eq
|
ka_uts_com/argv.py
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
|
3
|
+
from ka_uts_com.pacmod import Pacmod
|
4
|
+
from ka_uts_com.aeq import Aeq
|
5
|
+
|
6
|
+
from typing import Any, Callable, Dict, List
|
7
|
+
|
8
|
+
T_Arr = List[Any]
|
9
|
+
T_Dic = Dict[Any, Any]
|
10
|
+
|
11
|
+
TN_Arr = None | T_Arr
|
12
|
+
TN_Dic = None | T_Dic
|
13
|
+
|
14
|
+
|
15
|
+
class Argv:
|
16
|
+
""" Manage Commandline Arguments
|
17
|
+
"""
|
18
|
+
@staticmethod
|
19
|
+
def set_by_pacmod(d_eq: T_Dic, root_cls) -> None:
|
20
|
+
""" set current pacmod dictionary
|
21
|
+
"""
|
22
|
+
tenant = d_eq.get('tenant')
|
23
|
+
d_eq['pacmod_curr'] = Pacmod.sh_d_pacmod(root_cls, tenant)
|
24
|
+
|
25
|
+
@staticmethod
|
26
|
+
def set_by_prof(d_eq: T_Dic, sh_prof: Callable | Any) -> None:
|
27
|
+
""" set current pacmod dictionary
|
28
|
+
"""
|
29
|
+
if callable(sh_prof):
|
30
|
+
d_eq['sh_prof'] = sh_prof()
|
31
|
+
else:
|
32
|
+
d_eq['sh_prof'] = sh_prof
|
33
|
+
|
34
|
+
@classmethod
|
35
|
+
def sh(cls, a_s_eq: T_Arr, **kwargs) -> T_Dic:
|
36
|
+
""" show equates dictionary
|
37
|
+
"""
|
38
|
+
# print(f"DoEq sh kwargs = {kwargs}")
|
39
|
+
root_cls = kwargs.get('root_cls')
|
40
|
+
d_valid_parms: TN_Dic = kwargs.get('d_parms')
|
41
|
+
# print(f"DoEq sh d_valid_parms = {d_valid_parms}")
|
42
|
+
|
43
|
+
d_eq = Aeq.sh_d_eq(a_s_eq, d_valid_parms)
|
44
|
+
|
45
|
+
cls.set_by_pacmod(d_eq, root_cls)
|
46
|
+
_sh_prof = kwargs.get('sh_prof')
|
47
|
+
cls.set_by_prof(d_eq, _sh_prof)
|
48
|
+
|
49
|
+
return d_eq
|