ka-uts-com 1.0.1.250131__py3-none-any.whl → 2.1.0.250408__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 (46) hide show
  1. build/lib/dist/ka_uts_com-2.0.0.250407-py3-none-any.whl +0 -0
  2. build/lib/dist/ka_uts_com-2.0.0.250407.tar.gz +0 -0
  3. build/lib/ka_uts_com/__version__.py +1 -1
  4. build/lib/ka_uts_com/base/app_.py +10 -11
  5. build/lib/ka_uts_com/base/cfg_.py +14 -5
  6. build/lib/ka_uts_com/base/log_.py +66 -50
  7. build/lib/ka_uts_com/com.py +54 -11
  8. build/lib/ka_uts_com/data/log.std.yml +47 -26
  9. build/lib/ka_uts_com/data/log.usr.yml +46 -25
  10. build/lib/ka_uts_com/ioc/jinja2_.py +1 -1
  11. build/lib/ka_uts_com/ioc/yaml_.py +2 -1
  12. build/lib/ka_uts_com/log.py +23 -12
  13. build/lib/ka_uts_com/timer.py +10 -6
  14. build/lib/ka_uts_com/utils/aoeqstmt.py +0 -2
  15. build/lib/ka_uts_com/utils/doeq.py +7 -7
  16. build/lib/ka_uts_com/utils/pac.py +35 -0
  17. build/lib/ka_uts_com/utils/pacmod.py +74 -72
  18. dist/ka_uts_com-2.0.0.250407-py3-none-any.whl +0 -0
  19. dist/ka_uts_com-2.0.0.250407.tar.gz +0 -0
  20. ka_uts_com/__version__.py +1 -1
  21. ka_uts_com/base/app_.py +10 -11
  22. ka_uts_com/base/cfg_.py +14 -5
  23. ka_uts_com/base/log_.py +66 -50
  24. ka_uts_com/com.py +54 -11
  25. ka_uts_com/data/log.std.yml +47 -26
  26. ka_uts_com/data/log.usr.yml +46 -25
  27. ka_uts_com/ioc/jinja2_.py +1 -1
  28. ka_uts_com/ioc/yaml_.py +2 -1
  29. ka_uts_com/log.py +23 -12
  30. ka_uts_com/timer.py +10 -6
  31. ka_uts_com/utils/aoeqstmt.py +0 -2
  32. ka_uts_com/utils/doeq.py +7 -7
  33. ka_uts_com/utils/pac.py +35 -0
  34. ka_uts_com/utils/pacmod.py +74 -72
  35. {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.1.0.250408.dist-info}/METADATA +389 -406
  36. ka_uts_com-2.1.0.250408.dist-info/RECORD +55 -0
  37. {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.1.0.250408.dist-info}/licenses/LICENSE.txt +1 -2
  38. build/lib/dist/ka_uts_com-1.0.1.250131-py3-none-any.whl +0 -0
  39. build/lib/dist/ka_uts_com-1.0.1.250131.tar.gz +0 -0
  40. build/lib/ka_uts_com/utils/py.typed +0 -0
  41. dist/ka_uts_com-1.0.1.250131-py3-none-any.whl +0 -0
  42. dist/ka_uts_com-1.0.1.250131.tar.gz +0 -0
  43. ka_uts_com/utils/py.typed +0 -0
  44. ka_uts_com-1.0.1.250131.dist-info/RECORD +0 -55
  45. {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.1.0.250408.dist-info}/WHEEL +0 -0
  46. {ka_uts_com-1.0.1.250131.dist-info → ka_uts_com-2.1.0.250408.dist-info}/top_level.txt +0 -0
@@ -8,21 +8,25 @@ class Log:
8
8
  """
9
9
  class Eq:
10
10
 
11
- @classmethod
12
- def debug(cls, key: Any, value: Any) -> None:
13
- Log.debug(f"{key} = {value}", stacklevel=3)
14
-
15
11
  @classmethod
16
12
  def error(cls, key: Any, value: Any) -> None:
17
13
  Log.error(f"{key} = {value}", stacklevel=3)
18
14
 
15
+ @classmethod
16
+ def warning(cls, key: Any, value: Any) -> None:
17
+ Log.warning(f"{key} = {value}", stacklevel=3)
18
+
19
19
  @classmethod
20
20
  def info(cls, key: Any, value: Any) -> None:
21
21
  Log.info(f"{key} = {value}", stacklevel=3)
22
22
 
23
23
  @classmethod
24
- def warning(cls, key: Any, value: Any) -> None:
25
- Log.warning(f"{key} = {value}", stacklevel=3)
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)
26
30
 
27
31
  class Dic:
28
32
 
@@ -47,18 +51,18 @@ class Log:
47
51
  Log.warning(f"{key} = {value}", stacklevel=3)
48
52
 
49
53
  @staticmethod
50
- def debug(*args, **kwargs) -> None:
54
+ def error(*args, **kwargs) -> None:
51
55
  if kwargs is None:
52
56
  kwargs = {}
53
57
  kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
54
- Com.Log.debug(*args, **kwargs)
58
+ Com.Log.error(*args, **kwargs)
55
59
 
56
60
  @staticmethod
57
- def error(*args, **kwargs) -> None:
61
+ def warning(*args, **kwargs) -> None:
58
62
  if kwargs is None:
59
63
  kwargs = {}
60
64
  kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
61
- Com.Log.error(*args, **kwargs)
65
+ Com.Log.warning(*args, **kwargs)
62
66
 
63
67
  @staticmethod
64
68
  def info(*args, **kwargs) -> None:
@@ -68,8 +72,15 @@ class Log:
68
72
  Com.Log.info(*args, **kwargs)
69
73
 
70
74
  @staticmethod
71
- def warning(*args, **kwargs) -> None:
75
+ def log(*args, **kwargs) -> None:
72
76
  if kwargs is None:
73
77
  kwargs = {}
74
78
  kwargs['stacklevel'] = kwargs.get('stacklevel', 2)
75
- Com.Log.warning(*args, **kwargs)
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)
@@ -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:
@@ -0,0 +1,35 @@
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 ''
@@ -2,106 +2,108 @@
2
2
  from typing import Any
3
3
 
4
4
  from os import path as os_path
5
- import pkg_resources
5
+
6
+ from ka_uts_com.utils.pac import Pac
6
7
 
7
8
  TyArr = list[Any]
8
9
  TyDic = dict[Any, Any]
9
- TnDic = None | TyDic
10
+ TyPath = str
10
11
 
11
12
 
12
13
  class PacMod:
13
14
  """ Package Module Management
