holado 0.2.3__py3-none-any.whl → 0.2.5__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.

Potentially problematic release.


This version of holado might be problematic. Click here for more details.

Files changed (30) hide show
  1. holado/__init__.py +61 -23
  2. holado/common/context/service_manager.py +10 -2
  3. holado/common/context/session_context.py +43 -12
  4. holado/common/handlers/object.py +12 -4
  5. holado/holado_config.py +1 -0
  6. {holado-0.2.3.dist-info → holado-0.2.5.dist-info}/METADATA +1 -1
  7. {holado-0.2.3.dist-info → holado-0.2.5.dist-info}/RECORD +30 -30
  8. holado_ais/ais/ais_messages.py +140 -139
  9. holado_core/common/tools/path_manager.py +8 -4
  10. holado_grpc/api/rpc/grpc_client.py +122 -118
  11. holado_helper/docker/logging.conf +3 -1
  12. holado_helper/docker/run_holado_test_nonreg_in_docker.sh +28 -28
  13. holado_helper/docker/run_terminal_in_docker-with_docker_control.sh +27 -27
  14. holado_helper/docker/run_terminal_in_docker.sh +26 -26
  15. holado_helper/script/initialize_script.py +5 -5
  16. holado_logging/__init__.py +7 -9
  17. holado_logging/common/logging/holado_logger.py +2 -2
  18. holado_logging/common/logging/log_config.py +152 -127
  19. holado_logging/common/logging/log_manager.py +20 -19
  20. holado_multitask/multitasking/multitask_manager.py +1 -1
  21. holado_multitask/multithreading/thread.py +8 -4
  22. holado_protobuf/__init__.py +1 -1
  23. holado_protobuf/ipc/protobuf/protobuf_messages.py +821 -818
  24. holado_rabbitmq/tools/rabbitmq/rabbitmq_client.py +1 -2
  25. holado_test/behave/independant_runner.py +3 -5
  26. holado_test/scenario/step_tools.py +2 -0
  27. test_holado/environment.py +1 -1
  28. test_holado/logging.conf +3 -1
  29. {holado-0.2.3.dist-info → holado-0.2.5.dist-info}/WHEEL +0 -0
  30. {holado-0.2.3.dist-info → holado-0.2.5.dist-info}/licenses/LICENSE +0 -0
