ka-uts-com 1.0.1.250131__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.
Files changed (36) hide show
  1. build/lib/ka_uts_com/__version__.py +1 -1
  2. build/lib/ka_uts_com/base/app_.py +10 -11
  3. build/lib/ka_uts_com/base/cfg_.py +12 -4
  4. build/lib/ka_uts_com/base/log_.py +66 -50
  5. build/lib/ka_uts_com/com.py +60 -11
  6. build/lib/ka_uts_com/data/log.std.yml +47 -26
  7. build/lib/ka_uts_com/data/log.usr.yml +46 -25
  8. build/lib/ka_uts_com/log.py +23 -12
  9. build/lib/ka_uts_com/timer.py +10 -6
  10. build/lib/ka_uts_com/utils/aoeqstmt.py +0 -2
  11. build/lib/ka_uts_com/utils/doeq.py +7 -7
  12. build/lib/ka_uts_com/utils/pacmod.py +82 -66
  13. ka_uts_com/__version__.py +1 -1
  14. ka_uts_com/base/app_.py +10 -11
  15. ka_uts_com/base/cfg_.py +12 -4
  16. ka_uts_com/base/log_.py +66 -50
  17. ka_uts_com/com.py +60 -11
  18. ka_uts_com/data/log.std.yml +47 -26
  19. ka_uts_com/data/log.usr.yml +46 -25
  20. ka_uts_com/log.py +23 -12
  21. ka_uts_com/timer.py +10 -6
  22. ka_uts_com/utils/aoeqstmt.py +0 -2
  23. ka_uts_com/utils/doeq.py +7 -7
  24. ka_uts_com/utils/pacmod.py +82 -66
  25. {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.0.0.250407.dist-info}/METADATA +389 -406
  26. ka_uts_com-2.0.0.250407.dist-info/RECORD +49 -0
  27. {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.0.0.250407.dist-info}/licenses/LICENSE.txt +1 -2
  28. build/lib/dist/ka_uts_com-1.0.1.250131-py3-none-any.whl +0 -0
  29. build/lib/dist/ka_uts_com-1.0.1.250131.tar.gz +0 -0
  30. build/lib/ka_uts_com/utils/py.typed +0 -0
  31. dist/ka_uts_com-1.0.1.250131-py3-none-any.whl +0 -0
  32. dist/ka_uts_com-1.0.1.250131.tar.gz +0 -0
  33. ka_uts_com/utils/py.typed +0 -0
  34. ka_uts_com-1.0.1.250131.dist-info/RECORD +0 -55
  35. {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.0.0.250407.dist-info}/WHEEL +0 -0
  36. {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.0.0.250407.dist-info}/top_level.txt +0 -0
@@ -26,8 +26,12 @@ class Timer:
26
26
  """ Timer Management
27
27
  """
28
28
  @staticmethod
29
- def sh_task_id(d_pacmod: TyDic, class_id: Any, parms: TnAny, sep: TyStr) -> TyStr:
30
- """ start Timer
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.
31
35
  """
32
36
  package = d_pacmod.get('package')
33
37
  module = d_pacmod.get('module')
@@ -48,16 +52,16 @@ class Timer:
48
52
 
49
53
  @classmethod
50
54
  def start(cls, class_id: TyAny, parms: TnAny = None, sep: TyStr = ".") -> None:
51
- """ start Timer
55
+ """ Start Timer
52
56
  """
53
- task_id = cls.sh_task_id(Com.d_pacmod, class_id, parms, sep)
57
+ task_id = cls.sh_task_id(Com.d_app_pacmod, class_id, parms, sep)
54
58
  Com.d_timer[task_id] = datetime.now()
55
59
 
56
60
  @classmethod
57
61
  def end(cls, class_id: TyAny, parms: TnAny = None, sep: TyStr = ".") -> None:
58
- """ end Timer
62
+ """ End Timer
59
63
  """
60
- task_id = cls.sh_task_id(Com.d_pacmod, class_id, parms, sep)
64
+ task_id = cls.sh_task_id(Com.d_app_pacmod, class_id, parms, sep)
61
65
  start = Com.d_timer.get(task_id)
