ka-uts-com 2.1.0.250408__py3-none-any.whl → 2.2.0.250427__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 (54) hide show
  1. ka_uts_com/__version__.py +2 -2
  2. build/lib/ka_uts_com/base/app_.py → ka_uts_com/app.py +9 -11
  3. ka_uts_com/{base/cfg_.py → cfg.py} +7 -10
  4. ka_uts_com/com.py +47 -39
  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.2.0.250427.dist-info/METADATA +929 -0
  8. ka_uts_com-2.2.0.250427.dist-info/RECORD +14 -0
  9. {ka_uts_com-2.1.0.250408.dist-info → ka_uts_com-2.2.0.250427.dist-info}/WHEEL +1 -1
  10. {ka_uts_com-2.1.0.250408.dist-info → ka_uts_com-2.2.0.250427.dist-info}/top_level.txt +0 -1
  11. build/lib/dist/ka_uts_com-2.0.0.250407-py3-none-any.whl +0 -0
  12. build/lib/dist/ka_uts_com-2.0.0.250407.tar.gz +0 -0
  13. build/lib/ka_uts_com/__init__.py +0 -0
  14. build/lib/ka_uts_com/__version__.py +0 -10
  15. build/lib/ka_uts_com/base/cfg_.py +0 -36
  16. build/lib/ka_uts_com/base/log_.py +0 -131
  17. build/lib/ka_uts_com/com.py +0 -115
  18. build/lib/ka_uts_com/data/__init__.py +0 -0
  19. build/lib/ka_uts_com/data/log.std.yml +0 -107
  20. build/lib/ka_uts_com/data/log.usr.yml +0 -106
  21. build/lib/ka_uts_com/decorators/dec.py +0 -13
  22. build/lib/ka_uts_com/fnc.py +0 -42
  23. build/lib/ka_uts_com/ioc/jinja2_.py +0 -42
  24. build/lib/ka_uts_com/ioc/yaml_.py +0 -31
  25. build/lib/ka_uts_com/log.py +0 -86
  26. build/lib/ka_uts_com/py.typed +0 -0
  27. build/lib/ka_uts_com/timer.py +0 -69
  28. build/lib/ka_uts_com/utils/aoeqstmt.py +0 -37
  29. build/lib/ka_uts_com/utils/date.py +0 -15
  30. build/lib/ka_uts_com/utils/doeq.py +0 -99
  31. build/lib/ka_uts_com/utils/pac.py +0 -35
  32. build/lib/ka_uts_com/utils/pacmod.py +0 -109
  33. build/lib/ka_uts_com/utils/str.py +0 -265
  34. dist/ka_uts_com-2.0.0.250407-py3-none-any.whl +0 -0
  35. dist/ka_uts_com-2.0.0.250407.tar.gz +0 -0
  36. ka_uts_com/base/app_.py +0 -50
  37. ka_uts_com/base/exit_.py +0 -37
  38. ka_uts_com/base/log_.py +0 -131
  39. ka_uts_com/data/__init__.py +0 -0
  40. ka_uts_com/data/log.std.yml +0 -107
  41. ka_uts_com/data/log.usr.yml +0 -106
  42. ka_uts_com/fnc.py +0 -42
  43. ka_uts_com/ioc/jinja2_.py +0 -42
  44. ka_uts_com/ioc/yaml_.py +0 -31
  45. ka_uts_com/log.py +0 -86
  46. ka_uts_com/utils/aoeqstmt.py +0 -37
  47. ka_uts_com/utils/date.py +0 -15
  48. ka_uts_com/utils/doeq.py +0 -99
  49. ka_uts_com/utils/pac.py +0 -35
  50. ka_uts_com/utils/pacmod.py +0 -109
  51. ka_uts_com/utils/str.py +0 -265
  52. ka_uts_com-2.1.0.250408.dist-info/METADATA +0 -1611
  53. ka_uts_com-2.1.0.250408.dist-info/RECORD +0 -55
  54. {ka_uts_com-2.1.0.250408.dist-info → ka_uts_com-2.2.0.250427.dist-info}/licenses/LICENSE.txt +0 -0