@@ -1,128 +1,153 @@
1
-
2
- #################################################
3
- # HolAdo (Holistic Automation do)
4
- #
5
- # (C) Copyright 2021-2025 by Eric Klumpp
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
- #
9
- # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
-
11
- # The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
12
- #################################################
13
-
14
- import logging
15
-
16
-
17
- # logger = logging.getLogger(__name__)
18
-
19
-
20
- class LogConfig(object):
21
- TLogger = None
22
- TManager = None
23
- default_level = logging.INFO
24
-
25
- @classmethod
26
- def configure(cls, initialize_logging=True, log_level=None):
27
- # HolAdo needs at least to add logging level TRACE and PRINT
28
- cls.add_logging_level_trace()
29
- cls.add_logging_level_print()
30
-
31
- if log_level:
32
- if isinstance(log_level, str):
33
- cls.default_level = logging._nameToLevel[log_level]
34
- else:
35
- cls.default_level = log_level
36
-
37
- if initialize_logging:
38
- from holado_logging.common.logging.holado_logger import HALogger
39
-
40
- HALogger.default_message_size_limit = 10000
41
- cls.TLogger = HALogger
42
- cls.TManager = logging.Manager
43
-
44
- # Configure logging
45
- cls.configure_logging()
46
-
47
- @classmethod
48
- def configure_logging(cls):
49
- #TODO EKL: make loggers configuration optional
50
- # Configure loggers
51
- from holado_logging.common.logging.holado_logger import TestRootLogger
52
- logging.root = TestRootLogger(cls.default_level)
53
- logging.Logger.root = logging.root
54
- logging.Logger.manager = cls.TManager(cls.TLogger.root)
55
-
56
- logging.setLoggerClass(cls.TLogger)
57
-
58
-
59
- @classmethod
60
- def add_logging_level_print(cls):
61
- if not cls.has_logging_level("PRINT"):
62
- cls.add_logging_level("PRINT", 45, None)
63
-
64
- @classmethod
65
- def add_logging_level_trace(cls):
66
- if not cls.has_logging_level("TRACE"):
67
- cls.add_logging_level("TRACE", 5, None)
68
-
69
-
70
- @classmethod
71
- def has_logging_level(cls, levelName):
72
- return hasattr(logging, levelName)
73
-
74
- @classmethod
75
- def add_logging_level(cls, levelName, levelNum, methodName=None):
76
- """
77
- This method was implemented and shared by the author of library haggis (https://haggis.readthedocs.io).
78
-
79
- Comprehensively adds a new logging level to the `logging` module and the
80
- currently configured logging class.
81
-
82
- `levelName` becomes an attribute of the `logging` module with the value
83
- `levelNum`. `methodName` becomes a convenience method for both `logging`
84
- itself and the class returned by `logging.getLoggerClass()` (usually just
85
- `logging.Logger`). If `methodName` is not specified, `levelName.lower()` is
86
- used.
87
-
88
- To avoid accidental clobberings of existing attributes, this method will
89
- raise an `AttributeError` if the level name is already an attribute of the
90
- `logging` module or if the method name is already present
91
-
92
- Example
93
- -------
94
- >>> addLoggingLevel('TRACE', logging.DEBUG - 5)
95
- >>> logging.getLogger(__name__).setLevel("TRACE")
96
- >>> logging.getLogger(__name__).trace('that worked')
97
- >>> logging.trace('so did this')
98
- >>> logging.TRACE
99
- 5
100
-
101
- """
102
- if not methodName:
103
- methodName = levelName.lower()
104
-
105
- if hasattr(logging, levelName):
106
- raise AttributeError('{} already defined in logging module'.format(levelName))
107
- if hasattr(logging, methodName):
108
- raise AttributeError('{} already defined in logging module'.format(methodName))
109
- if hasattr(logging.getLoggerClass(), methodName):
110
- raise AttributeError('{} already defined in logger class'.format(methodName))
111
-
112
- # This method was inspired by the answers to Stack Overflow post
113
- # http://stackoverflow.com/q/2183233/2988730, especially
114
- # http://stackoverflow.com/a/13638084/2988730
115
- def logForLevel(self, message, *args, **kwargs):
116
- if self.isEnabledFor(levelNum):
117
- self._log(levelNum, message, args, **kwargs)
118
- def logToRoot(message, *args, **kwargs):
119
- logging.log(levelNum, message, *args, **kwargs)
120
-
121
- logging.addLevelName(levelNum, levelName)
122
- setattr(logging, levelName, levelNum)
123
- setattr(logging.getLoggerClass(), methodName, logForLevel)
124
- setattr(logging, methodName, logToRoot)
125
-
126
-
127
-
1
+
2
+ #################################################
3
+ # HolAdo (Holistic Automation do)
4
+ #
5
+ # (C) Copyright 2021-2025 by Eric Klumpp
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ # The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
12
+ #################################################
13
+
14
+ import logging
15
+
16
+
17
+ # logger = logging.getLogger(__name__)
18
+
19
+
20
+ class LogConfig(object):
21
+ TLogger = None
22
+ TManager = None
23
+ config_file_path = None
24
+ default_level = logging.INFO
25
+ log_on_console=False
26
+ log_in_file=True
27
+ __is_configured = False
28
+
29
+ @classmethod
30
+ def configure(cls, use_holado_logger=True, config_file_path=None, log_level=None, log_on_console=False, log_in_file=True):
31
+ if cls.__is_configured:
32
+ logging.warning(f"Logging was already configured, it is not possible to configure it twice. This new configuration is skipped.")
33
+ return
34
+
35
+ # HolAdo needs at least to add logging level TRACE and PRINT
36
+ cls.add_logging_level_trace()
37
+ cls.add_logging_level_print()
38
+
39
+ cls.config_file_path = config_file_path
40
+ if config_file_path:
41
+ import configparser
42
+ config = configparser.ConfigParser()
43
+ config.read(config_file_path)
44
+ log_level = config.get("holado", "level")
45
+ log_on_console = config.get("holado", "log_on_console")
46
+ log_in_file = config.get("holado", "log_in_file")
47
+
48
+ if log_level:
49
+ if isinstance(log_level, str):
50
+ log_level = logging._nameToLevel[log_level]
51
+ cls.default_level = log_level
52
+ if log_on_console:
53
+ if isinstance(log_on_console, str):
54
+ log_on_console = True if log_on_console == "True" else False
55
+ cls.log_on_console = log_on_console
56
+ if log_in_file:
57
+ if isinstance(log_in_file, str):
58
+ log_in_file = True if log_in_file == "True" else False
59
+ cls.log_in_file = log_in_file
60
+
61
+ if use_holado_logger:
62
+ cls.__set_holado_loggers()
63
+
64
+ cls.__is_configured = True
65
+
66
+ @classmethod
67
+ def __set_holado_loggers(cls):
68
+ from holado_logging.common.logging.holado_logger import HALogger
69
+
70
+ # Configure loggers to use
71
+ HALogger.default_message_size_limit = 10000
72
+ cls.TLogger = HALogger
73
+ cls.TManager = logging.Manager
74
+
75
+ # Set loggers in logging
76
+ from holado_logging.common.logging.holado_logger import HARootLogger
77
+ logging.root = HARootLogger(cls.default_level)
78
+ logging.Logger.root = logging.root
79
+ logging.Logger.manager = cls.TManager(cls.TLogger.root)
80
+
81
+ logging.setLoggerClass(cls.TLogger)
82
+
83
+
84
+ @classmethod
85
+ def add_logging_level_print(cls):
86
+ if not cls.has_logging_level("PRINT"):
87
+ cls.add_logging_level("PRINT", 45, None)
88
+
89
+ @classmethod
90
+ def add_logging_level_trace(cls):
91
+ if not cls.has_logging_level("TRACE"):
92
+ cls.add_logging_level("TRACE", 5, None)
93
+
94
+
95
+ @classmethod
96
+ def has_logging_level(cls, levelName):
97
+ return hasattr(logging, levelName)
98
+
99
+ @classmethod
100
+ def add_logging_level(cls, levelName, levelNum, methodName=None):
101
+ """
102
+ This method was implemented and shared by the author of library haggis (https://haggis.readthedocs.io).
103
+
104
+ Comprehensively adds a new logging level to the `logging` module and the
105
+ currently configured logging class.
106
+
107
+ `levelName` becomes an attribute of the `logging` module with the value
108
+ `levelNum`. `methodName` becomes a convenience method for both `logging`
109
+ itself and the class returned by `logging.getLoggerClass()` (usually just
110
+ `logging.Logger`). If `methodName` is not specified, `levelName.lower()` is
111
+ used.
112
+
113
+ To avoid accidental clobberings of existing attributes, this method will
114
+ raise an `AttributeError` if the level name is already an attribute of the
115
+ `logging` module or if the method name is already present
116
+
117
+ Example
118
+ -------
119
+ >>> addLoggingLevel('TRACE', logging.DEBUG - 5)
120
+ >>> logging.getLogger(__name__).setLevel("TRACE")
121
+ >>> logging.getLogger(__name__).trace('that worked')
122
+ >>> logging.trace('so did this')
123
+ >>> logging.TRACE
124
+ 5
125
+
126
+ """
127
+ if not methodName:
128
+ methodName = levelName.lower()
129
+
130
+ if hasattr(logging, levelName):
131
+ raise AttributeError('{} already defined in logging module'.format(levelName))
132
+ if hasattr(logging, methodName):
133
+ raise AttributeError('{} already defined in logging module'.format(methodName))
134
+ if hasattr(logging.getLoggerClass(), methodName):
135
+ raise AttributeError('{} already defined in logger class'.format(methodName))
136
+
137
+ # This method was inspired by the answers to Stack Overflow post
138
+ # http://stackoverflow.com/q/2183233/2988730, especially
139
+ # http://stackoverflow.com/a/13638084/2988730
140
+ def logForLevel(self, message, *args, **kwargs):
141
+ if self.isEnabledFor(levelNum):
142
+ self._log(levelNum, message, args, **kwargs)
143
+ def logToRoot(message, *args, **kwargs):
144
+ logging.log(levelNum, message, *args, **kwargs)
145
+
146
+ logging.addLevelName(levelNum, levelName)
147
+ setattr(logging, levelName, levelNum)
148
+ setattr(logging.getLoggerClass(), methodName, logForLevel)
149
+ setattr(logging, methodName, logToRoot)
150
+
151
+
152
+
128
153
 
@@ -63,28 +63,28 @@ class LogManager(object):
63
63
  self.format = '%(asctime)s | %(process)-5d-%(thread)-5d | %(levelname)5s | %(module)35s | %(message)s'
64
64
  self.style = '%'
65
65
 
66
- def initialize(self, log_on_console=True):
66
+ def configure(self):
67
+ self.__config_file_path = LogConfig.config_file_path
68
+
69
+ if self.__config_file_path:
70
+ config = configparser.ConfigParser()
71
+ config.read(self.__config_file_path)
72
+
73
+ if config.has_section("loggers_levels"):
74
+ self.__loggers_levels = config.items(section="loggers_levels")
75
+
76
+ def initialize(self):
67
77
  """
68
78
  Initialize log manager.
69
79
  If log_on_console is True, logs are published on console until a new configuration by calling method set_config
70
80
  """
71
- if log_on_console:
81
+ handlers = []
82
+ if LogConfig.log_on_console:
72
83
  self.on_console = True
73
84
  self.__console_handler = self.__new_console_handler()
74
- logging.basicConfig(format=self.format, style=self.style, level=LogConfig.default_level, handlers=[self.__console_handler])
75
- else:
76
- logging.basicConfig(format=self.format, style=self.style, level=LogConfig.default_level, handlers=[])
77
-
78
- def set_config_file_path(self, file_path, update_default_level=True):
79
- self.__config_file_path = file_path
85
+ handlers.append(self.__console_handler)
80
86
 