62
66
  end = datetime.now()
63
67
  elapse_time_sec = Timestamp.sh_elapse_time_sec(end, start)
@@ -29,11 +29,9 @@ class AoEqStmt:
29
29
  def sh_d_eq(cls, a_eqstmt: TyArr, **kwargs) -> TyDic:
30
30
  """ show equates dictionary
31
31
  """
32
- root_cls = kwargs.get('root_cls')
33
32
  d_parms: TnDic = kwargs.get('d_parms')
34
33
  _sh_prof = kwargs.get('sh_prof')
35
34
  d_eq: TyDic = cls.init_d_eq(a_eqstmt)
36
35
  d_eq_new: TyDic = DoEq.verify(d_eq, d_parms)
37
- DoEq._set_d_pacmod(d_eq_new, root_cls)
38
36
  DoEq._set_sh_prof(d_eq_new, _sh_prof)
39
37
  return d_eq_new
@@ -2,7 +2,7 @@
2
2
  from collections.abc import Callable
3
3
  from typing import Any
4
4
 
5
- from ka_uts_com.utils.pacmod import PacMod
5
+ # from ka_uts_com.utils.pacmod import PacMod
6
6
  from ka_uts_com.utils.str import Str
7
7
  from ka_uts_com.utils.date import Date
8
8
 
@@ -55,12 +55,12 @@ class DoEq:
55
55
  # print(f"value = {value}, type(value) = {type(value)}")
56
56
  return value
57
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)
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
64
 
65
65
  @staticmethod
66
66
  def _set_sh_prof(d_eq: TyDic, sh_prof: TyCall | Any) -> None:
@@ -2,106 +2,122 @@
2
2
  from typing import Any
3
3
 
4
4
  from os import path as os_path
5
- import pkg_resources
5
+ # import pkg_resources
6
+ import importlib.resources as resources
6
7
 
7
8
  TyArr = list[Any]
8
9
  TyDic = dict[Any, Any]
10
+ TyPath = str
11
+
9
12
  TnDic = None | TyDic
13
+ TnPath = None | TyPath
10
14
 
11
15
 
12
16
  class PacMod:
13
17
  """ Package Module Management
14
18
  """
15
19
  @staticmethod
16
- def sh_d_pacmod(root_cls, tenant: Any) -> TyDic:
20
+ def sh_d_pacmod(cls) -> TyDic:
17
21
  """ Show Pacmod Dictionary
18
22
  """
19
- a_pacmod: TyArr = root_cls.__module__.split(".")
20
- package = a_pacmod[0]
21
- module = a_pacmod[1]
22
- d_pacmod: TyDic = {}
23
- d_pacmod['tenant'] = tenant
24
- d_pacmod['package'] = package
25
- d_pacmod['module'] = module
26
- return d_pacmod
23
+ a_pacmod: TyArr = cls.__module__.split(".")
24
+ return {'package': a_pacmod[0], 'module': a_pacmod[1]}
27
25
 
28
- # class Cfg:
29
- # """ Configuration Sub Class of Package Module Class
30
- # """
31
26
  @staticmethod
32
- def sh_path_cfg_yaml(d_pacmod: TyDic) -> str:
27
+ def sh_path_module_yaml(d_pacmod: TyDic) -> str:
33
28
  """ show directory
34
29
  """
30
+ # def sh_path_cfg_yaml(d_pacmod: TyDic) -> str:
35
31
  package = d_pacmod['package']
36
32
  module = d_pacmod['module']
37
-
38
- directory: str = f"{package}.data"
39
-
40
- # print(f"dir = {dir}")
41
- # print(f"package = {package}")
42
- # print(f"module = {module}")
43
-
44
- path: str = pkg_resources.resource_filename(directory, f"{module}.yml")
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)
45
37
  return path
46
38
 
47
39
  @staticmethod
