atomicshop 3.3.25__py3-none-any.whl → 3.3.27__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__ = '3.3.25'
4
+ __version__ = '3.3.27'
atomicshop/ssh_remote.py CHANGED
@@ -1,6 +1,5 @@
1
1
  import sys
2
2
  import base64
3
- import socket
4
3
  import logging
5
4
  from pathlib import Path
6
5
 
@@ -138,43 +137,6 @@ class SSHRemote:
138
137
  def close(self):
139
138
  self.ssh_client.close()
140
139
 
141
- def exec_command_with_error_handling(self, script_string: str):
142
- # Defining variables.
143
- stdin = None
144
- stdout = None
145
- stderr = None
146
- result_exception = None
147
-
148
- # Don't put debugging break point over the next line in PyCharm. For some reason it gets stuck.
149
- # Put the point right after that.
150
- try:
151
- stdin, stdout, stderr = self.ssh_client.exec_command(command=script_string, timeout=30)
152
- except AttributeError as function_exception_object:
153
- if function_exception_object.name == "open_session":
154
- result_exception = "'SSHRemote().connect' wasn't executed."
155
- print_api(result_exception, logger=self.logger, logger_method='error', traceback_string=True)
156
-
157
- # Since getting Process name is not the main feature of the server, we can pass the exception
158
- pass
159
- else:
160
- result_exception = f"Couldn't execute script over SSH. Unknown yet exception with 'AttributeError' " \
161
- f"and name: {function_exception_object.name}"
162
- print_api(result_exception, logger=self.logger, logger_method='error', traceback_string=True)
163
- # Since getting Process name is not the main feature of the server, we can pass the exception
164
- pass
165
- except socket.error:
166
- result_exception = "Couldn't execute script over SSH. SSH socket closed."
167
- print_api(result_exception, logger=self.logger, logger_method='error', traceback_string=True)
168
- # Since getting Process name is not the main feature of the server, we can pass the exception
169
- pass
170
- except Exception:
171
- result_exception = "Couldn't execute script over SSH. Unknown yet exception."
172
- print_api(result_exception, logger=self.logger, logger_method='error', traceback_string=True)
173
- # Since getting Process name is not the main feature of the server, we can pass the exception
174
- pass
175
-
176
- return stdin, stdout, stderr, result_exception
177
-
178
140
  @staticmethod
179
141
  def check_console_output_for_errors(console_output_string: str):
180
142
  # Defining variables.
@@ -192,52 +154,33 @@ class SSHRemote:
192
154
 
193
155
  return function_result
194
156
 
195
- def remote_execution(self, script_string: str):
196
- # Defining variables.
197
- output_lines = None
198
- function_error = None
199
- stdin = None
200
- stdout = None
201
- stderr = None
202
- exec_exception = None
157
+ def remote_execution(self, script_string: str) -> tuple[str, str]:
158
+ output_result: str = str()
159
+ error_result: str = str()
203
160
 
204
161
  # Execute the command over SSH remotely.
205
- stdin, stdout, stderr, exec_exception = self.exec_command_with_error_handling(script_string)
206
- # If exception was returned from execution.
207
- if exec_exception:
208
- self.logger.info("Trying to reconnect over SSH.")
209
- # Close existing SSH Connection.
210
- self.close()
211
- # And connect again.
212
- self.connect()
213
- self.logger.info("Reconnected. Trying to send the command one more time.")
214
- # Try to execute the command over SSH remotely again.
215
- stdin, stdout, stderr, exec_exception = self.exec_command_with_error_handling(script_string)
216
- # If there was an exception again.
217
- if exec_exception:
218
- # Populate the function_error variable that will be returned outside.
219
- function_error = exec_exception
220
-
221
- # If there was no exception executing the remote command.
222
- if not function_error:
223
- # Reading the buffer of stdout.
224
- output_lines = stdout.readlines()
225
- # Reading the buffer of stderr.
226
- function_error = stderr.readlines()
227
-
228
- # Joining error lines list to string if not empty.
229
- if function_error:
230
- function_error = ''.join(function_error)
231
- # Else, joining output lines to string.
232
- else:
233
- output_lines = ''.join(output_lines)
234
-
235
- # Since they're "file-like" objects we need to close them after we finished using.
236
- stdin.close()
237
- stdout.close()
238
- stderr.close()
239
-
240
- return output_lines, function_error
162
+ # Don't put debugging break point over the next line in PyCharm. For some reason it gets stuck.
163
+ # Put the point right after that.
164
+ stdin, stdout, stderr = self.ssh_client.exec_command(command=script_string, timeout=30)
165
+
166
+ # Reading the buffer of stdout.
167
+ output_lines: list = stdout.readlines()
168
+ # Reading the buffer of stderr.
169
+ error_lines: list = stderr.readlines()
170
+
171
+ # Joining error lines list to string if not empty.
172
+ if error_lines:
173
+ error_result: str = ''.join(error_lines)
174
+ # Else, joining output lines to string.
175
+ else:
176
+ output_result = ''.join(output_lines)
177
+
178
+ # Since they're "file-like" objects we need to close them after we finished using.
179
+ stdin.close()
180
+ stdout.close()
181
+ stderr.close()
182
+
183
+ return output_result, error_result
241
184
 
