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.
- holado/__init__.py +61 -23
- holado/common/context/service_manager.py +10 -2
- holado/common/context/session_context.py +43 -12
- holado/common/handlers/object.py +12 -4
- holado/holado_config.py +1 -0
- {holado-0.2.3.dist-info → holado-0.2.5.dist-info}/METADATA +1 -1
- {holado-0.2.3.dist-info → holado-0.2.5.dist-info}/RECORD +30 -30
- holado_ais/ais/ais_messages.py +140 -139
- holado_core/common/tools/path_manager.py +8 -4
- holado_grpc/api/rpc/grpc_client.py +122 -118
- holado_helper/docker/logging.conf +3 -1
- holado_helper/docker/run_holado_test_nonreg_in_docker.sh +28 -28
- holado_helper/docker/run_terminal_in_docker-with_docker_control.sh +27 -27
- holado_helper/docker/run_terminal_in_docker.sh +26 -26
- holado_helper/script/initialize_script.py +5 -5
- holado_logging/__init__.py +7 -9
- holado_logging/common/logging/holado_logger.py +2 -2
- holado_logging/common/logging/log_config.py +152 -127
- holado_logging/common/logging/log_manager.py +20 -19
- holado_multitask/multitasking/multitask_manager.py +1 -1
- holado_multitask/multithreading/thread.py +8 -4
- holado_protobuf/__init__.py +1 -1
- holado_protobuf/ipc/protobuf/protobuf_messages.py +821 -818
- holado_rabbitmq/tools/rabbitmq/rabbitmq_client.py +1 -2
- holado_test/behave/independant_runner.py +3 -5
- holado_test/scenario/step_tools.py +2 -0
- test_holado/environment.py +1 -1
- test_holado/logging.conf +3 -1
- {holado-0.2.3.dist-info → holado-0.2.5.dist-info}/WHEEL +0 -0
- {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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if
|
|
62
|
-
cls.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"""
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
logging.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
|
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
|
-
|
|
81
|
+
handlers = []
|
|
82
|
+
if LogConfig.log_on_console:
|
|
72
83
|
self.on_console = True
|
|
73
84
|
self.__console_handler = self.__new_console_handler()
|
|
74
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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.
|
|
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
|
"""
|
holado_protobuf/__init__.py
CHANGED
|
@@ -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),
|