48
- def sh_path_keys_yaml(
49
- d_pacmod: TyDic, filename: str = 'keys.yml') -> str:
40
+ def sh_path_keys(
41
+ d_pacmod: TyDic, filename: str = 'keys.yml') -> TyPath:
50
42
  """ show directory
51
43
  """
52
44
  package = d_pacmod['package']
53
- directory = f"{package}.data"
54
- path: str = pkg_resources.resource_filename(directory, filename)
45
+ files = resources.files(f"{package}.data")
46
+ print("sh_path_keys files = {files}")
47
+ path: TyPath = files.joinpath(filename)
55
48
  return path
56
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
+
57
64
  @staticmethod
58
- def sh_pacmod_type(d_pacmod: TyDic, type_: str) -> str:
59
- """ show Data File Path
65
+ def sh_path_cfg(com) -> TyPath:
66
+ """ show directory
60
67
  """
61
- package = d_pacmod['package']
62
- module = d_pacmod['module']
63
- return f"/data/{package}/{module}/{type_}"
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
64
74
 
65
- @classmethod
66
- def sh_file_path(
67
- cls, d_pacmod: TyDic, type_: str, suffix: str,
68
- pid: Any, ts: Any, **kwargs) -> str:
69
- """ show type specific path
70
- """
71
- filename = kwargs.get('filename')
72
- if filename is not None:
73
- filename_ = filename
74
- else:
75
- filename_ = type_
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_}"
76
83
 
77
- sw_run_pid_ts = kwargs.get('sw_run_pid_ts', True)
78
- if sw_run_pid_ts is None:
79
- sw_run_pid_ts = True
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
80
102
 
81
- _dir: str = cls.sh_pacmod_type(d_pacmod, type_)
82
- if sw_run_pid_ts:
83
- file_path = os_path.join(
84
- _dir, f"{filename_}_{pid}_{ts}.{suffix}")
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_}"
85
113
  else:
86
- file_path = os_path.join(_dir, f"{filename_}.{suffix}")
87
- return file_path
114
+ return f"{dir_dat}/{package}/{module}/{type_}"
88
115
 
89
116
  @classmethod
90
- def sh_pattern(
91
- cls, d_pacmod: TyDic, type_: str, suffix: str, **kwargs) -> str:
117
+ def sh_path_pattern(
118
+ cls, com, filename, type_: str, suffix: str) -> str:
92
119
  """ show type specific path
93
120
  """
94
- filename = kwargs.get('filename')
95
- _directory: str = cls.sh_pacmod_type(d_pacmod, type_)
96
- path = os_path.join(_directory, f"{filename}*.{suffix}")
121
+ _dir: str = cls.sh_dir_type(com, type_)
122
+ path: TyPath = os_path.join(_dir, f"{filename}*.{suffix}")
97
123
  return path
98
-
99
- @staticmethod
100
- def sh_path_cfg_log(d_pacmod: TnDic = None, filename: str = 'log.yml'):
101
- """ show directory
102
- """
103
- if d_pacmod is None:
104
- d_pacmod = {'package': 'ka_uts_com', 'module': 'com'}
105
- return pkg_resources.resource_filename(
106
- f"{d_pacmod['package']}.data", filename
107
- )
ka_uts_com/__version__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  __title__ = 'ka_uts_com'
2
2
  __description__ = 'Communication Utilities.'
3
3
  __url__ = 'https://ka-ut-com.readthedocs.io/en/latest'
4
- __version__ = '1.0.1.250131'
4
+ __version__ = '2.0.0.250407'
5
5
  __build__ = 0x022200
6
6
  __author__ = 'Bernd Stroehle'
7
7
  __author_email__ = 'bernd.stroehle@gmail.com'
ka_uts_com/base/app_.py CHANGED
@@ -22,30 +22,29 @@ class App_:
22
22
  """Aplication Class