14
15
  """
15
16
  @staticmethod
16
- def sh_d_pacmod(root_cls, tenant: Any) -> TyDic:
17
+ def sh_d_pacmod(cls) -> TyDic:
17
18
  """ Show Pacmod Dictionary
18
19
  """
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
20
+ a_pacmod: TyArr = cls.__module__.split(".")
21
+ return {'package': a_pacmod[0], 'module': a_pacmod[1]}
27
22
 
28
- # class Cfg:
29
- # """ Configuration Sub Class of Package Module Class
30
- # """
31
23
  @staticmethod
32
- def sh_path_cfg_yaml(d_pacmod: TyDic) -> str:
24
+ def sh_path_module_yaml(d_pacmod: TyDic) -> Any:
33
25
  """ show directory
34
26
  """
35
27
  package = d_pacmod['package']
36
28
  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")
45
- return path
29
+ path = f"{module}/data/{module}.yml"
30
+ return Pac.sh_path_by_package(package, path)
46
31
 
47
32
  @staticmethod
48
- def sh_path_keys_yaml(
49
- d_pacmod: TyDic, filename: str = 'keys.yml') -> str:
33
+ def sh_path_keys(d_pacmod: TyDic) -> Any:
50
34
  """ show directory
51
35
  """
52
36
  package = d_pacmod['package']
53
- directory = f"{package}.data"
54
- path: str = pkg_resources.resource_filename(directory, filename)
55
- return path
37
+ path = 'data/keys.yml'
38
+ return Pac.sh_path_by_package(package, path)
56
39
 
57
- @staticmethod
58
- def sh_pacmod_type(d_pacmod: TyDic, type_: str) -> str:
59
- """ show Data File Path
60
- """
61
- package = d_pacmod['package']
62
- module = d_pacmod['module']
63
- return f"/data/{package}/{module}/{type_}"
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
64
53
 
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_
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_}"
76
70
 
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
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
80
89
 
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}")
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_}"
85
100
  else:
86
- file_path = os_path.join(_dir, f"{filename_}.{suffix}")
87
- return file_path
101
+ return f"{dir_dat}/{package}/{module}/{type_}"
88
102
 
89
103
  @classmethod
90
- def sh_pattern(
91
- cls, d_pacmod: TyDic, type_: str, suffix: str, **kwargs) -> str:
104
+ def sh_path_pattern(
105
+ cls, com, filename, type_: str, suffix: str) -> TyPath:
92
106
  """ show type specific path
93
107
  """
94
- filename = kwargs.get('filename')
95
- _directory: str = cls.sh_pacmod_type(d_pacmod, type_)
96
- path = os_path.join(_directory, f"{filename}*.{suffix}")
97
- 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
- )
108
+ _dir: str = cls.sh_dir_type(com, type_)
109
+ return os_path.join(_dir, f"{filename}*.{suffix}")
Binary file
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.1.0.250408'
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
@@ -3,7 +3,6 @@ from typing import Any
3
3
 
4
4
  from logging import Logger
5
5
 
6
- from ka_uts_com.utils.pacmod import PacMod
7
6
  from ka_uts_com.ioc.yaml_ import Yaml_
8
7
 
9
8
  TyAny = Any
@@ -17,11 +16,21 @@ TyLogger = Logger
17
16
  class Cfg_:
18
17
  """Configuration Class
19
18
  """
19
+ sw_init: TyBool = False
20
20
  cfg: Any = None
21
21
 
22
22
  @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)
23
+ def init(cls, com, **kwargs) -> None:
24
+ if cls.sw_init:
25
+ return
26
+ cls.sw_init = True
27
+ _path = com.sh_path_cfg()
28
+ if _path:
29
+ cls.cfg = Yaml_.read(_path, com.Log)
30
+
31
+ @classmethod
32
+ def sh(cls, com, **kwargs) -> Any:
33
+ if cls.sw_init:
34
+ return cls
35
+ cls.init(com, **kwargs)
27
36
  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: