holado 0.7.0__py3-none-any.whl → 0.8.0__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 (36) hide show
  1. holado/common/context/context.py +110 -4
  2. holado/common/context/session_context.py +16 -5
  3. {holado-0.7.0.dist-info → holado-0.8.0.dist-info}/METADATA +4 -3
  4. {holado-0.7.0.dist-info → holado-0.8.0.dist-info}/RECORD +35 -30
  5. holado_context/tests/behave/steps/private/common/context_steps.py +35 -3
  6. holado_core/common/resource/persisted_method_to_call_manager.py +134 -27
  7. holado_core/common/tools/path_manager.py +47 -26
  8. holado_docker/tests/behave/steps/tools/docker_controller/client_steps.py +12 -9
  9. holado_docker/tools/docker_controller/client/rest/docker_controller_client.py +53 -5
  10. holado_docker/tools/docker_controller/server/rest/api/config.py +49 -0
  11. holado_docker/tools/docker_controller/server/rest/api/container.py +5 -5
  12. holado_docker/tools/docker_controller/server/rest/api/os.py +41 -0
  13. holado_docker/tools/docker_controller/server/rest/openapi.yaml +94 -0
  14. holado_docker/tools/docker_controller/server/run_docker_controller_in_docker.sh +2 -1
  15. holado_helper/docker/run_holado_test_nonreg_in_docker.sh +1 -1
  16. holado_helper/docker/run_terminal_in_docker.sh +1 -1
  17. holado_json/tests/behave/steps/ipc/json_steps.py +11 -0
  18. holado_python/common/iterables.py +8 -0
  19. holado_python/standard_library/ssl/resources/certificates/tcpbin.crt +16 -16
  20. holado_python/standard_library/ssl/resources/certificates/tcpbin.key +26 -26
  21. holado_rabbitmq/tools/rabbitmq/rabbitmq_client.py +0 -2
  22. holado_rest/api/rest/rest_client.py +7 -11
  23. holado_system/tests/behave/steps/system/file_steps.py +14 -3
  24. holado_test/common/context/scenario_context.py +3 -64
  25. holado_yaml/tests/behave/steps/yaml_steps.py +106 -9
  26. holado_yaml/yaml/enums.py +28 -0
  27. holado_yaml/yaml/pyyaml/pyyaml_client.py +72 -0
  28. holado_yaml/yaml/ruamel/ruamel_yaml_client.py +80 -0
  29. holado_yaml/yaml/yaml_client.py +195 -0
  30. holado_yaml/yaml/yaml_manager.py +57 -49
  31. test_holado/features/NonReg/holado_yaml/yaml.feature +304 -8
  32. test_holado/features/NonReg/scenario/scenario.feature +48 -4
  33. test_holado/logging.conf +1 -0
  34. holado_helper/docker/run_terminal_in_docker-with_docker_control.sh +0 -103
  35. {holado-0.7.0.dist-info → holado-0.8.0.dist-info}/WHEEL +0 -0
  36. {holado-0.7.0.dist-info → holado-0.8.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,72 @@
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
+ from holado_core.common.tools.tools import Tools
16
+ from holado_yaml.yaml.yaml_client import YAMLClient
17
+ from holado_core.common.exceptions.technical_exception import TechnicalException
18
+
19
+
20
+ logger = logging.getLogger(__name__)
21
+
22
+ try:
23
+ import yaml # @UnresolvedImport
24
+ with_yaml = True
25
+ except Exception as exc:
26
+ if Tools.do_log(logger, logging.DEBUG):
27
+ logger.debug(f"YAML is not available with pyyaml. Initialization failed on error: {exc}")
28
+ with_yaml = False
29
+
30
+
31
+
32
+ class PyYAMLClient(YAMLClient):
33
+ """
34
+ Client for actions on YAML files.
35
+ """
36
+
37
+ @classmethod
38
+ def is_available(cls):
39
+ return with_yaml
40
+
41
+ def __init__(self, name=None, client_type=None):
42
+ super().__init__(name)
43
+
44
+ if client_type == "base":
45
+ self.__loader_type = yaml.BaseLoader
46
+ self.__dumper_type = yaml.BaseDumper
47
+ elif client_type == "full":
48
+ self.__loader_type = yaml.FullLoader
49
+ self.__dumper_type = yaml.Dumper
50
+ elif client_type == "safe" or client_type is None:
51
+ self.__loader_type = yaml.SafeLoader
52
+ self.__dumper_type = yaml.SafeDumper
53
+ elif client_type == "unsafe":
54
+ self.__loader_type = yaml.UnsafeLoader
55
+ self.__dumper_type = yaml.Dumper
56
+ else:
57
+ raise TechnicalException(f"Unmanaged client type '{client_type}'")
58
+
59
+ def load_io_file(self, file_like_object):
60
+ return yaml.load(file_like_object, self.__loader_type)
61
+
62
+ def load_multiple_documents_io_file(self, file_like_object):
63
+ return list(yaml.load_all(file_like_object, self.__loader_type))
64
+
65
+ def save_in_io_file(self, file_like_object, data, **kwargs):
66
+ if 'sort_keys' not in kwargs:
67
+ kwargs['sort_keys'] = False
68
+ yaml.dump(data, file_like_object, **kwargs)
69
+
70
+
71
+
72
+
@@ -0,0 +1,80 @@
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
+ from holado_core.common.tools.tools import Tools
16
+ from holado_yaml.yaml.yaml_client import YAMLClient
17
+
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+ try:
22
+ import ruamel.yaml # @UnresolvedImport
23
+ with_ruamel_yaml = True
24
+ except Exception as exc:
25
+ if Tools.do_log(logger, logging.DEBUG):
26
+ logger.debug(f"YAML is not available with ruamel.yaml. Initialization failed on error: {exc}")
27
+ with_ruamel_yaml = False
28
+
29
+
30
+
31
+ class RuamelYAMLClient(YAMLClient):
32
+ """
33
+ Client for actions on YAML files.
34
+ """
35
+
36
+ @classmethod
37
+ def is_available(cls):
38
+ return with_ruamel_yaml
39
+
40
+ def __init__(self, name=None, client_type=None, **kwargs):
41
+ super().__init__(name)
42
+
43
+ if client_type is None:
44
+ client_type = kwargs.get('typ')
45
+ self.__internal_client = ruamel.yaml.YAML(typ=client_type, **kwargs)
46
+
47
+ @property
48
+ def internal_client(self):
49
+ return self.__internal_client
50
+
51
+ def load_io_file(self, file_like_object):
52
+ res = self.internal_client.load(file_like_object)
53
+ self._rm_style_info(res)
54
+ return res
55
+
56
+ def load_multiple_documents_io_file(self, file_like_object):
57
+ res = list(self.internal_client.load_all(file_like_object))
58
+ self._rm_style_info(res)
59
+ return res
60
+
61
+ def save_in_io_file(self, file_like_object, data, **kwargs):
62
+ self.internal_client.dump(data, file_like_object, **kwargs)
63
+
64
+ def _rm_style_info(self, d):
65
+ """Remove style info so that fields order can be preserved if saved again.
66
+ """
67
+ if isinstance(d, dict):
68
+ if hasattr(d, 'fa'):
69
+ d.fa._flow_style = None
70
+ for k, v in d.items():
71
+ self._rm_style_info(k)
72
+ self._rm_style_info(v)
73
+ elif isinstance(d, list):
74
+ if hasattr(d, 'fa'):
75
+ d.fa._flow_style = None
76
+ for elem in d:
77
+ self._rm_style_info(elem)
78
+
79
+
80
+
@@ -0,0 +1,195 @@
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
+ from holado.common.context.session_context import SessionContext
16
+ from holado.common.handlers.object import Object
17
+ import abc
18
+ from holado_core.common.exceptions.technical_exception import TechnicalException
19
+ from holado_python.standard_library.typing import Typing
20
+ from holado_yaml.yaml.enums import UpdateType
21
+ import os
22
+ from holado_python.common.iterables import remove_all
23
+ from holado.common.handlers.undefined import not_applicable, undefined_value
24
+ from io import StringIO
25
+ from holado_core.common.tools.tools import Tools
26
+
27
+
28
+ logger = logging.getLogger(__name__)
29
+
30
+
31
+ class YAMLClient(Object):
32
+ """
33
+ Client for actions on YAML files.
34
+ """
35
+ __metaclass__ = abc.ABCMeta
36
+
37
+ @classmethod
38
+ def _get_path_manager(cls):
39
+ return SessionContext.instance().path_manager
40
+
41
+ def __init__(self, name=None):
42
+ super().__init__(name)
43
+
44
+ def load_file(self, file_path):
45
+ with open(file_path, 'r') as file:
46
+ res = self.load_io_file(file)
47
+
48
+ if Tools.do_log(logger, logging.DEBUG):
49
+ logger.debug(f"Load YAML file '{file_path}' => [{Typing.get_object_class_fullname(res)}] {res}")
50
+ return res
51
+
52
+ def load_string(self, text):
53
+ with StringIO(text) as file:
54
+ res = self.load_io_file(file)
55
+
56
+ if Tools.do_log(logger, logging.DEBUG):
57
+ logger.debug(f"Load YAML string [{text}] => [{Typing.get_object_class_fullname(res)}] {res}")
58
+ return res
59
+
60
+ def load_io_file(self, file_like_object):
61
+ raise NotImplementedError()
62
+
63
+ def load_multiple_documents_file(self, file_path):
64
+ with open(file_path, 'r') as file:
65
+ res = self.load_multiple_documents_io_file(file)
66
+ return res
67
+
68
+ def load_multiple_documents_string(self, text):
69
+ with StringIO(text) as file:
70
+ res = self.load_multiple_documents_io_file(file)
71
+ return res
72
+
73
+ def load_multiple_documents_io_file(self, file_like_object):
74
+ raise NotImplementedError()
75
+
76
+ def save_in_file(self, file_path, data, mode=None, user=None, group=None, **kwargs):
77
+ self._get_path_manager().makefile(file_path, mode=mode, user=user, group=group)
78
+
79
+ with open(file_path, 'w') as file:
80
+ self.save_in_io_file(file, data, **kwargs)
81
+
82
+ def save_in_string(self, data, **kwargs):
83
+ with StringIO() as file:
84
+ self.save_in_io_file(file, data, **kwargs)
85
+ res = file.getvalue()
86
+ return res
87
+
88
+ def save_in_io_file(self, file_like_object, data, **kwargs):
89
+ raise NotImplementedError()
90
+
91
+ def update_file(self, file_path, data, update_type=UpdateType.AddOrUpdate, with_backup=True, backup_extension='.bak', mode=None, user=None, group=None, **kwargs):
92
+ # If file doesn't exist, create an empty file
93
+ self._get_path_manager().makefile(file_path, mode=mode, user=user, group=group)
94
+
95
+ # Manage backup
96
+ # Note: It is done after potential empty file creation, so that restore will leave the file empty or remove it
97
+ if with_backup:
98
+ if backup_extension is None:
99
+ backup_extension = '.bak'
100
+ backup_path = file_path + backup_extension
101
+ if not self._get_path_manager().check_file_exists(backup_path, raise_exception=False):
102
+ self._get_path_manager().copy_path_recursively(file_path, backup_path, user=user, group=group)
103
+ self._get_path_manager().check_file_exists(backup_path, raise_exception=True)
104
+
105
+ # Update file
106
+ dst_data = self.load_file(file_path)
107
+ self.update_data(dst_data, data, update_type)
108
+ self.save_in_file(file_path, dst_data, **kwargs) # Note: as file already exists, it is not needed to pass parameters mode, user and group
109
+
110
+ def update_string(self, text, data, update_type=UpdateType.AddOrUpdate, **kwargs):
111
+ dst_data = self.load_string(text)
112
+ self.update_data(dst_data, data, update_type)
113
+ res = self.save_in_string(dst_data, **kwargs)
114
+ return res
115
+
116
+ def update_data(self, dst, src, update_type=UpdateType.AddOrUpdate):
117
+ if isinstance(src, str):
118
+ src = self.load_string(src)
119
+
120
+ self._update_data_object(dst, src, update_type)
121
+
122
+ def _update_data_object(self, dst, src, update_type=UpdateType.AddOrUpdate):
123
+ if isinstance(src, dict):
124
+ self._update_data_dict(dst, src, update_type)
125
+ elif isinstance(src, list):
126
+ self._update_data_list(dst, src, update_type)
127
+ else:
128
+ raise TechnicalException(f"Unmanaged update of object of type {Typing.get_object_class_fullname(dst)} with data of type {Typing.get_object_class_fullname(src)}")
129
+
130
+ def _update_data_dict(self, dst, src, update_type=UpdateType.AddOrUpdate):
131
+ if update_type == UpdateType.AddOrUpdate:
132
+ for key, value in src.items():
133
+ if key not in dst or not (isinstance(value, dict) or isinstance(value, list)):
134
+ dst[key] = value
135
+ else:
136
+ self._update_data_object(dst[key], value, update_type)
137
+ elif update_type == UpdateType.Delete:
138
+ for key, value in src.items():
139
+ if key in dst:
140
+ if isinstance(value, dict) or isinstance(value, list):
141
+ self._update_data_object(dst[key], value, update_type)
142
+ if not dst[key]:
143
+ del dst[key]
144
+ else:
145
+ del dst[key]
146
+ elif update_type == UpdateType.Replace:
147
+ for key, value in src.items():
148
+ if key in dst and isinstance(value, dict):
149
+ has_inner_dict = any(map(lambda x:isinstance(x, dict), value.values()))
150
+ if has_inner_dict:
151
+ self._update_data_object(dst[key], value, update_type)
152
+ else:
153
+ dst[key] = value
154
+ else:
155
+ dst[key] = value
156
+ else:
157
+ raise TechnicalException(f"Unamanged update type {update_type}")
158
+
159
+ def _update_data_list(self, dst, src, update_type=UpdateType.AddOrUpdate):
160
+ if update_type == UpdateType.AddOrUpdate:
161
+ for value in src:
162
+ dst.append(value)
163
+ elif update_type == UpdateType.Delete:
164
+ for value in src:
165
+ remove_all(dst, value)
166
+ elif update_type == UpdateType.Replace:
167
+ for index, value in enumerate(src):
168
+ if value is not_applicable:
169
+ continue
170
+ if index < len(dst):
171
+ if isinstance(value, dict) or isinstance(value, list):
172
+ self._update_data_object(dst[index], value, update_type)
173
+ else:
174
+ dst[index] = value
175
+ else:
176
+ while len(dst) < index:
177
+ dst.append(undefined_value)
178
+ dst.append(value)
179
+ else:
180
+ raise TechnicalException(f"Unamanged update type {update_type}")
181
+
182
+ def restore_file(self, file_path, backup_extension='.bak', remove_empty_file=False):
183
+ if backup_extension is None:
184
+ backup_extension = '.bak'
185
+ backup_path = file_path + backup_extension
186
+ if self._get_path_manager().check_file_exists(backup_path, raise_exception=False):
187
+ # Replace file by backup
188
+ self._get_path_manager().rename(backup_path, file_path, raise_if_exists=False)
189
+
190
+ # Manage remove of empty file
191
+ if remove_empty_file and os.path.getsize(file_path) == 0:
192
+ self._get_path_manager().remove_path(file_path)
193
+
194
+
195
+
@@ -12,21 +12,14 @@
12
12
  #################################################
13
13
 
14
14
  import logging
15
- from holado_core.common.tools.tools import Tools
16
- from holado.common.context.session_context import SessionContext
17
- from holado_core.common.exceptions.functional_exception import FunctionalException
18
- from yaml.loader import BaseLoader, FullLoader, SafeLoader
15
+ from holado_yaml.yaml.ruamel.ruamel_yaml_client import RuamelYAMLClient
16
+ from holado_yaml.yaml.pyyaml.pyyaml_client import PyYAMLClient
17
+ from holado_core.common.exceptions.technical_exception import TechnicalException
18
+ from holado_yaml.yaml.enums import UpdateType
19
19
 
20
20
 
21
21
  logger = logging.getLogger(__name__)
22
22
 
23
- try:
24
- import yaml
25
- with_yaml = True
26
- except Exception as exc:
27
- if Tools.do_log(logger, logging.DEBUG):
28
- logger.debug(f"YAML is not available. Initialization failed on error: {exc}")
29
- with_yaml = False
30
23
 
31
24
 
32
25
  class YAMLManager(object):
@@ -36,51 +29,66 @@ class YAMLManager(object):
36
29
 
37
30
  @classmethod
38
31
  def is_available(cls):
39
- return with_yaml
32
+ return RuamelYAMLClient.is_available() or PyYAMLClient.is_available()
40
33
 
41
34
  @classmethod
42
- def __get_path_manager(cls):
43
- return SessionContext.instance().path_manager
35
+ def get_client(cls, client_type, **kwargs):
36
+ if RuamelYAMLClient.is_available():
37
+ return RuamelYAMLClient(client_type=client_type)
38
+ elif PyYAMLClient.is_available():
39
+ return PyYAMLClient(client_type=client_type)
40
+ else:
41
+ raise TechnicalException("Missing dependencies")
42
+
43
+
44
+ # Manage YAML files
44
45
 
45
46
  @classmethod
46
- def load_file(cls, file_path, with_only_strings=False, with_full_yaml_features=False):
47
- if with_only_strings and with_full_yaml_features:
48
- raise FunctionalException(f"It is not possible to set both with_only_strings and with_full_yaml_features to True")
49
-
50
- if with_only_strings:
51
- loader = BaseLoader
52
- elif with_full_yaml_features:
53
- loader = FullLoader
54
- else:
55
- loader = SafeLoader
56
-
57
- with open(file_path, 'r') as file:
58
- res = yaml.load(file, Loader=loader)
59
-
60
- return res
47
+ def load_file(cls, file_path, client_type=None, client=None):
48
+ client = client if client is not None else cls.get_client(client_type)
49
+ return client.load_file(file_path)
61
50
 
62
51
  @classmethod
63
- def load_multiple_documents_file(cls, file_path, with_only_strings=False, with_full_yaml_features=False):
64
- if with_only_strings and with_full_yaml_features:
65
- raise FunctionalException(f"It is not possible to set both with_only_strings and with_full_yaml_features to True")
66
-
67
- if with_only_strings:
68
- loader = BaseLoader
69
- elif with_full_yaml_features:
70
- loader = FullLoader
71
- else:
72
- loader = SafeLoader
73
-
74
- with open(file_path, 'r') as file:
75
- res = list(yaml.load_all(file, Loader=loader))
76
-
77
- return res
52
+ def load_multiple_documents_file(cls, file_path, client_type=None, client=None):
53
+ client = client if client is not None else cls.get_client(client_type)
54
+ return client.load_multiple_documents_file(file_path)
78
55
 
79
56
  @classmethod
80
- def save_file(cls, data, file_path):
81
- cls.__get_path_manager().makedirs(file_path)
82
- with open(file_path, 'w') as file:
83
- yaml.dump(data, file)
84
-
57
+ def save_in_file(cls, file_path, data, client_type=None, client=None):
58
+ client = client if client is not None else cls.get_client(client_type)
59
+ client.save_in_file(file_path, data)
60
+
61
+ @classmethod
62
+ def update_file(cls, file_path, data, update_type=UpdateType.AddOrUpdate, client_type=None, client=None, with_backup=True, backup_extension='.bak'):
63
+ client = client if client is not None else cls.get_client(client_type)
64
+ client.update_file(file_path, data, update_type, with_backup, backup_extension)
65
+
66
+ @classmethod
67
+ def restore_file(cls, file_path, client_type=None, client=None, backup_extension='.bak'):
68
+ client = client if client is not None else cls.get_client(client_type)
69
+ client.restore_file(file_path, backup_extension)
70
+
71
+
72
+ # Manage YAML strings
73
+
74
+ @classmethod
75
+ def load_string(cls, text, client_type=None, client=None):
76
+ client = client if client is not None else cls.get_client(client_type)
77
+ return client.load_string(text)
78
+
79
+ @classmethod
80
+ def load_multiple_documents_string(cls, text, client_type=None, client=None):
81
+ client = client if client is not None else cls.get_client(client_type)
82
+ return client.load_multiple_documents_string(text)
83
+
84
+ @classmethod
85
+ def save_in_string(cls, data, client_type=None, client=None):
86
+ client = client if client is not None else cls.get_client(client_type)
87
+ return client.save_in_string(data)
88
+
89
+ @classmethod
90
+ def update_string(cls, text, data, update_type=UpdateType.AddOrUpdate, client_type=None, client=None):
91
+ client = client if client is not None else cls.get_client(client_type)
92
+ return client.update_string(text, data, update_type)
85
93
 
86
94