23
23
  """
24
24
  sw_init: TyBool = False
25
- httpmod: TyAny = None
26
25
  sw_replace_keys: TnBool = None
27
26
  keys: TnArr = None
27
+ httpmod: TyAny = None
28
28
  reqs: TyDic = {}
29
29
  app: TyDic = {}
30
30
 
31
31
  @classmethod
32
- def init(cls, log: TyLogger, **kwargs) -> None:
32
+ def init(cls, com, **kwargs) -> None:
33
33
  if cls.sw_init:
34
34
  return
35
35
  cls.sw_init = True
36
36
  cls.httpmod = kwargs.get('httpmod')
37
37
  cls.sw_replace_keys = kwargs.get('sw_replace_keys', False)
38
- try:
39
- if cls.sw_replace_keys:
40
- d_pacmod: TyDic = kwargs.get('d_pacmod', {})
41
- cls.keys = Yaml_.read(PacMod.sh_path_keys_yaml(d_pacmod), log)
42
- except Exception as exc:
43
- log.error(exc, exc_info=True)
44
- raise
38
+ if cls.sw_replace_keys:
39
+ try:
40
+ cls.keys = Yaml_.read(PacMod.sh_path_keys(com), com.Log)
41
+ except Exception as exc:
42
+ com.Log.error(exc, exc_info=True)
43
+ raise
45
44
 
46
45
  @classmethod
47
- def sh(cls, log: TyLogger, **kwargs) -> Any:
46
+ def sh(cls, com, **kwargs) -> Any:
48
47
  if cls.sw_init:
49
48
  return cls
50
- cls.init(log, **kwargs)
49
+ cls.init(com, **kwargs)
51
50
  return cls
ka_uts_com/base/cfg_.py CHANGED
@@ -17,11 +17,19 @@ TyLogger = Logger
17
17
  class Cfg_:
18
18
  """Configuration Class
19
19
  """
20
+ sw_init: TyBool = False
20
21
  cfg: Any = None
21
22
 
22
23
  @classmethod
23
- def sh(cls, log: TyLogger, d_pacmod: TyDic) -> Any:
24
- """ show configuration
25
- """
26
- cls.cfg = Yaml_.read(PacMod.sh_path_cfg_yaml(d_pacmod), log)
24
+ def init(cls, com, **kwargs) -> None:
25
+ if cls.sw_init:
26
+ return
27
+ cls.sw_init = True
28
+ cls.cfg = Yaml_.read(PacMod.sh_path_cfg(com), com.Log)
29
+
30
+ @classmethod
31
+ def sh(cls, com, **kwargs) -> Any:
32
+ if cls.sw_init:
33
+ return cls
34
+ cls.init(com, **kwargs)
27
35
  return cls.cfg
ka_uts_com/base/log_.py CHANGED
@@ -9,7 +9,7 @@ from logging import Logger
9
9
  from datetime import datetime
10
10
  import psutil
11
11
 
12
- from ka_uts_com.utils.pacmod import PacMod
12
+ # from ka_uts_com.com import Com
13
13
  from ka_uts_com.ioc.jinja2_ import Jinja2_
14
14
 
15
15
  TyAny = Any
@@ -20,6 +20,7 @@ TyArr = list[Any]
20
20
  TyBool = bool
21
21
  TyDic = dict[Any, Any]
22
22
  TyDir = str
23
+ TyPath = str
23
24
  TyLogger = Logger
24
25
 
25
26
  TnAny = None | Any
@@ -30,11 +31,6 @@ TnTimeStamp = None | TyTimeStamp
30
31
  TnDateTime = None | TyDateTime
31
32
 
32
33
 
33
- class LogStandard:
34
- """Standard Logging
35
- """
36
-
37
-
38
34
  class Log_:
39
35
 
40
36
  sw_init: bool = False
@@ -42,70 +38,90 @@ class Log_:
42
38
  username: str = psutil.Process().username()
43
39
 
44
40
  @classmethod
45
- def sh_run_dir(cls, com, **kwargs) -> TyDir:
41
+ def sh_dir_run(cls, com) -> TyDir:
46
42
  """Show run_dir