242
185
  def remote_execution_python(self, script_string: str):
243
186
  """
@@ -277,8 +220,7 @@ class SSHRemote:
277
220
  :return: SSH console output, Error output
278
221
  """
279
222
  # Defining variables.
280
- function_return = None
281
- function_error = None
223
+ error_result: str | None = None
282
224
 
283
225
  encoded_base64_string = base64.b64encode(script_string.encode('ascii'))
284
226
  command_string: str = fr'python -c "import base64;exec(base64.b64decode({encoded_base64_string}))"'
@@ -295,14 +237,13 @@ class SSHRemote:
295
237
  # If the message is known and didn't return empty.
296
238
  if console_check:
297
239
  # 'execution_error' variable will be that full error.
298
- function_error = console_check
240
+ error_result = console_check
299
241
 
300
- return remote_output, function_error
242
+ return remote_output, error_result
301
243
 
302
244
  def connect_get_client_commandline(self, script_string):
303
245
  # Defining locals.
304
- execution_output = None
305
- execution_error = None
246
+ execution_output: str | None = None
306
247
 
307
248
  # Making actual SSH Connection to the computer.
308
249
  execution_error = self.connect()
@@ -316,13 +257,7 @@ class SSHRemote:
316
257
  if not execution_error:
317
258
  self.logger.info("Executing SSH command to acquire the calling process.")
318
259
 
319
- try:
320
- execution_output, execution_error = self.remote_execution_python(script_string)
321
- # Basically we don't care much about SSH exceptions. Just log them and pass to record.
322
- except Exception as function_exception_object:
323
- execution_error = function_exception_object
324
- print_api(execution_error, logger=self.logger, logger_method='error', traceback_string=True)
325
- pass
260
+ execution_output, execution_error = self.remote_execution_python(script_string)
326
261
 
327
262
  # Closing SSH connection at this stage.
328
263
  self.close()
@@ -553,6 +553,13 @@ class SocketWrapper:
553
553
  source_ip: str = client_address[0]
554
554
  dest_port: int = listening_socket_object.getsockname()[1]
555
555
 
556
+ # Not always there will be a hostname resolved by the IP address, so we will leave it empty if it fails.
557
+ try:
558
+ source_hostname = socket.gethostbyaddr(source_ip)[0]
559
+ source_hostname = source_hostname.lower()
560
+ except socket.herror:
561
+ pass
562
+
556
563
  # This is the earliest stage to ask for process name.
557
564
  # SSH Remote / LOCALHOST script execution to identify process section.
558
565
  # If 'get_process_name' was set to True, then this will be executed.
@@ -566,18 +573,11 @@ class SocketWrapper:
566
573
  logger=self.logger)
567
574
  process_name = get_command_instance.get_process_name(print_kwargs={'logger': self.logger})
568
575
 
569
- # Not always there will be a hostname resolved by the IP address, so we will leave it empty if it fails.
570
- try:
571
- source_hostname = socket.gethostbyaddr(source_ip)[0]
572
- except socket.herror:
573
- pass
574
-
575
576
  # If 'accept()' function worked well, SSL worked well, then 'client_socket' won't be empty.
576
577
  if client_socket:
577
578
  # Get the protocol type from the socket.
578
579
  is_tls: bool = False
579
580
 
580
- time.sleep(1) # Wait a second to gather some data.
581
581
  tls_properties = ssl_base.is_tls(client_socket)
582
582
 
583
583
  if tls_properties:
@@ -706,7 +706,7 @@ class SocketWrapper:
706
706
  except Exception as e:
707
707
  _ = e
708
708
  exception_string: str = tracebacks.get_as_string()
709
- full_string: str = f"Engine: {engine_name} | {exception_string}"
709
+ full_string: str = f"Engine: [{engine_name}] | {exception_string}"
710
710
  self.exceptions_logger.write(full_string)
711
711
 
712
712
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atomicshop
3
- Version: 3.3.25
3
+ Version: 3.3.27
4
4
  Summary: Atomic functions and classes to make developer life easier
