ka-uts-com 2.0.0.250407__py3-none-any.whl → 2.1.1.250415__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 (48) hide show
  1. ka_uts_com/__version__.py +1 -1
  2. ka_uts_com/{base/app_.py → app.py} +8 -8
  3. ka_uts_com/{base/cfg_.py → cfg.py} +8 -7
  4. ka_uts_com/com.py +47 -47
  5. build/lib/ka_uts_com/base/exit_.py → ka_uts_com/exit.py +1 -1
  6. ka_uts_com/timer.py +1 -1
  7. ka_uts_com-2.1.1.250415.dist-info/METADATA +910 -0
  8. ka_uts_com-2.1.1.250415.dist-info/RECORD +14 -0
  9. {ka_uts_com-2.0.0.250407.dist-info → ka_uts_com-2.1.1.250415.dist-info}/top_level.txt +0 -1
  10. build/lib/ka_uts_com/__init__.py +0 -0
  11. build/lib/ka_uts_com/__version__.py +0 -10
  12. build/lib/ka_uts_com/base/app_.py +0 -50
  13. build/lib/ka_uts_com/base/cfg_.py +0 -35
  14. build/lib/ka_uts_com/base/log_.py +0 -131
  15. build/lib/ka_uts_com/com.py +0 -121
  16. build/lib/ka_uts_com/data/__init__.py +0 -0
  17. build/lib/ka_uts_com/data/log.std.yml +0 -107
  18. build/lib/ka_uts_com/data/log.usr.yml +0 -106
  19. build/lib/ka_uts_com/decorators/dec.py +0 -13
  20. build/lib/ka_uts_com/fnc.py +0 -42
  21. build/lib/ka_uts_com/ioc/jinja2_.py +0 -42
  22. build/lib/ka_uts_com/ioc/yaml_.py +0 -30
  23. build/lib/ka_uts_com/log.py +0 -86
  24. build/lib/ka_uts_com/py.typed +0 -0
  25. build/lib/ka_uts_com/timer.py +0 -69
  26. build/lib/ka_uts_com/utils/aoeqstmt.py +0 -37
  27. build/lib/ka_uts_com/utils/date.py +0 -15
  28. build/lib/ka_uts_com/utils/doeq.py +0 -99
  29. build/lib/ka_uts_com/utils/pacmod.py +0 -123
  30. build/lib/ka_uts_com/utils/str.py +0 -265
  31. ka_uts_com/base/exit_.py +0 -37
  32. ka_uts_com/base/log_.py +0 -131
  33. ka_uts_com/data/__init__.py +0 -0
  34. ka_uts_com/data/log.std.yml +0 -107
  35. ka_uts_com/data/log.usr.yml +0 -106
  36. ka_uts_com/fnc.py +0 -42
  37. ka_uts_com/ioc/jinja2_.py +0 -42
  38. ka_uts_com/ioc/yaml_.py +0 -30
  39. ka_uts_com/log.py +0 -86
  40. ka_uts_com/utils/aoeqstmt.py +0 -37
  41. ka_uts_com/utils/date.py +0 -15
  42. ka_uts_com/utils/doeq.py +0 -99
  43. ka_uts_com/utils/pacmod.py +0 -123
  44. ka_uts_com/utils/str.py +0 -265
  45. ka_uts_com-2.0.0.250407.dist-info/METADATA +0 -1611
  46. ka_uts_com-2.0.0.250407.dist-info/RECORD +0 -49
  47. {ka_uts_com-2.0.0.250407.dist-info → ka_uts_com-2.1.1.250415.dist-info}/WHEEL +0 -0
  48. {ka_uts_com-2.0.0.250407.dist-info → ka_uts_com-2.1.1.250415.dist-info}/licenses/LICENSE.txt +0 -0