47
43
  """
48
- tenant: str = com.d_pacmod['tenant']
49
- package: str = com.d_pacmod['package']
50
- module: str = com.d_pacmod['module']
51
- log_type: str = kwargs.get('log_type', 'std')
52
- if log_type == "std":
53
- return f"/data/{tenant}/RUN/{package}/{module}"
54
- return f"/data/{tenant}/RUN/{package}/{module}/{cls.username}"
44
+ # print(f"sh_dir_run com.dir_dat = {com.dir_dat}")
45
+ # print(f"sh_dir_run com.cmd = {com.cmd}")
46
+ # print(f"sh_dir_run com.tenant = {com.tenant}")
47
+ # print(f"sh_dir_run com = {com}")
48
+ dir_dat: str = com.dir_dat
49
+ tenant: str = com.tenant
50
+ cmd: str = com.cmd
51
+ package: str = com.d_app_pacmod['package']
52
+ # module: str = com.d_app_pacmod['module']
53
+ if tenant is not None:
54
+ path = f"{dir_dat}/{tenant}/RUN/{package}"
55
+ else:
56
+ path = f"{dir_dat}/RUN/{package}"
57
+ if com.log_type == "usr":
58
+ path = f"{path}/{cls.username}"
59
+ if cmd is not None:
60
+ path = f"{path}/{cmd}"
61
+ # print(f"sh_dir_run path = {path}")
62
+ # print("==================================")
63
+ return path
55
64
 
56
65
  @classmethod
57
- def sh_cfg(cls, com, **kwargs) -> TyDic:
66
+ def sh_d_log_cfg(cls, com, **kwargs) -> TyDic:
58
67
  """Read log file path with jinja2
59
68
  """
60
- run_dir = kwargs.get('run_dir', cls.sh_run_dir(com, **kwargs))
61
- run_dir_debug: str = kwargs.get('run_dir_debug', f"{run_dir}/debs")
62
- run_dir_info: str = kwargs.get('run_dir_info', f"{run_dir}/logs")
63
- run_dir_error: str = kwargs.get('run_dir_error', f"{run_dir}/errs")
64
-
65
- if kwargs.get('sw_mklogdirs', True):
66
- os.makedirs(run_dir_debug, exist_ok=True)
67
- os.makedirs(run_dir_info, exist_ok=True)
68
- os.makedirs(run_dir_error, exist_ok=True)
69
-
70
- log_type = kwargs.get('log_type', 'std')
71
- logcfg_file = f'log.{log_type}.yml'
72
- logcfg_path: str = PacMod.sh_path_cfg_log(filename=logcfg_file)
73
- cfg: TyDic = Jinja2_.read(
74
- logcfg_path,
75
- com.Log,
76
- debug_dir=run_dir_debug,
77
- info_dir=run_dir_info,
78
- error_dir=run_dir_error,
79
- module=com.d_pacmod['module'],
69
+ dir_run = cls.sh_dir_run(com)
70
+ if kwargs.get('sw_single_dir_run', True):
71
+ # print("---sw_single_dir_run = True --------------")
72
+ dir_run_errs = f"{dir_run}/logs"
73
+ dir_run_wrns = f"{dir_run}/logs"
74
+ dir_run_infs = f"{dir_run}/logs"
75
+ dir_run_logs = f"{dir_run}/logs"
76
+ dir_run_debs = f"{dir_run}/logs"
77
+ if kwargs.get('sw_mk_dir_run', True):
78
+ os.makedirs(dir_run_logs, exist_ok=True)
79
+ else:
80
+ # print("---sw_single_dir_run = False -------------")
81
+ dir_run_errs = f"{dir_run}/errs"
82
+ dir_run_wrns = f"{dir_run}/wrns"
83
+ dir_run_infs = f"{dir_run}/infs"
84
+ dir_run_logs = f"{dir_run}/logs"
85
+ dir_run_debs = f"{dir_run}/debs"
86
+ if kwargs.get('sw_mk_dir_run', True):
87
+ os.makedirs(dir_run_errs, exist_ok=True)
88
+ os.makedirs(dir_run_wrns, exist_ok=True)
89
+ os.makedirs(dir_run_infs, exist_ok=True)
90
+ os.makedirs(dir_run_logs, exist_ok=True)
91
+ os.makedirs(dir_run_debs, exist_ok=True)
92
+ # path_log_cfg: TyPath = PacMod.sh_path_log_cfg(com)
93
+ module = com.d_app_pacmod['module']
94
+ # print(f"sh_d_log_cfg cls.path_log_cfg = {cls.path_log_cfg}")
95
+ d_log_cfg: TyDic = Jinja2_.read(
96
+ com.path_log_cfg, com.Log,
97
+ dir_run_errs=dir_run_errs,
98
+ dir_run_wrns=dir_run_wrns,
99
+ dir_run_infs=dir_run_infs,
100
+ dir_run_logs=dir_run_logs,
101
+ dir_run_debs=dir_run_debs,
102
+ module=module,
80
103
  pid=com.pid,
81
104
  ts=com.ts)
82
- # ts=com.ts_start)
105
+ # print(f"sh_d_log_cfg d_log_cfg = {d_log_cfg}")
83
106
  sw_debug: TyBool = kwargs.get('sw_debug', False)
84
107
  if sw_debug:
85
108
  level = logging.DEBUG
86
109
  else:
87
110
  level = logging.INFO
88
- if log_type == 'std':
89
- logger_name = 'main'
90
- else:
91
- logger_name = 'person'
92
- cfg['handlers'][f"{logger_name}_debug_console"]['level'] = level
93
- cfg['handlers'][f"{logger_name}_debug_file"]['level'] = level
111
+ logger_name = com.log_type
112
+ d_log_cfg['handlers'][f"{logger_name}_debug_console"]['level'] = level
113
+ d_log_cfg['handlers'][f"{logger_name}_debug_file"]['level'] = level
94
114
 
95
- return cfg
115
+ return d_log_cfg
96
116
 
97
117
  @classmethod
98
118
  def init(cls, com, **kwargs) -> None:
99
119
  """Set static variable log level in log configuration handlers