81
- config = configparser.ConfigParser()
82
- config.read(self.__config_file_path)
83
- if update_default_level:
84
- LogConfig.default_level = config.get("logger_root", "level")
85
-
86
- if config.has_section("loggers_levels"):
87
- self.__loggers_levels = config.items(section="loggers_levels")
87
+ logging.basicConfig(format=self.format, style=self.style, level=LogConfig.default_level, handlers=handlers)
88
88
 
89
89
  def has_log_file(self, file_name):
90
90
  with self.__files_lock:
@@ -154,8 +154,7 @@ class LogManager(object):
154
154
  # Update log destination to files
155
155
  with self.__files_lock:
156
156
  # Remove old log files
157
- # if self.__root_file_name:
158
- # self.remove_root_file_handler(do_reset=True)
157
+ # Note: root file is not removed if it is configured
159
158
  for file_name in list(self.__file_handlers.keys()):
160
159
  if file_name not in self.__file_names:
161
160
  self.remove_file_handler(file_name, do_remove_log_file=False)
@@ -166,7 +165,6 @@ class LogManager(object):
166
165
  for file_name in self.__file_names:
167
166
  if file_name not in list(self.__file_handlers.keys()):
168
167
  self.add_file_handler(file_name)
169
-
170
168
 
171
169
  # level
172
170
  if logger_.getEffectiveLevel() != LogConfig.default_level:
@@ -176,7 +174,10 @@ class LogManager(object):
176
174
  for name, level in self.__loggers_levels:
177
175
  if not name.startswith("#"):
178
176
  logging.getLogger(name).setLevel(level)
179
-
177
+
178
+ # WARNING: For local debug only
179
+ # logging.getLogger("holado_logging.common.logging.log_manager").setLevel(logging.DEBUG)
180
+
180
181
  def set_level(self, log_level, do_set_config=True):
181
182
  from holado_core.common.exceptions.technical_exception import TechnicalException
182
183
 