@@ -1,30 +0,0 @@
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
@@ -1,86 +0,0 @@
1
- from ka_uts_com.com import Com
2
- from typing import Any
3
- TyDic = dict[Any, Any]
4
-
5
-
6
- class Log:
7
- """Logging Class
8
- """
9
- class Eq:
10
-
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)
26
-
27
- @classmethod
28
- def debug(cls, key: Any, value: Any) -> None:
29
- Log.debug(f"{key} = {value}", stacklevel=3)
30
-
31
- class Dic:
32
-
33
- @classmethod
34
- def debug(cls, dic: TyDic) -> None:
35
- for key, value in dic.items():
36
- Log.debug(f"{key} = {value}", stacklevel=3)
37
-
38
- @classmethod
39
- def error(cls, dic: TyDic) -> None:
40
- for key, value in dic.items():
41
- Log.error(f"{key} = {value}", stacklevel=3)
42
-
43
- @classmethod
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)
52
-
53
- @staticmethod
54
- def error(*args, **kwargs) -> None:
55
- if kwargs is None:
56
- kwargs = {}
57
- kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
58
- Com.Log.error(*args, **kwargs)
59
-
60
- @staticmethod
61
- def warning(*args, **kwargs) -> None:
62
- if kwargs is None:
63
- kwargs = {}
64
- kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
65
- Com.Log.warning(*args, **kwargs)
66
-
67
- @staticmethod
68
- def info(*args, **kwargs) -> None:
69
- if kwargs is None:
70
- kwargs = {}
71
- kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
72
- Com.Log.info(*args, **kwargs)
73
-
74
- @staticmethod
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:
83
- if kwargs is None:
84
- kwargs = {}
85
- kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
86
- Com.Log.debug(*args, **kwargs)
File without changes
@@ -1,69 +0,0 @@
1
- # coding=utf-8
2
- from datetime import datetime
3
-
4
- from ka_uts_com.com import Com
5
- from ka_uts_com.log import Log
6
-
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
14
-
15
-
16
- class Timestamp:
17
-
18
- @staticmethod
19
- def sh_elapse_time_sec(end: Any, start: TnAny) -> TnAny:
20
- if start is None:
21
- return None
22
- return end.timestamp()-start.timestamp()
23
-
24
-
25
- class Timer:
26
- """ Timer Management
27
- """
28
- @staticmethod
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
- """
36
- package = d_pacmod.get('package')
37
- module = d_pacmod.get('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: TyArr = []
47
- for item in [package, module, class_name, parms]:
48
- if not item:
49
- continue
50
- arr.append(item)
51
- return sep.join(arr)
52
-
53
- @classmethod
54
- def start(cls, class_id: TyAny, parms: TnAny = None, sep: TyStr = ".") -> None:
55
- """ Start Timer
56
- """
57
- task_id = cls.sh_task_id(Com.d_app_pacmod, class_id, parms, sep)
58
- Com.d_timer[task_id] = datetime.now()
59
-
60
- @classmethod
61
- def end(cls, class_id: TyAny, parms: TnAny = None, sep: TyStr = ".") -> None:
62
- """ End Timer
63
- """
64
- task_id = cls.sh_task_id(Com.d_app_pacmod, class_id, parms, sep)
65
- start = Com.d_timer.get(task_id)
66
- end = datetime.now()
67
- elapse_time_sec = Timestamp.sh_elapse_time_sec(end, start)
68
- msg = f"{task_id} elapse time [sec] = {elapse_time_sec}"
69
- Log.info(msg, stacklevel=2)
@@ -1,37 +0,0 @@
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 +0,0 @@
1
- from datetime import datetime
2
- from datetime import date
3
-
4
- TyDate = date
5
- TnDate = None | TyDate
6
- TnStr = None | str
7
-
8
-
9
- class Date:
10
-
11
- @staticmethod
12
- def sh(datestring: TnStr, fmt: str) -> TnDate:
13
- if not datestring:
14
- return None
15
- return datetime.strptime(datestring, fmt).date()
@@ -1,99 +0,0 @@
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
@@ -1,123 +0,0 @@
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