100
120
  """
101
- log_type = kwargs.get('log_type', 'std')
102
121
  cls.sw_init = True
103
- cfg = cls.sh_cfg(com, **kwargs)
104
- logging.config.dictConfig(cfg)
105
- if log_type == "std":
106
- cls.log = logging.getLogger('main')
107
- else:
108
- cls.log = logging.getLogger(log_type)
122
+ d_log_cfg = cls.sh_d_log_cfg(com, **kwargs)
123
+ logging.config.dictConfig(d_log_cfg)
124
+ cls.log = logging.getLogger(com.log_type)
109
125
 
110
126
  @classmethod
111
127
  def sh(cls, com, **kwargs) -> TyLogger:
ka_uts_com/com.py CHANGED
@@ -4,12 +4,14 @@ from typing import Any
4
4
  import os
5
5
  import time
6
6
  import calendar
7
+ import importlib.resources as resources
7
8
  import logging
8
9
  import logging.config
9
10
  from logging import Logger
10
11
  from datetime import datetime
11
12
 
12
13
  from ka_uts_com.utils.aoeqstmt import AoEqStmt
14
+ from ka_uts_com.utils.pacmod import PacMod
13
15
  from ka_uts_com.base.app_ import App_
14
16
  from ka_uts_com.base.cfg_ import Cfg_
15
17
  from ka_uts_com.base.exit_ import Exit_
@@ -28,15 +30,23 @@ TnArr = None | TyArr
28
30
  TnDic = None | TyDic
29
31
  TnTimeStamp = None | TyTimeStamp
30
32
  TnDateTime = None | TyDateTime
33
+ TnStr = None | str
31
34
 
32
35
 
33
36
  class Com:
34
37
  """Communication Class
