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.
- build/lib/ka_uts_com/__version__.py +1 -1
- build/lib/ka_uts_com/base/app_.py +50 -0
- build/lib/ka_uts_com/base/cfg_.py +35 -0
- build/lib/ka_uts_com/base/exit_.py +37 -0
- build/lib/ka_uts_com/base/log_.py +131 -0
- build/lib/ka_uts_com/com.py +91 -192
- build/lib/ka_uts_com/data/log.std.yml +107 -0
- build/lib/ka_uts_com/data/{log.standard.yml → log.usr.yml} +47 -27
- build/lib/ka_uts_com/decorators/dec.py +13 -0
- build/lib/ka_uts_com/fnc.py +29 -24
- build/lib/ka_uts_com/ioc/jinja2_.py +42 -0
- build/lib/ka_uts_com/ioc/yaml_.py +30 -0
- build/lib/ka_uts_com/log.py +48 -25
- build/lib/ka_uts_com/timer.py +24 -27
- build/lib/ka_uts_com/utils/aoeqstmt.py +37 -0
- build/lib/ka_uts_com/{date.py → utils/date.py} +4 -4
- build/lib/ka_uts_com/utils/doeq.py +99 -0
- build/lib/ka_uts_com/utils/pacmod.py +123 -0
- build/lib/ka_uts_com/{str.py → utils/str.py} +36 -39
- ka_uts_com/__version__.py +1 -1
- ka_uts_com/base/app_.py +50 -0
- ka_uts_com/base/cfg_.py +35 -0
- ka_uts_com/base/exit_.py +37 -0
- ka_uts_com/base/log_.py +131 -0
- ka_uts_com/com.py +91 -192
- ka_uts_com/data/log.std.yml +107 -0
- ka_uts_com/data/{log.standard.yml → log.usr.yml} +47 -27
- ka_uts_com/decorators/dec.py +13 -0
- ka_uts_com/fnc.py +29 -24
- ka_uts_com/ioc/jinja2_.py +42 -0
- ka_uts_com/ioc/yaml_.py +30 -0
- ka_uts_com/log.py +48 -25
- ka_uts_com/timer.py +24 -27
- ka_uts_com/utils/aoeqstmt.py +37 -0
- ka_uts_com/{date.py → utils/date.py} +4 -4
- ka_uts_com/utils/doeq.py +99 -0
- ka_uts_com/utils/pacmod.py +123 -0
- ka_uts_com/{str.py → utils/str.py} +36 -39
- ka_uts_com-2.0.0.250407.dist-info/METADATA +1611 -0
- ka_uts_com-2.0.0.250407.dist-info/RECORD +49 -0
- {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-2.0.0.250407.dist-info}/WHEEL +1 -1
- {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-2.0.0.250407.dist-info/licenses}/LICENSE.txt +1 -2
- 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/aeq.py +0 -87
- build/lib/ka_uts_com/argv.py +0 -49
- build/lib/ka_uts_com/data/log.personal.yml +0 -93
- build/lib/ka_uts_com/ioc.py +0 -57
- build/lib/ka_uts_com/pacmod.py +0 -111
- 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/aeq.py +0 -87
- ka_uts_com/argv.py +0 -49
- ka_uts_com/data/log.personal.yml +0 -93
- ka_uts_com/ioc.py +0 -57
- ka_uts_com/pacmod.py +0 -111
- ka_uts_com-1.0.0.240823.dist-info/METADATA +0 -943
- ka_uts_com-1.0.0.240823.dist-info/RECORD +0 -41
- {ka_uts_com-1.0.0.240823.dist-info → ka_uts_com-2.0.0.250407.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,4 @@
|
|
1
1
|
version: 1
|
2
|
-
|
3
2
|
disable_existing_loggers: False
|
4
3
|
|
5
4
|
# root:
|
@@ -10,25 +9,27 @@ disable_existing_loggers: False
|
|
10
9
|
|
11
10
|
loggers:
|
12
11
|
|
13
|
-
#
|
14
|
-
|
12
|
+
# user logger
|
13
|
+
usr:
|
15
14
|
# level: NOTSET
|
16
15
|
level: DEBUG
|
17
16
|
handlers:
|
18
|
-
-
|
19
|
-
-
|
20
|
-
-
|
21
|
-
-
|
17
|
+
- usr_debug_console
|
18
|
+
- usr_error_file
|
19
|
+
- usr_warning_file
|
20
|
+
- usr_debug_file
|
21
|
+
- usr_info_file
|
22
|
+
- usr_log_file
|
22
23
|
|
23
24
|
handlers:
|
24
25
|
|
25
|
-
|
26
|
+
usr_debug_console:
|
26
27
|
class: 'logging.StreamHandler'
|
27
28
|
level: DEBUG
|
28
|
-
formatter:
|
29
|
+
formatter: usr_debug
|
29
30
|
stream: 'ext://sys.stderr'
|
30
31
|
|
31
|
-
#
|
32
|
+
# person_info_rotating_file_handler:
|
32
33
|
# class: 'logging.handlers.RotatingFileHandler'
|
33
34
|
# level: INFO
|
34
35
|
# formatter: info
|
@@ -38,31 +39,45 @@ handlers:
|
|
38
39
|
# backupCount: 10
|
39
40
|
# encoding: utf8
|
40
41
|
|
41
|
-
|
42
|
+
usr_error_file:
|
43
|
+
class: 'logging.FileHandler'
|
44
|
+
level: ERROR
|
45
|
+
formatter: usr_error
|
46
|
+
filename: '{{dir_run_errs}}/errs_{{pid}}_{{ts}}.log'
|
47
|
+
mode: 'a'
|
48
|
+
|
49
|
+
usr_warning_file:
|
50
|
+
class: 'logging.FileHandler'
|
51
|
+
level: ERROR
|
52
|
+
formatter: usr_warning
|
53
|
+
filename: '{{dir_run_wrns}}/wrns_{{pid}}_{{ts}}.log'
|
54
|
+
mode: 'a'
|
55
|
+
|
56
|
+
usr_debug_file:
|
42
57
|
class: 'logging.FileHandler'
|
43
58
|
level: DEBUG
|
44
|
-
formatter:
|
45
|
-
filename: '
|
59
|
+
formatter: usr_debug
|
60
|
+
filename: '{{dir_run_debs}}/debs_{{pid}}_{{ts}}.log'
|
46
61
|
mode: 'a'
|
47
62
|
|
48
|
-
|
63
|
+
usr_info_file:
|
49
64
|
class: 'logging.FileHandler'
|
50
65
|
level: INFO
|
51
|
-
formatter:
|
52
|
-
filename: '
|
66
|
+
formatter: usr_info
|
67
|
+
filename: '{{dir_run_infs}}/infs_{{pid}}_{{ts}}.log'
|
53
68
|
mode: 'a'
|
54
69
|
|
55
|
-
|
70
|
+
usr_log_file:
|
56
71
|
class: 'logging.FileHandler'
|
57
|
-
level:
|
58
|
-
formatter:
|
59
|
-
filename: '
|
72
|
+
level: INFO
|
73
|
+
formatter: usr_log
|
74
|
+
filename: '{{dir_run_logs}}/logs_{{pid}}_{{ts}}.log'
|
60
75
|
mode: 'a'
|
61
76
|
|
62
|
-
|
77
|
+
usr_critical_mail:
|
63
78
|
class: 'logging.handlers.SMTPHandler'
|
64
79
|
level: CRITICAL
|
65
|
-
formatter:
|
80
|
+
formatter: usr_critical
|
66
81
|
mailhost : localhost
|
67
82
|
fromaddr: 'monitoring@domain.com'
|
68
83
|
toaddrs:
|
@@ -73,14 +88,19 @@ handlers:
|
|
73
88
|
|
74
89
|
formatters:
|
75
90
|
|
76
|
-
|
77
|
-
format: '%(asctime)s-%(levelname)s-%(name)s::%(module)s|%(lineno)s:: %(message)s'
|
78
|
-
main_debug:
|
91
|
+
usr_errs:
|
79
92
|
format: '%(asctime)-15s %(levelname)s-%(name)s-%(process)d::%(module)s.%(funcName)s|%(lineno)s:: %(message)s'
|
80
93
|
datefmt: '%Y-%m-%d %H:%M:%S'
|
81
|
-
|
94
|
+
usr_wrns:
|
82
95
|
format: '%(asctime)-15s %(levelname)s-%(name)s-%(process)d::%(module)s.%(funcName)s|%(lineno)s:: %(message)s'
|
83
96
|
datefmt: '%Y-%m-%d %H:%M:%S'
|
84
|
-
|
97
|
+
usr_debs:
|
98
|
+
format: '%(asctime)-15s %(levelname)s-%(name)s-%(process)d::%(module)s.%(funcName)s|%(lineno)s:: %(message)s'
|
99
|
+
datefmt: '%Y-%m-%d %H:%M:%S'
|
100
|
+
usr_infs:
|
101
|
+
format: '%(asctime)s-%(levelname)s-%(name)s::%(module)s|%(lineno)s:: %(message)s'
|
102
|
+
usr_logs:
|
103
|
+
format: '%(asctime)s-%(levelname)s-%(name)s::%(module)s|%(lineno)s:: %(message)s'
|
104
|
+
usr_critical:
|
85
105
|
format: '%(asctime)-15s %(levelname)s-%(name)s-%(process)d::%(module)s.%(funcName)s|%(lineno)s:: %(message)s'
|
86
106
|
datefmt: '%Y-%m-%d %H:%M:%S'
|
build/lib/ka_uts_com/fnc.py
CHANGED
@@ -1,37 +1,42 @@
|
|
1
1
|
# coding=utf-8
|
2
|
+
from collections.abc import Callable
|
3
|
+
from typing import Any
|
2
4
|
|
3
|
-
|
5
|
+
TyArr = list[Any]
|
6
|
+
TyCallable = Callable[..., Any]
|
7
|
+
TyDic = dict[Any, Any]
|
8
|
+
TyArrDic = TyArr | TyDic
|
9
|
+
TyDoC = dict[str, TyCallable]
|
10
|
+
TyMsg = str
|
4
11
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
TN_Str = None | str
|
9
|
-
TN_Callable = None | Callable
|
12
|
+
TnStr = None | str
|
13
|
+
TnDoC = None | TyDoC
|
14
|
+
TnCallable = None | TyCallable
|
10
15
|
|
11
16
|
|
12
17
|
class Fnc:
|
13
|
-
"""
|
18
|
+
"""
|
19
|
+
Functions
|
14
20
|
"""
|
15
21
|
@staticmethod
|
16
|
-
def
|
17
|
-
|
18
|
-
msg = f"key {key} is None or empty string"
|
19
|
-
raise Exception(msg)
|
20
|
-
_fnc: TN_Callable = d_key2fnc.get(key)
|
21
|
-
if not _fnc:
|
22
|
-
msg = f"key {key} is not defined in function table {d_key2fnc}"
|
23
|
-
raise Exception(msg)
|
24
|
-
else:
|
25
|
-
return _fnc
|
22
|
+
def identity(obj: Any) -> Any:
|
23
|
+
return obj
|
26
24
|
|
27
25
|
@staticmethod
|
28
|
-
def
|
26
|
+
def sh(doc: TnDoC, key: TnStr) -> TyCallable:
|
27
|
+
if not doc:
|
28
|
+
msg = f"function table: {doc} is not defined"
|
29
|
+
raise Exception(msg)
|
29
30
|
if not key:
|
30
|
-
msg = f"key {key} is
|
31
|
+
msg = f"key: {key} is not defined"
|
31
32
|
raise Exception(msg)
|
32
|
-
|
33
|
-
if not
|
34
|
-
msg = f"key {key} is not defined in function table {
|
33
|
+
fnc: TnCallable = doc.get(key)
|
34
|
+
if not fnc:
|
35
|
+
msg = f"key: {key} is not defined in function table: {doc}"
|
35
36
|
raise Exception(msg)
|
36
|
-
|
37
|
-
|
37
|
+
return fnc
|
38
|
+
|
39
|
+
@classmethod
|
40
|
+
def ex(cls, doc: TnDoC, key: TnStr, args_kwargs: TyArrDic) -> Any:
|
41
|
+
fnc: TyCallable = cls.sh(doc, key)
|
42
|
+
return fnc(args_kwargs)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
# from collections.abc import Callable
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
import os
|
6
|
+
import yaml
|
7
|
+
import jinja2
|
8
|
+
# import logging
|
9
|
+
# import logging.config
|
10
|
+
from logging import Logger
|
11
|
+
|
12
|
+
TyAny = Any
|
13
|
+
TyDic = dict[Any, Any]
|
14
|
+
TyLogger = Logger
|
15
|
+
|
16
|
+
TnDic = None | TyDic
|
17
|
+
|
18
|
+
|
19
|
+
class Jinja2_:
|
20
|
+
|
21
|
+
""" Manage Object to Json file affilitation
|
22
|
+
"""
|
23
|
+
@staticmethod
|
24
|
+
def read_template(path: str) -> Any:
|
25
|
+
directory, file = os.path.split(path)
|
26
|
+
env = jinja2.Environment(loader=jinja2.FileSystemLoader(directory))
|
27
|
+
return env.get_template(file)
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def read(cls, path: str, log: TyLogger, **kwargs) -> Any:
|
31
|
+
try:
|
32
|
+
# read jinja template from file
|
33
|
+
template = cls.read_template(path)
|
34
|
+
# render template as yaml string
|
35
|
+
template_rendered = template.render(kwargs)
|
36
|
+
# load yaml string into object
|
37
|
+
obj: Any = yaml.safe_load(template_rendered)
|
38
|
+
return obj
|
39
|
+
except IOError as exc:
|
40
|
+
log.error(exc, exc_info=True)
|
41
|
+
# log.error(f"No such file or directory: {path}")
|
42
|
+
raise
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
import yaml
|
3
|
+
|
4
|
+
from typing import Any
|
5
|
+
TyAny = Any
|
6
|
+
TyArr = list[Any]
|
7
|
+
TyDic = dict[Any, Any]
|
8
|
+
|
9
|
+
TnAny = None | Any
|
10
|
+
|
11
|
+
|
12
|
+
class Yaml_:
|
13
|
+
""" Manage Object to Yaml file affilitation
|
14
|
+
"""
|
15
|
+
@staticmethod
|
16
|
+
def read(path: str, log) -> TnAny:
|
17
|
+
try:
|
18
|
+
with open(path) as fd:
|
19
|
+
# The Loader parameter handles the conversion from YAML
|
20
|
+
# scalar values to Python object format
|
21
|
+
obj = yaml.load(fd, Loader=yaml.SafeLoader)
|
22
|
+
return obj
|
23
|
+
except FileNotFoundError:
|
24
|
+
log.error(f"No such file or directory: {path}")
|
25
|
+
except IOError:
|
26
|
+
# if Com.Log is not None:
|
27
|
+
# fnc_error = Com.Log.error
|
28
|
+
# fnc_error(exc, exc_info=True)
|
29
|
+
raise
|
30
|
+
return None
|
build/lib/ka_uts_com/log.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
from ka_uts_com.com import Com
|
2
|
-
|
3
|
-
|
2
|
+
from typing import Any
|
3
|
+
TyDic = dict[Any, Any]
|
4
4
|
|
5
5
|
|
6
6
|
class Log:
|
@@ -8,56 +8,79 @@ class Log:
|
|
8
8
|
"""
|
9
9
|
class Eq:
|
10
10
|
|
11
|
-
@
|
12
|
-
def
|
13
|
-
"
|
14
|
-
|
15
|
-
|
11
|
+
@classmethod
|
12
|
+
def error(cls, key: Any, value: Any) -> None:
|
13
|
+
Log.error(f"{key} = {value}", stacklevel=3)
|
14
|
+
|
15
|
+
@classmethod
|
16
|
+
def warning(cls, key: Any, value: Any) -> None:
|
17
|
+
Log.warning(f"{key} = {value}", stacklevel=3)
|
18
|
+
|
19
|
+
@classmethod
|
20
|
+
def info(cls, key: Any, value: Any) -> None:
|
21
|
+
Log.info(f"{key} = {value}", stacklevel=3)
|
22
|
+
|
23
|
+
@classmethod
|
24
|
+
def log(cls, key: Any, value: Any) -> None:
|
25
|
+
Log.log(f"{key} = {value}", stacklevel=3)
|
16
26
|
|
17
27
|
@classmethod
|
18
28
|
def debug(cls, key: Any, value: Any) -> None:
|
19
|
-
Log.debug(
|
29
|
+
Log.debug(f"{key} = {value}", stacklevel=3)
|
30
|
+
|
31
|
+
class Dic:
|
20
32
|
|
21
33
|
@classmethod
|
22
|
-
def
|
23
|
-
|
34
|
+
def debug(cls, dic: TyDic) -> None:
|
35
|
+
for key, value in dic.items():
|
36
|
+
Log.debug(f"{key} = {value}", stacklevel=3)
|
24
37
|
|
25
38
|
@classmethod
|
26
|
-
def
|
27
|
-
|
39
|
+
def error(cls, dic: TyDic) -> None:
|
40
|
+
for key, value in dic.items():
|
41
|
+
Log.error(f"{key} = {value}", stacklevel=3)
|
28
42
|
|
29
43
|
@classmethod
|
30
|
-
def
|
31
|
-
|
44
|
+
def info(cls, dic: TyDic) -> None:
|
45
|
+
for key, value in dic.items():
|
46
|
+
Log.info(f"{key} = {value}", stacklevel=3)
|
47
|
+
|
48
|
+
@classmethod
|
49
|
+
def warning(cls, dic: TyDic) -> None:
|
50
|
+
for key, value in dic.items():
|
51
|
+
Log.warning(f"{key} = {value}", stacklevel=3)
|
32
52
|
|
33
53
|
@staticmethod
|
34
|
-
def
|
54
|
+
def error(*args, **kwargs) -> None:
|
35
55
|
if kwargs is None:
|
36
56
|
kwargs = {}
|
37
57
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
38
|
-
|
39
|
-
fnc_debug(*args, **kwargs)
|
58
|
+
Com.Log.error(*args, **kwargs)
|
40
59
|
|
41
60
|
@staticmethod
|
42
|
-
def
|
61
|
+
def warning(*args, **kwargs) -> None:
|
43
62
|
if kwargs is None:
|
44
63
|
kwargs = {}
|
45
64
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
46
|
-
|
47
|
-
fnc_error(*args, **kwargs)
|
65
|
+
Com.Log.warning(*args, **kwargs)
|
48
66
|
|
49
67
|
@staticmethod
|
50
68
|
def info(*args, **kwargs) -> None:
|
51
69
|
if kwargs is None:
|
52
70
|
kwargs = {}
|
53
71
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
54
|
-
|
55
|
-
fnc_info(*args, **kwargs)
|
72
|
+
Com.Log.info(*args, **kwargs)
|
56
73
|
|
57
74
|
@staticmethod
|
58
|
-
def
|
75
|
+
def log(*args, **kwargs) -> None:
|
76
|
+
if kwargs is None:
|
77
|
+
kwargs = {}
|
78
|
+
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
79
|
+
Com.Log.log(*args, **kwargs)
|
80
|
+
|
81
|
+
@staticmethod
|
82
|
+
def debug(*args, **kwargs) -> None:
|
59
83
|
if kwargs is None:
|
60
84
|
kwargs = {}
|
61
85
|
kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
|
62
|
-
|
63
|
-
fnc_warning(*args, **kwargs)
|
86
|
+
Com.Log.debug(*args, **kwargs)
|
build/lib/ka_uts_com/timer.py
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
# coding=utf-8
|
2
|
-
|
3
2
|
from datetime import datetime
|
4
3
|
|
5
4
|
from ka_uts_com.com import Com
|
6
5
|
from ka_uts_com.log import Log
|
7
6
|
|
8
|
-
from typing import Any
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
TN_Str = None | T_Str
|
7
|
+
from typing import Any
|
8
|
+
TyAny = Any
|
9
|
+
TyArr = list[Any]
|
10
|
+
TyDic = dict[Any, Any]
|
11
|
+
TyStr = str
|
12
|
+
TnAny = None | TyAny
|
13
|
+
TnStr = None | TyStr
|
16
14
|
|
17
15
|
|
18
16
|
class Timestamp:
|
19
17
|
|
20
18
|
@staticmethod
|
21
|
-
def sh_elapse_time_sec(
|
22
|
-
end: Any, start: TN_Any) -> TN_Any:
|
19
|
+
def sh_elapse_time_sec(end: Any, start: TnAny) -> TnAny:
|
23
20
|
if start is None:
|
24
21
|
return None
|
25
22
|
return end.timestamp()-start.timestamp()
|
@@ -29,12 +26,15 @@ class Timer:
|
|
29
26
|
""" Timer Management
|
30
27
|
"""
|
31
28
|
@staticmethod
|
32
|
-
def sh_task_id(
|
33
|
-
|
34
|
-
|
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.
|
35
35
|
"""
|
36
|
-
package =
|
37
|
-
module =
|
36
|
+
package = d_pacmod.get('package')
|
37
|
+
module = d_pacmod.get('module')
|
38
38
|
if isinstance(class_id, str):
|
39
39
|
class_name = class_id
|
40
40
|
else:
|
@@ -43,28 +43,25 @@ class Timer:
|
|
43
43
|
parms = ""
|
44
44
|
else:
|
45
45
|
parms = f" {parms}"
|
46
|
-
arr:
|
46
|
+
arr: TyArr = []
|
47
47
|
for item in [package, module, class_name, parms]:
|
48
48
|
if not item:
|
49
49
|
continue
|
50
50
|
arr.append(item)
|
51
|
-
return
|
51
|
+
return sep.join(arr)
|
52
52
|
|
53
53
|
@classmethod
|
54
|
-
def start(
|
55
|
-
|
56
|
-
parms: TN_Any = None, separator: T_Str = ".") -> None:
|
57
|
-
""" start Timer
|
54
|
+
def start(cls, class_id: TyAny, parms: TnAny = None, sep: TyStr = ".") -> None:
|
55
|
+
""" Start Timer
|
58
56
|
"""
|
59
|
-
task_id = cls.sh_task_id(class_id, parms,
|
57
|
+
task_id = cls.sh_task_id(Com.d_app_pacmod, class_id, parms, sep)
|
60
58
|
Com.d_timer[task_id] = datetime.now()
|
61
59
|
|
62
60
|
@classmethod
|
63
|
-
def end(cls, class_id:
|
64
|
-
|
65
|
-
""" end Timer
|
61
|
+
def end(cls, class_id: TyAny, parms: TnAny = None, sep: TyStr = ".") -> None:
|
62
|
+
""" End Timer
|
66
63
|
"""
|
67
|
-
task_id = cls.sh_task_id(class_id, parms,
|
64
|
+
task_id = cls.sh_task_id(Com.d_app_pacmod, class_id, parms, sep)
|
68
65
|
start = Com.d_timer.get(task_id)
|
69
66
|
end = datetime.now()
|
70
67
|
elapse_time_sec = Timestamp.sh_elapse_time_sec(end, start)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
from ka_uts_com.utils.doeq import DoEq
|
3
|
+
|
4
|
+
from typing import Any
|
5
|
+
TyArr = list[Any]
|
6
|
+
TyDic = dict[Any, Any]
|
7
|
+
|
8
|
+
TnArr = None | TyArr
|
9
|
+
TnDic = None | TyDic
|
10
|
+
TnStr = None | str
|
11
|
+
|
12
|
+
|
13
|
+
class AoEqStmt:
|
14
|
+
""" Dictionary of Equates
|
15
|
+
"""
|
16
|
+
@staticmethod
|
17
|
+
def init_d_eq(a_eqstmt: TyArr) -> TyDic:
|
18
|
+
d_eq = {}
|
19
|
+
for s_eq in a_eqstmt[1:]:
|
20
|
+
a_eq = s_eq.split('=')
|
21
|
+
if len(a_eq) == 1:
|
22
|
+
d_eq['cmd'] = a_eq[0]
|
23
|
+
else:
|
24
|
+
d_eq[a_eq[0]] = a_eq[1]
|
25
|
+
d_eq[a_eq[0]] = a_eq[1]
|
26
|
+
return d_eq
|
27
|
+
|
28
|
+
@classmethod
|
29
|
+
def sh_d_eq(cls, a_eqstmt: TyArr, **kwargs) -> TyDic:
|
30
|
+
""" show equates dictionary
|
31
|
+
"""
|
32
|
+
d_parms: TnDic = kwargs.get('d_parms')
|
33
|
+
_sh_prof = kwargs.get('sh_prof')
|
34
|
+
d_eq: TyDic = cls.init_d_eq(a_eqstmt)
|
35
|
+
d_eq_new: TyDic = DoEq.verify(d_eq, d_parms)
|
36
|
+
DoEq._set_sh_prof(d_eq_new, _sh_prof)
|
37
|
+
return d_eq_new
|
@@ -1,15 +1,15 @@
|
|
1
1
|
from datetime import datetime
|
2
2
|
from datetime import date
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
TyDate = date
|
5
|
+
TnDate = None | TyDate
|
6
|
+
TnStr = None | str
|
7
7
|
|
8
8
|
|
9
9
|
class Date:
|
10
10
|
|
11
11
|
@staticmethod
|
12
|
-
def sh(datestring:
|
12
|
+
def sh(datestring: TnStr, fmt: str) -> TnDate:
|
13
13
|
if not datestring:
|
14
14
|
return None
|
15
15
|
return datetime.strptime(datestring, fmt).date()
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
from collections.abc import Callable
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
# from ka_uts_com.utils.pacmod import PacMod
|
6
|
+
from ka_uts_com.utils.str import Str
|
7
|
+
from ka_uts_com.utils.date import Date
|
8
|
+
|
9
|
+
|
10
|
+
TyArr = list[Any]
|
11
|
+
TyCall = Callable[..., Any]
|
12
|
+
TyDic = dict[Any, Any]
|
13
|
+
TyStr = str
|
14
|
+
|
15
|
+
TnArr = None | TyArr
|
16
|
+
TnDic = None | TyDic
|
17
|
+
TnStr = None | TyStr
|
18
|
+
|
19
|
+
|
20
|
+
class DoEq:
|
21
|
+
""" Manage Commandline Arguments
|
22
|
+
"""
|
23
|
+
@classmethod
|
24
|
+
def sh_value(cls, key: str, value: Any, d_valid_parms: TnDic) -> Any:
|
25
|
+
|
26
|
+
# print(f"key = {key}, type(key) = {type(key)}")
|
27
|
+
# print(f"value = {value}, type(value) = {type(value)}")
|
28
|
+
if not d_valid_parms:
|
29
|
+
return value
|
30
|
+
_type: TnStr = d_valid_parms.get(key)
|
31
|
+
# print(f"_type = {_type}")
|
32
|
+
if not _type:
|
33
|
+
return value
|
34
|
+
if isinstance(_type, str):
|
35
|
+
match _type:
|
36
|
+
case 'int':
|
37
|
+
value = int(value)
|
38
|
+
case 'bool':
|
39
|
+
value = Str.sh_boolean(value)
|
40
|
+
case 'dict':
|
41
|
+
value = Str.sh_dic(value)
|
42
|
+
case 'list':
|
43
|
+
value = Str.sh_arr(value)
|
44
|
+
case '%Y-%m-%d':
|
45
|
+
value = Date.sh(value, _type)
|
46
|
+
case '_':
|
47
|
+
match _type[0]:
|
48
|
+
case '[', '{':
|
49
|
+
_obj = Str.sh_dic(_type)
|
50
|
+
if value not in _obj:
|
51
|
+
msg = (f"parameter={key} value={value} is invalid; "
|
52
|
+
f"valid values are={_obj}")
|
53
|
+
raise Exception(msg)
|
54
|
+
|
55
|
+
# print(f"value = {value}, type(value) = {type(value)}")
|
56
|
+
return value
|
57
|
+
|
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
|
+
|
65
|
+
@staticmethod
|
66
|
+
def _set_sh_prof(d_eq: TyDic, sh_prof: TyCall | Any) -> None:
|
67
|
+
""" set current pacmod dictionary
|
68
|
+
"""
|
69
|
+
if callable(sh_prof):
|
70
|
+
d_eq['sh_prof'] = sh_prof()
|
71
|
+
else:
|
72
|
+
d_eq['sh_prof'] = sh_prof
|
73
|
+
|
74
|
+
@classmethod
|
75
|
+
def verify(cls, d_eq: TyDic, d_parms: TnDic) -> TyDic:
|
76
|
+
if d_parms is None:
|
77
|
+
return d_eq
|
78
|
+
if 'cmd' in d_eq:
|
79
|
+
_d_valid_parms = d_parms
|
80
|
+
_cmd = d_eq['cmd']
|
81
|
+
_valid_commands = list(d_parms.keys())
|
82
|
+
if _cmd not in _valid_commands:
|
83
|
+
msg = (f"Wrong command: {_cmd}; "
|
84
|
+
f"valid commands are: {_valid_commands}")
|
85
|
+
raise Exception(msg)
|
86
|
+
_d_valid_parms = d_parms[_cmd]
|
87
|
+
else:
|
88
|
+
_d_valid_parms = d_parms
|
89
|
+
if _d_valid_parms is None:
|
90
|
+
return d_eq
|
91
|
+
|
92
|
+
d_eq_new = {}
|
93
|
+
for key, value in d_eq.items():
|
94
|
+
if key not in _d_valid_parms:
|
95
|
+
msg = (f"Wrong parameter: {key}; "
|
96
|
+
f"valid parameters are: {_d_valid_parms}")
|
97
|
+
raise Exception(msg)
|
98
|
+
d_eq_new[key] = cls.sh_value(key, value, _d_valid_parms)
|
99
|
+
return d_eq_new
|