ka_uts_com/fnc.py DELETED
@@ -1,42 +0,0 @@
1
- # coding=utf-8
2
- from collections.abc import Callable
3
- from typing import Any
4
-
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
11
-
12
- TnStr = None | str
13
- TnDoC = None | TyDoC
14
- TnCallable = None | TyCallable
15
-
16
-
17
- class Fnc:
18
- """
19
- Functions
20
- """
21
- @staticmethod
22
- def identity(obj: Any) -> Any:
23
- return obj
24
-
25
- @staticmethod
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)
30
- if not key:
31
- msg = f"key: {key} is not defined"
32
- raise Exception(msg)
33
- fnc: TnCallable = doc.get(key)
34
- if not fnc:
35
- msg = f"key: {key} is not defined in function table: {doc}"
36
- raise Exception(msg)
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)
ka_uts_com/ioc/jinja2_.py DELETED
@@ -1,42 +0,0 @@
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='{path'}")
42
- raise
ka_uts_com/ioc/yaml_.py DELETED
@@ -1,31 +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='{path}'")
25
- raise
26
- except IOError:
27
- # if Com.Log is not None:
28
- # fnc_error = Com.Log.error
29
- # fnc_error(exc, exc_info=True)
30
- raise
31
- return None
ka_uts_com/log.py DELETED
@@ -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)
@@ -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
ka_uts_com/utils/date.py DELETED
@@ -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()
ka_uts_com/utils/doeq.py DELETED
@@ -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
ka_uts_com/utils/pac.py DELETED
@@ -1,35 +0,0 @@
1
- # coding=utf-8
2
- from typing import Any
3
-
4
- import os
5
- import importlib.resources as resources
6
-
7
- TyArr = list[Any]
8
- TyDic = dict[Any, Any]
9
- TyPackage = str
10
- TyPackages = list[str]
11
- TyPath = str
12
-
13
-
14
- class Pac:
15
-
16
- @staticmethod
17
- def sh_path_by_package(package: TyPackage, path: TyPath) -> Any:
18
- """ show directory
19
- """
20
- _path = str(resources.files(package).joinpath(path))
21
- # if _path.is_file():
22
- if _path is not None and _path != '':
23
- if os.path.exists(_path):
24
- return _path
25
- return ''
26
-
27
- @classmethod
28
- def sh_path_by_packages(cls, packages: TyPackages, path: TyPath) -> Any:
29
- """ show directory
30
- """
31
- for _package in packages:
32
- _path = cls.sh_path_by_package(_package, path)
33
- if _path:
34
- return _path
35
- return ''
@@ -1,109 +0,0 @@
1
- # coding=utf-8
2
- from typing import Any
3
-
4
- from os import path as os_path
5
-
6
- from ka_uts_com.utils.pac import Pac
7
-
8
- TyArr = list[Any]
9
- TyDic = dict[Any, Any]
10
- TyPath = str
11
-
12
-
13
- class PacMod:
14
- """ Package Module Management
15
- """
16
- @staticmethod
17
- def sh_d_pacmod(cls) -> TyDic:
18
- """ Show Pacmod Dictionary
19
- """
20
- a_pacmod: TyArr = cls.__module__.split(".")
21
- return {'package': a_pacmod[0], 'module': a_pacmod[1]}
22
-
23
- @staticmethod
24
- def sh_path_module_yaml(d_pacmod: TyDic) -> Any:
25
- """ show directory
26
- """
27
- package = d_pacmod['package']
28
- module = d_pacmod['module']
29
- path = f"{module}/data/{module}.yml"
30
- return Pac.sh_path_by_package(package, path)
31
-
32
- @staticmethod
33
- def sh_path_keys(d_pacmod: TyDic) -> Any:
34
- """ show directory
35
- """
36
- package = d_pacmod['package']
37
- path = 'data/keys.yml'
38
- return Pac.sh_path_by_package(package, path)
39
-
40
- # @staticmethod
41
- # def sh_path_log_cfg(com) -> TyPath:
42
- # """ show directory
43
- # """
44
- # package = com.d_app_pacmod['package']
45
- # path = resources.files(package).joinpath(f"data/log.{com.log_type}.yml")
46
- # if path.is_file():
47
- # return path
48
- # package = com.d_com_pacmod['package']
49
- # path = resources.files(package).joinpath(f"data/log.{com.log_type}.yml")
50
- # if path.is_file():
51
- # return path
52
- # raise ModuleNotFoundError
53
-
54
- # @staticmethod
55
- # def sh_path_cfg(d_pacmod: TyDic) -> Any:
56
- # """ show directory
57
- # """
58
- # package = com.d_app_pacmod['package']
59
- # path = 'dat/cfg.yml'
60
- # return Pac.sh_path(package, path)
61
-
62
- # @staticmethod
63
- # def sh_path_type(d_pacmod: TyDic, type_: str) -> str:
64
- # """ show Data File Path
65
- # """
66
- # # def sh_pacmod_type(d_pacmod: TyDic, type_: str) -> str:
67
- # package = d_pacmod['package']
68
- # module = d_pacmod['module']
69
- # return f"/data/{package}/{module}/{type_}"
70
-
71
- # @classmethod
72
- # def sh_file_path(
73
- # cls, d_pacmod: TyDic, type_: str, suffix: str,
74
- # pid: Any, ts: Any, **kwargs) -> str:
75
- # """ show type specific path
76
- # """
77
- # filename_ = kwargs.get('filename', type_)
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.sh_pacmod_type(d_pacmod, type_)
83
- # if sw_run_pid_ts:
84
- # file_path = os_path.join(
85
- # _dir, f"{filename_}_{pid}_{ts}.{suffix}")
86
- # else:
87
- # file_path = os_path.join(_dir, f"{filename_}.{suffix}")
88
- # return file_path
89
-
90
- @staticmethod
91
- def sh_dir_type(com, type_: str) -> TyPath:
92
- """Show run_dir
93
- """
94
- dir_dat: str = com.dir_dat
95
- tenant: str = com.tenant
96
- package: str = com.d_app_pacmod['package']
97
- module: str = com.d_app_pacmod['module']
98
- if not tenant:
99
- return f"{dir_dat}/{tenant}/{package}/{module}/{type_}"
100
- else:
101
- return f"{dir_dat}/{package}/{module}/{type_}"
102
-
103
- @classmethod
104
- def sh_path_pattern(
105
- cls, com, filename, type_: str, suffix: str) -> TyPath:
106
- """ show type specific path
107
- """
108
- _dir: str = cls.sh_dir_type(com, type_)
109
- return os_path.join(_dir, f"{filename}*.{suffix}")