35
38
  """
36
39
  sw_init: bool = False
37
- cfg: TnDic = None
40
+ dir_dat: TnStr = None
41
+ tenant: TnStr = None
42
+ log_type: TnStr = None
43
+ cmd: TnStr = None
44
+ d_com_pacmod: TyDic = {}
45
+ d_app_pacmod: TyDic = {}
46
+ path_bin = None
47
+ path_log_cfg = None
48
+
38
49
  pid = None
39
- d_pacmod: TyDic = {}
40
50
 
41
51
  ts: TnTimeStamp
42
52
  ts_start: TnDateTime = None
@@ -44,29 +54,68 @@ class Com:
44
54
  ts_etime: TnDateTime = None
45
55
  d_timer: TyDic = {}
46
56
 
47
- Log: Logger = logging.getLogger('dummy_logger')
57
+ cfg: TnDic = None
58
+ Log = logging.getLogger('dummy_logger')
48
59
  App: Any = None
49
60
  Exit: Any = None
50
61
 
51
62
  @classmethod
52
- def init(cls, **kwargs):
63
+ def init(cls, app_cls, kwargs: TyDic):
53
64
  """ set log and application (module) configuration
54
65
  """
55
66
  if cls.sw_init:
56
67
  return
57
68
  cls.sw_init = True
58
- cls.d_pacmod = kwargs.get('d_pacmod', {})
69
+ cls.dir_dat = kwargs.get('dir_dat', '/data')
70
+ cls.tenant = kwargs.get('tenant')
71
+ cls.log_type = kwargs.get('log_type', 'std')
72
+ cls.cmd = kwargs.get('cmd')
73
+ cls.d_com_pacmod = PacMod.sh_d_pacmod(cls)
74
+ cls.d_app_pacmod = PacMod.sh_d_pacmod(app_cls)
75
+
59
76
  cls.ts = calendar.timegm(time.gmtime())
60
77
  cls.pid = os.getpid()
61
78
 
79
+ # print(f"Com.init cls.tenanat = {cls.tenant}")
80
+ # print(f"Com.init cls.cmd = {cls.cmd}")
81
+ # print(f"Com.init kwargs = {kwargs}")
82
+
83
+ cls.set_path_bin()
84
+ cls.set_path_log_cfg()
85
+
62
86
  cls.Log = Log_.sh(cls, **kwargs)
63
- cls.cfg = Cfg_.sh(cls.Log, cls.d_pacmod)
64
- cls.App = App_.sh(cls.Log, **kwargs)
87
+ cls.cfg = Cfg_.sh(cls, **kwargs)
88
+ cls.App = App_.sh(cls, **kwargs)
65
89
  cls.Exit = Exit_.sh(**kwargs)
66
90
 
67
91
  @classmethod
68
- def sh_kwargs(cls, root_cls, d_parms, *args) -> TyDic:
69
- _kwargs: TyDic = AoEqStmt.sh_d_eq(
70
- *args, d_parms=d_parms, root_cls=root_cls)
71
- cls.init(**_kwargs)
92
+ def sh_kwargs(cls, app_cls, d_parms, *args) -> TyDic:
93
+ _kwargs: TyDic = AoEqStmt.sh_d_eq(*args, d_parms=d_parms)
94
+ cls.init(app_cls, _kwargs)
95
+ _kwargs['com'] = cls
72
96
  return _kwargs
97
+
98
+ @classmethod
99
+ def set_path_bin(cls):
100
+ """ show directory
101
+ """
102
+ package = cls.d_app_pacmod['package']
103
+ path = resources.files(package).joinpath("bin")
104
+ if path.is_file():
105
+ cls.path_bin = path
106
+ # raise ModuleNotFoundError
107
+
108
+ @classmethod
109
+ def set_path_log_cfg(cls):
110
+ """ show directory
111
+ """
112
+ package = cls.d_app_pacmod['package']
113
+ path = resources.files(package).joinpath(f"data/log.{cls.log_type}.yml")
114
+ if path.is_file():
115
+ cls.path_log_cfg = path
116
+ return
117
+ package = cls.d_com_pacmod['package']
118
+ path = resources.files(package).joinpath(f"data/log.{cls.log_type}.yml")
119
+ if path.is_file():
120
+ cls.path_log_cfg = path
121
+ # raise ModuleNotFoundError