@@ -187,7 +187,7 @@ class MultitaskManager(object):
187
187
 
188
188
  def prepare_thread(self, name, update_parent=True):
189
189
  """
190
- Create a process context and return a unique name based to given name
190
+ Create a thread context and return a unique name based to given name
191
191
  """
192
192
  with self.__thread_lock:
193
193
  res = name
@@ -21,6 +21,7 @@ from holado_python.standard_library.typing import Typing
21
21
  from holado.common.handlers.undefined import undefined_argument, default_context
22
22
  from holado_core.common.exceptions.technical_exception import TimeoutTechnicalException
23
23
  from holado_core.common.exceptions.functional_exception import FunctionalException
24
+ from holado_python.common.tools.datetime import DateTime, FORMAT_DATETIME_ISO
24
25
 
25
26
  logger = logging.getLogger(__name__)
26
27
 
@@ -35,7 +36,8 @@ class Thread(threading.Thread):
35
36
  default_wait_timeout = Config.timeout_seconds * 1000
36
37
 
37
38
  self.__name = name
38
- self.__unique_name = SessionContext.instance().multitask_manager.prepare_thread(name)
39
+ # Note: if SessionContext doesn't have an instance (like during session context reset), use name+now as unique name
40
+ self.__unique_name = SessionContext.instance().multitask_manager.prepare_thread(name) if SessionContext.has_instance() else f"{name}_{DateTime.datetime_2_str(DateTime.now(), FORMAT_DATETIME_ISO)}"
39
41
  self.__default_wait_timeout = default_wait_timeout
40
42
  self.__delay_before_run_sec = delay_before_run_sec
41
43
 
@@ -48,7 +50,8 @@ class Thread(threading.Thread):
48
50
  self._is_idle.set()
49
51
 
50
52
  # Register thread
51
- if register_thread:
53
+ # Note: Do not register thread if session context doesn't have an instance (like during session context reset)
54
+ if register_thread and SessionContext.has_instance():
52
55
  # Registered name has to be unique
53
56
  SessionContext.instance().threads_manager.register_thread(self.__unique_name, self, scope=register_scope)
54
57
 
@@ -74,13 +77,14 @@ class Thread(threading.Thread):
74
77
 
75
78
  def _set_ident(self):
76
79
  super()._set_ident()
77
- if not MultitaskManager.has_thread_native_id():
80
+ if not MultitaskManager.has_thread_native_id() and SessionContext.has_instance():
78
81
  SessionContext.instance().multitask_manager.set_thread_uid(self.__unique_name, MultitaskManager.get_thread_uid(thread=self))
79
82
 
80
83
  if MultitaskManager.has_thread_native_id():
81
84
  def _set_native_id(self):
82
85
  super()._set_native_id()
83
- SessionContext.instance().multitask_manager.set_thread_uid(self.__unique_name, MultitaskManager.get_thread_uid(thread=self))
86
+ if SessionContext.has_instance():
87
+ SessionContext.instance().multitask_manager.set_thread_uid(self.__unique_name, MultitaskManager.get_thread_uid(thread=self))
84
88
 
85
89
  def join(self, timeout=undefined_argument, raise_if_still_alive=True):
86
90
  """
@@ -19,7 +19,6 @@ def dependencies():
19
19
 
20
20
  def register():
21
21
  from holado.common.context.session_context import SessionContext
22
- from holado_protobuf.ipc.protobuf.types.google.protobuf import Timestamp
23
22
  from holado_python.common.tools.comparators.datetime_comparator import DatetimeComparator
24
23
  from holado_python.common.tools.datetime import DateTime
25
24
 
@@ -51,6 +50,7 @@ def register():
51
50
 
52
51
  # Register datetime conversion
53
52
 
53
+ from holado_protobuf.ipc.protobuf.types.google.protobuf import Timestamp
54
54
  DatetimeComparator.register_resource_for_type_in_class('protobuf.Timestamp', None,
55
55
  lambda o: isinstance(o, Timestamp.protobuf_class()),
56
56
  lambda o: DateTime.seconds_nanos_to_datetime(o.seconds, o.nanos),