atomicshop 2.10.3__py3-none-any.whl → 2.10.4__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 atomicshop might be problematic. Click here for more details.

atomicshop/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  """Atomic Basic functions and classes to make developer life easier"""
2
2
 
3
3
  __author__ = "Den Kras"
4
- __version__ = '2.10.3'
4
+ __version__ = '2.10.4'
@@ -23,14 +23,19 @@ def find_highest_number(numbers: list[float, int, str]):
23
23
  return max(numbers)
24
24
 
25
25
 
26
- def convert_bytes_to_readable(byte_size: Union[int, float]):
26
+ def convert_bytes_to_readable(
27
+ byte_size: Union[int, float],
28
+ return_formatted_string=False
29
+ ) -> Union[tuple[Union[int, float], str], str]:
27
30
  """
28
31
  Convert bytes to a more readable format (KB, MB, GB, etc.) with two numbers after the decimal point.
29
32
 
30
33
  :param byte_size: Size in bytes
31
34
  :type byte_size: int or float
32
- :return: A string representing the size in a readable format
33
- :rtype: str
35
+ :param return_formatted_string: If True, return the formatted string,
36
+ otherwise return the size and suffix separately in a tuple.
37
+ :type return_formatted_string: bool
38
+ :return: tuple of integer or float and suffix string - representing the size in a readable format
34
39
  """
35
40
  # Define the suffixes for each unit of measurement
36
41
  suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
@@ -44,5 +49,9 @@ def convert_bytes_to_readable(byte_size: Union[int, float]):
44
49
  i += 1
45
50
 
46
51
  # Format the result to include two digits after the decimal point
47
- readable_format = "{:.2f} {}".format(byte_size, suffixes[i])
48
- return readable_format
52
+ if return_formatted_string:
53
+ readable_format: str = "{:.2f} {}".format(byte_size, suffixes[i])
54
+ return readable_format
55
+ else:
56
+ return byte_size, suffixes[i]
57
+
@@ -1,6 +1,7 @@
1
1
  DEFAULT_ELASTIC_PORT: str = '9200'
2
2
  DEFAULT_ELASTIC_HOST: str = 'localhost'
3
3
  DEFAULT_ELASTIC_URL: str = f"http://{DEFAULT_ELASTIC_HOST}:{DEFAULT_ELASTIC_PORT}"
4
+ DEFAULT_ELASTIC_URL_JVM_OPTIONS: str = f"{DEFAULT_ELASTIC_URL}/_nodes?filter_path=**.jvm&pretty"
4
5
 
5
6
  DEFAULT_KIBANA_PORT: str = '5601'
6
7
  DEFAULT_KIBANA_HOST: str = 'localhost'
@@ -12,7 +13,7 @@ ELASTIC_CONFIG_FILE: str = f"{ELASTIC_SEARCH_CONFIG_DIRECTORY}/elasticsearch.yml
12
13
  XPACK_SECURITY_SETTING_NAME: str = "xpack.security.enabled"
13
14
 
14
15
  ELASTIC_JVM_OPTIONS_DIRECTORY: str = f"{ELASTIC_SEARCH_CONFIG_DIRECTORY}/jvm.options.d"
15
- ELASTIC_JVM_OPTIONS_CUSTOM_FILE: str = f"{ELASTIC_JVM_OPTIONS_DIRECTORY}/custom.options"
16
+ ELASTIC_JVM_OPTIONS_4GB_CUSTOM_FILE: str = f"{ELASTIC_JVM_OPTIONS_DIRECTORY}/4gb_memory_heap.options"
16
17
  ELASTIC_JVM_OPTIONS_4GB_MEMORY_USAGE: list[str] = ['-Xms4g', '-Xmx4g']
17
18
 
18
19
  UBUNTU_DEPENDENCY_PACKAGES: list[str] = ['apt-transport-https', 'openjdk-11-jdk', 'wget']
