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.
Files changed (41) hide show
  1. build/lib/dist/ka_uts_com-1.0.0.240823-py3-none-any.whl +0 -0
  2. build/lib/dist/ka_uts_com-1.0.0.240823.tar.gz +0 -0
  3. build/lib/ka_uts_com/__init__.py +0 -0
  4. build/lib/ka_uts_com/__version__.py +10 -0
  5. build/lib/ka_uts_com/aeq.py +87 -0
  6. build/lib/ka_uts_com/argv.py +49 -0
  7. build/lib/ka_uts_com/com.py +222 -0
  8. build/lib/ka_uts_com/data/__init__.py +0 -0
  9. build/lib/ka_uts_com/data/log.personal.yml +93 -0
  10. build/lib/ka_uts_com/data/log.standard.yml +86 -0
  11. build/lib/ka_uts_com/date.py +15 -0
  12. build/lib/ka_uts_com/fnc.py +37 -0
  13. build/lib/ka_uts_com/ioc.py +57 -0
  14. build/lib/ka_uts_com/log.py +63 -0
  15. build/lib/ka_uts_com/pacmod.py +111 -0
  16. build/lib/ka_uts_com/py.typed +0 -0
  17. build/lib/ka_uts_com/str.py +268 -0
  18. build/lib/ka_uts_com/timer.py +72 -0
  19. dist/ka_uts_com-1.0.0.240823-py3-none-any.whl +0 -0
  20. dist/ka_uts_com-1.0.0.240823.tar.gz +0 -0
  21. ka_uts_com/__init__.py +0 -0
  22. ka_uts_com/__version__.py +10 -0
  23. ka_uts_com/aeq.py +87 -0
  24. ka_uts_com/argv.py +49 -0
  25. ka_uts_com/com.py +222 -0
  26. ka_uts_com/data/__init__.py +0 -0
  27. ka_uts_com/data/log.personal.yml +93 -0
  28. ka_uts_com/data/log.standard.yml +86 -0
  29. ka_uts_com/date.py +15 -0
  30. ka_uts_com/fnc.py +37 -0
  31. ka_uts_com/ioc.py +57 -0
  32. ka_uts_com/log.py +63 -0
  33. ka_uts_com/pacmod.py +111 -0
  34. ka_uts_com/py.typed +0 -0
  35. ka_uts_com/str.py +268 -0
  36. ka_uts_com/timer.py +72 -0
  37. ka_uts_com-1.0.0.240823.dist-info/LICENSE.txt +19 -0
  38. ka_uts_com-1.0.0.240823.dist-info/METADATA +943 -0
  39. ka_uts_com-1.0.0.240823.dist-info/RECORD +41 -0
  40. ka_uts_com-1.0.0.240823.dist-info/WHEEL +5 -0
  41. ka_uts_com-1.0.0.240823.dist-info/top_level.txt +4 -0
ka_uts_com/str.py ADDED
@@ -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
ka_uts_com/timer.py ADDED
@@ -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)
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright (c) 2022 Kosakya, GmbH. All rights reserved.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more detail.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+ # Person: Role: Email:
18
+ # Bernd Stroehle Author bernd.stroehle@gmail.com
19
+ # Maintainer