5
5
  Author: Denis Kras
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
- atomicshop/__init__.py,sha256=peqNB9IL7p86gZd32BF4w1uBeAZvZo0dOfoMRX3xB5U,123
1
+ atomicshop/__init__.py,sha256=kvByZYai6H_Nq6t2xgY25H5YqEP8Wumh3lsrq7L5tzs,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
@@ -37,7 +37,7 @@ atomicshop/scheduling.py,sha256=MvF20M6uU0Kh_CQn2ERxMTLvvF-ToBrdMhXNrKxYFj8,4682
37
37
  atomicshop/script_as_string_processor.py,sha256=uAIWwhHE-eP2FniuwBqEiM6VzyQX96uwdE3aA31rIm8,1883
38
38
  atomicshop/sound.py,sha256=tHiQQbFBk7EYN3pAfGNcxfF9oNsoYnZgu9z9iq8hxQE,24352
39
39
  atomicshop/speech_recognize.py,sha256=55-dIjgkpF93mvJnJuxSFuft5H5eRvGNlUj9BeIOZxk,5903
40
- atomicshop/ssh_remote.py,sha256=-Xr8VMRJ2WpxdEG8HT2kFKKsb9GhSVVOJvUm948h1PE,15917
40
+ atomicshop/ssh_remote.py,sha256=6LUrFW-ZFMfQ52TmUxMVGcrVmMM3uqKaGKOY3lnEgFA,12480
41
41
  atomicshop/sys_functions.py,sha256=MTBxRve5bh58SPvhX3gMiGqHlSBuI_rdNN1NnnBBWqI,906
42
42
  atomicshop/system_resource_monitor.py,sha256=yHdBU4mAVqoVS0Nn_SM_H42i4PgsgXDaXaMxfnL5CgA,14588
43
43
  atomicshop/system_resources.py,sha256=iKUvVSaXR47inmr3cTYsgNfclT38dRia2oupnlhIpK4,9290
@@ -308,14 +308,14 @@ atomicshop/wrappers/socketw/sender.py,sha256=aX_K8l_rHjd5AWb8bi5mt8-YTkMYVRDB6Dn
308
308
  atomicshop/wrappers/socketw/sni.py,sha256=uj6KKYKmSrzXcKBhVLaHQhYn1wNfIUpdnmcvn21V9iE,18176
309
309
  atomicshop/wrappers/socketw/socket_client.py,sha256=WWIiCxUX9irN9aWzJ6-1xrXNB_iv_diq3ha1yrWsNGU,22671
310
310
  atomicshop/wrappers/socketw/socket_server_tester.py,sha256=Qobmh4XV8ZxLUaw-eW4ESKAbeSLecCKn2OWFzMhadk0,6420
311
- atomicshop/wrappers/socketw/socket_wrapper.py,sha256=bSFRfmzlfOsqb0jBLGsdCxDkZl6L0Si5QJZkShjOxEM,42589
311
+ atomicshop/wrappers/socketw/socket_wrapper.py,sha256=abvs3Jb7PZ6H5il0Yto6gCLkwY5tD40f0GYOzZVb8ng,42581
312
312
  atomicshop/wrappers/socketw/ssl_base.py,sha256=62-hPm7zla1rh3m_WvDnXqKH-sDUTdiRptD8STCkgdk,2313
313
313
  atomicshop/wrappers/socketw/statistics_csv.py,sha256=_gA8bMX6Sw_UCXKi2y9wNAwlqifgExgDGfQIa9pFxQA,5543
314
314
  atomicshop/wrappers/winregw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
315
315
  atomicshop/wrappers/winregw/winreg_installed_software.py,sha256=Qzmyktvob1qp6Tjk2DjLfAqr_yXV0sgWzdMW_9kwNjY,2345
316
316
  atomicshop/wrappers/winregw/winreg_network.py,sha256=ih0BVNwByLvf9F_Lac4EdmDYYJA3PzMvmG0PieDZrsE,9905
317
- atomicshop-3.3.25.dist-info/licenses/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
318
- atomicshop-3.3.25.dist-info/METADATA,sha256=VAymfm9H0qFDtFWy28IxXTtb6CGaePBQVC4QkN7nGv8,9318
319
- atomicshop-3.3.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
320
- atomicshop-3.3.25.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
321
- atomicshop-3.3.25.dist-info/RECORD,,
317
+ atomicshop-3.3.27.dist-info/licenses/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
318
+ atomicshop-3.3.27.dist-info/METADATA,sha256=dxwQ9W2q8wFoiAT41Anf4SywPfllS6Upu1klqk5fRWk,9318
319
+ atomicshop-3.3.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
320
+ atomicshop-3.3.27.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
321
+ atomicshop-3.3.27.dist-info/RECORD,,