@@ -170,29 +170,35 @@ def modify_xpack_security_setting(
170
170
  print_api(f"The setting is already set to [{setting}].")
171
171
 
172
172
 
173
- def create_jvm_options_custom_file(file_path: str = None, options: list = None):
173
+ def create_jvm_options_custom_file(file_path: str, options: list):
174
174
  """
175
175
  The function creates a custom JVM options file for Elasticsearch.
176
- The default file path is 'config_basic.ELASTIC_JVM_OPTIONS_CUSTOM_FILE'.
177
- The default options are 'config_basic.ELASTIC_JVM_OPTIONS_4GB_MEMORY_USAGE'.
178
- The 4GB memory usage options are needed for the Elasticsearch to work properly and not to crash.
176
+ You can use the default directory path as 'config_basic.ELASTIC_JVM_OPTIONS_DIRECTORY'.
179
177
  :param file_path: str, the path to the custom JVM options file.
180
178
  :param options: list, the list of JVM options.
181
179
  :return:
182
180
  """
183
181
 
184
- if not file_path:
185
- file_path = config_basic.ELASTIC_JVM_OPTIONS_CUSTOM_FILE
186
-
187
- if not options:
188
- options = config_basic.ELASTIC_JVM_OPTIONS_4GB_MEMORY_USAGE
189
-
190
182
  # Write the options to the file.
191
183
  with open(file_path, 'w') as file:
192
184
  for option in options:
193
185
  file.write(f"{option}\n")
194
186
 
195
187
 
188
+ def create_jvm_options_custom_4gb_memory_heap_file(file_path: str = None):
189
+ """
190
+ The function creates a custom JVM options file with 4GB memory heap usage.
191
+ The 4GB memory usage options are needed for the Elasticsearch to work properly and not to crash.
192
+ :param file_path: str, the path to the custom JVM options file.
193
+ :return:
194
+ """
195
+
196
+ if not file_path:
197
+ file_path = config_basic.ELASTIC_JVM_OPTIONS_4GB_CUSTOM_FILE
198
+
199
+ create_jvm_options_custom_file(file_path, config_basic.ELASTIC_JVM_OPTIONS_4GB_MEMORY_USAGE)
200
+
201
+
196
202
  def is_server_available(
197
203
  max_attempts: int = 5,
198
204
  wait_between_attempts_seconds: float = 10,
@@ -234,3 +240,25 @@ def is_server_available(
234
240
 
235
241
  print_api("Elasticsearch did not start within the expected time.", color='red', **print_kwargs)
236
242
  return False
243
+
244
+
245
+ def is_4gb_memory_heap_options_applied_on_server() -> bool:
246
+ """
247
+ The function checks if the 4GB memory heap options are applied on the Elasticsearch server.
248
+ :return: bool.
249
+ """
250
+
251
+ # Send a GET request
252
+ response = requests.get(config_basic.DEFAULT_ELASTIC_URL_JVM_OPTIONS)
253
+ response.raise_for_status() # Raise an exception for HTTP errors
254
+
255
+ # Load JSON data from the response
256
+ jvm_data = response.json()
257
+
258
+ # Check if memory heap options are applied in 'input_arguments' key.
259
+ for node in jvm_data['nodes'].values():
260
+ # Get the JVM input arguments values.
261
+ input_arguments = node['jvm']['input_arguments']
262
+
263
+ # Check that the 4GB memory heap options are applied.
264
+ return all(options in input_arguments for options in config_basic.ELASTIC_JVM_OPTIONS_4GB_MEMORY_USAGE)
@@ -216,10 +216,7 @@ def install_elastic_kibana_ubuntu(install_elastic: bool = True, install_kibana:
216
216
  infrastructure.start_elastic_and_check_service_availability()
217
217
 
218
218
  print_api("Creating custom JVM options file with 4GB memory usage.")
219
- infrastructure.create_jvm_options_custom_file(
220
- file_path=config_basic.ELASTIC_JVM_OPTIONS_CUSTOM_FILE,
221
- options=config_basic.ELASTIC_JVM_OPTIONS_4GB_MEMORY_USAGE
222
- )
219
+ infrastructure.create_jvm_options_custom_4gb_memory_heap_file()
223
220
 
224
221
  if install_kibana:
225
222
  # Install Kibana.
@@ -68,7 +68,7 @@ def install_before_restart(
68
68
  archive_path=fact_source_archive_path, extract_directory=installation_directory,
69
69
  remove_first_directory=True, **(print_kwargs or {}))
70
70
 
71
- # Set the executable permission on the pre-install file.
71
+ # Set the executable permission on the pre-installation file.
72
72
  permissions.set_executable_permission(fact_core_pre_install_file_path)
73
73
 
74
74
  # Run the shell script
@@ -1,5 +1,7 @@
1
1
  import psutil
2
2
 
3
+ from ...basics import numbers
4
+
3
5
 
4
6
  def get_memory_usage():
5
7
  """
@@ -7,3 +9,17 @@ def get_memory_usage():
7
9
  :return: float
8
10
  """
9
11
  return psutil.virtual_memory().percent
12
+
13
+
14
+ def get_total_ram(convert_size_to_readable=False) -> tuple[int, str]:
15
+ """
16
+ Get total physical memory in bytes.
17
+ :return:
18
+ """
19
+
20
+ memory_size: int = psutil.virtual_memory().total
21
+
22
+ if convert_size_to_readable:
23
+ return numbers.convert_bytes_to_readable(memory_size)
24
+
25
+ return memory_size, 'B'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atomicshop
3
- Version: 2.10.3
3
+ Version: 2.10.4
4
4
  Summary: Atomic functions and classes to make developer life easier
5
5
  Author: Denis Kras
6
6
  License: MIT License
@@ -1,4 +1,4 @@
1
- atomicshop/__init__.py,sha256=CAdy7uaKf071UFjU2KsMKAsd6EzULOhS7j2IOVneT_A,123
1
+ atomicshop/__init__.py,sha256=jiF6fRhuPCS2l3bXIdgVnGCUG5xcjtXdqlhFtq2zNTI,123
2
2
  atomicshop/_basics_temp.py,sha256=6cu2dd6r2dLrd1BRNcVDKTHlsHs_26Gpw8QS6v32lQ0,3699
3
3
  atomicshop/_create_pdf_demo.py,sha256=Yi-PGZuMg0RKvQmLqVeLIZYadqEZwUm-4A9JxBl_vYA,3713
4
4
  atomicshop/_patch_import.py,sha256=ENp55sKVJ0e6-4lBvZnpz9PQCt3Otbur7F6aXDlyje4,6334
@@ -88,7 +88,7 @@ atomicshop/basics/isinstancing.py,sha256=fQ35xfqbguQz2BUn-3a4KVGskhTcIn8JjRtxV2r
88
88
  atomicshop/basics/list_of_dicts.py,sha256=EeUh5FwUSmjQ7_Df7yTBgwHsou5jx3tP2a0dzgs8-fk,5773
89
89
  atomicshop/basics/lists.py,sha256=pLpYPSu0BjJIAe_Ar55XhLsH2YBhftn7b-tTAdkK1sw,3928
90
90
  atomicshop/basics/multiprocesses.py,sha256=AczaI4TmYduNjE6_VEQhxvDQn4VLDdXYRxhPDpjH4T0,17974
91
- atomicshop/basics/numbers.py,sha256=j0f4glCtyIypEdCKv145F1gkzEEoZ2GdsGO-OM4BN7o,1439
91
+ atomicshop/basics/numbers.py,sha256=EDmt4M72hVE3IUqximSsrxM7HW64QQFCaGP5_fZuLPo,1839
92
92
  atomicshop/basics/randoms.py,sha256=DmYLtnIhDK29tAQrGP1Nt-A-v8WC7WIEB8Edi-nk3N4,282
93
93
  atomicshop/basics/strings.py,sha256=aQ92AJPvb3U0O6n2FMqRUqEsPCiklwGX--jPmB9M0_s,15418
94
94
  atomicshop/basics/threads.py,sha256=xvgdDJdmgN0wmmARoZ-H7Kvl1GOcEbvgaeGL4M3Hcx8,2819
@@ -157,10 +157,10 @@ atomicshop/wrappers/dockerw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
157
157
  atomicshop/wrappers/dockerw/dockerw.py,sha256=w8zSJr5C7cbvbuG09ORCpAe0BOcibqqL_Z2EKEBHYK4,6266
158
158
  atomicshop/wrappers/dockerw/install_docker.py,sha256=eF0raR1EO9Xk1MVH7CvtkFI2Fgu9zL12MIYV_1vPTQk,4799
159
159
  atomicshop/wrappers/elasticsearchw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
160
- atomicshop/wrappers/elasticsearchw/config_basic.py,sha256=q9Ybr8TTeNPy6FxtiYCln8WNuwOQjdPazTRoGl7Lk8w,1066
160
+ atomicshop/wrappers/elasticsearchw/config_basic.py,sha256=fDujtrjEjbWiYh_WQ3OcYp_8mXhXPYeKLy4wSPL5qM0,1177
161
161
  atomicshop/wrappers/elasticsearchw/elasticsearchw.py,sha256=7TqFdEFznO8NlligJhEKk1vm641ALpCYdaRl1uoXdzM,9768
162
- atomicshop/wrappers/elasticsearchw/infrastructure.py,sha256=Sy15gLVe_LAk9WpAoFxu5YApecFlYeJzzJ8lk5NYQEw,9217
163
- atomicshop/wrappers/elasticsearchw/install_elastic.py,sha256=5CNgIoPIDnTCk5kU7Zcyb48TP4JScvUzeZmhcWt63sI,8754
162
+ atomicshop/wrappers/elasticsearchw/infrastructure.py,sha256=aQZpPNN6mcBR5K5iOX-pLV3GJJhmkj5IqbTwkzKKSYE,10261
163
+ atomicshop/wrappers/elasticsearchw/install_elastic.py,sha256=IhbapWeq5am-MtmnvKBNBPzvaL338rvfG0rbSpl8azE,8620
164
164
  atomicshop/wrappers/elasticsearchw/queries/__init__.py,sha256=KBjT-bAt75CJsx1Apko9mpuFU4pfZV8DcGWQvpX65RU,78
165
165
  atomicshop/wrappers/elasticsearchw/queries/aggregation.py,sha256=N9a5yMMnb10sMa_x1qJBFQpgyJ49UWo8_vxuqmUtZ1A,1742
166
166
  atomicshop/wrappers/elasticsearchw/queries/info.py,sha256=P_VhhBo8MvRI4Shi-bh4RsYtlYNRKRBzScXPC64Up_Q,2900
@@ -178,7 +178,7 @@ atomicshop/wrappers/factw/fact_extractor/docker_image.py,sha256=jJAoJNQ4aoATjn3x
178
178
  atomicshop/wrappers/factw/fact_extractor/get_extractor.py,sha256=2mfOAftHIlCcGt1s7MWdq7DsDCuI6wX3MtvcEZ4SK-0,756
179
179
  atomicshop/wrappers/factw/install/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
180
180
  atomicshop/wrappers/factw/install/install_after_restart.py,sha256=roM1W2hkDynpEKda55xd7AsZxodsFj8i4wmFGt_HHzA,1558
181
- atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py,sha256=fAH53sJgWoXOOhjeAmME2SHYm-5YQAgEi1neaok82Lk,4246
181
+ atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py,sha256=7Yk1xZXFXoPZVsSvgZzOLMoZza9OFIB5HplLQxY-7Bs,4251
182
182
  atomicshop/wrappers/factw/postgresql/__init__.py,sha256=xMBn2d3Exo23IPP2F_9-SXmOlhFbwWDgS9KwozSTjA0,162
183
183
  atomicshop/wrappers/factw/postgresql/analysis.py,sha256=2Rxzy2jyq3zEKIo53z8VkjuslKE_i5mq2ZpmJAvyd6U,716
184
184
  atomicshop/wrappers/factw/postgresql/file_object.py,sha256=VRiCXnsd6yDbnsE-TEKYPC-gkAgFVkE6rygRrJLQShI,713
@@ -213,7 +213,7 @@ atomicshop/wrappers/playwrightw/scenarios.py,sha256=Wz7aVYfG7K4fuSe_TUAc1jhFXVq5
213
213
  atomicshop/wrappers/playwrightw/waits.py,sha256=308fdOu6YDqQ7K7xywj7R27sSmFanPBQqpZyBC-NFmo,7015
214
214
  atomicshop/wrappers/psutilw/cpus.py,sha256=w6LPBMINqS-T_X8vzdYkLS2Wzuve28Ydp_GafTCngrc,236
215
215
  atomicshop/wrappers/psutilw/disks.py,sha256=3ZSVoommKH1TWo37j_83frB-NqXF4Nf5q5mBCX8G4jE,9221
216
- atomicshop/wrappers/psutilw/memories.py,sha256=wpdKEkQ9Wty_r7ZJKkfli7wIHMXdQOMlmDlzmc_0FWo,161
216
+ atomicshop/wrappers/psutilw/memories.py,sha256=_S0aL8iaoIHebd1vOFrY_T9aROM5Jx2D5CvDh_4j0Vc,528
217
217
  atomicshop/wrappers/psutilw/psutilw.py,sha256=G22ZQfGnqX15-feD8KUXfEZO4pFkIEnB8zgPzJ2jc7M,20868
218
218
  atomicshop/wrappers/psycopgw/psycopgw.py,sha256=XJvVf0oAUjCHkrYfKeFuGCpfn0Oxj3u4SbKMKA1508E,7118
219
219
  atomicshop/wrappers/pywin32w/wmi_win32process.py,sha256=qMzXtJ5hBZ5ydAyqpDbSx0nO2RJQL95HdmV5SzNKMhk,6826
@@ -233,8 +233,8 @@ atomicshop/wrappers/socketw/socket_server_tester.py,sha256=AhpurHJmP2kgzHaUbq5ey
233
233
  atomicshop/wrappers/socketw/socket_wrapper.py,sha256=aXBwlEIJhFT0-c4i8iNlFx2It9VpCEpsv--5Oqcpxao,11624
234
234
  atomicshop/wrappers/socketw/ssl_base.py,sha256=k4V3gwkbq10MvOH4btU4onLX2GNOsSfUAdcHmL1rpVE,2274
235
235
  atomicshop/wrappers/socketw/statistics_csv.py,sha256=t3dtDEfN47CfYVi0CW6Kc2QHTEeZVyYhc57IYYh5nmA,826
236
- atomicshop-2.10.3.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
237
- atomicshop-2.10.3.dist-info/METADATA,sha256=Y3tx3_gaPuodTn3bxopQR6X7_AYeMMMcv6Fjtv4dLJA,10423
238
- atomicshop-2.10.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
239
- atomicshop-2.10.3.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
240
- atomicshop-2.10.3.dist-info/RECORD,,
236
+ atomicshop-2.10.4.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
237
+ atomicshop-2.10.4.dist-info/METADATA,sha256=0kskgiSsXWr6BHlxBF9mViz3QkT0EoWqwm0LKmPJdBQ,10423
238
+ atomicshop-2.10.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
239
+ atomicshop-2.10.4.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
240
+ atomicshop-2.10.4.dist-info/RECORD,,