osbot-utils 1.21.0__py3-none-any.whl → 1.22.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.
@@ -1,7 +1,8 @@
1
1
  from osbot_utils.utils.Misc import list_set
2
2
  from osbot_utils.utils.Dev import pprint
3
3
  from osbot_utils.decorators.methods.cache_on_self import cache_on_self
4
- from osbot_utils.utils.Files import current_temp_folder, path_combine, create_folder, safe_file_name, file_exists, file_delete
4
+ from osbot_utils.utils.Files import current_temp_folder, path_combine, create_folder, safe_file_name, file_exists, \
5
+ file_delete, file_size
5
6
  from osbot_utils.utils.Json import json_save_file, json_load_file
6
7
 
7
8
 
@@ -32,6 +33,9 @@ class Local_Cache:
32
33
  def cache_exists(self):
33
34
  return file_exists(self.path_cache_file())
34
35
 
36
+ def cache_file_size(self):
37
+ return file_size(self.path_cache_file())
38
+
35
39
  def create(self):
36
40
  if not self.cache_exists():
37
41
  self.save()
@@ -1,11 +1,13 @@
1
1
  from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
2
+ from osbot_utils.base_classes.Type_Safe import Type_Safe
2
3
  from osbot_utils.decorators.methods.cache_on_self import cache_on_self
3
4
  from osbot_utils.helpers.ssh.SCP import SCP
4
5
  from osbot_utils.helpers.ssh.SSH__Execute import SSH__Execute
5
6
  from osbot_utils.helpers.ssh.SSH__Linux import SSH__Linux
7
+ from osbot_utils.helpers.ssh.SSH__Linux__Amazon import SSH__Linux__Amazon
6
8
  from osbot_utils.helpers.ssh.SSH__Python import SSH__Python
7
9
 
8
- class SSH(Kwargs_To_Self):
10
+ class SSH(Type_Safe): # todo: add ip_address to global vars here, and when that is done, add the wait_for_ssh method (that exists in EC2_Instance)
9
11
 
10
12
  def setup(self):
11
13
  self.ssh_execute().setup()
@@ -25,6 +27,11 @@ class SSH(Kwargs_To_Self):
25
27
  def ssh_linux(self):
26
28
  return SSH__Linux(ssh_execute = self.ssh_execute())
27
29
 
30
+ @cache_on_self
31
+ def ssh_linux_amazon(self):
32
+ return SSH__Linux__Amazon(ssh_execute=self.ssh_execute())
33
+
28
34
  @cache_on_self
29
35
  def ssh_python(self):
30
- return SSH__Python(ssh_execute = self.ssh_execute(), ssh_linux = self.ssh_linux())
36
+ return SSH__Python(ssh_execute = self.ssh_execute(), ssh_linux = self.ssh_linux())
37
+
@@ -21,6 +21,7 @@ class SSH__Execute(Type_Safe):
21
21
  ssh_key_file : str
22
22
  ssh_key_user : str
23
23
  strict_host_check : bool = False
24
+ print_after_exec : bool = False
24
25
 
25
26
  # execution & other commands # todo refactor into separate class
26
27
  def exec(self, command):
@@ -29,7 +30,7 @@ class SSH__Execute(Type_Safe):
29
30
  def exec__print(self, command):
30
31
  result = self.execute_command__return_stdout(command)
31
32
  self.print_header_for_command(command)
32
- print(result)
33
+ self.print_status__stderr__stdout(result)
33
34
  return result
34
35
 
35
36
  def execute_command(self, command):
@@ -38,13 +39,15 @@ class SSH__Execute(Type_Safe):
38
39
  with capture_duration() as duration:
39
40
  result = start_process("ssh", ssh_args) # execute command using subprocess.run(...)
40
41
  result['duration'] = duration.data()
42
+ if self.print_after_exec:
43
+ self.print_status__stderr__stdout(result)
41
44
  return result
42
45
  return status_error(error='in execute_command not all required vars were setup')
43
46
 
44
47
  def execute_command__print(self, command):
45
48
  self.print_header_for_command(command)
46
49
  result = self.execute_command(command)
47
- pprint(result)
50
+ self.print_status__stderr__stdout(result)
48
51
  return result
49
52
 
50
53
  def execute_ssh_args(self):
@@ -142,8 +145,14 @@ class SSH__Execute(Type_Safe):
142
145
  # pprint(self.ls(path))
143
146
  # return self
144
147
 
145
- def print_exec(self, command=''):
146
- return self.exec__print(command)
148
+ def print_status__stderr__stdout(self, result):
149
+ print()
150
+ print( '┌──────────────────────────────────────────')
151
+ print(f'├ command: {result.get("command") }')
152
+ print(f'│ status : {result.get("status" ).strip()}')
153
+ print(f'│ stderr : {result.get("stderr" ).strip()}')
154
+ print(f'│ stdout : {result.get("stdout" ).strip()}')
155
+ return self
147
156
 
148
157
  def print_header_for_command(self, command):
149
158
  print('\n')
@@ -0,0 +1,14 @@
1
+ from osbot_utils.helpers.ssh.SSH__Linux import SSH__Linux
2
+
3
+
4
+ class SSH__Linux__Amazon(SSH__Linux):
5
+
6
+ def install_python3(self):
7
+ execute_commands = ('sudo yum install -y python3.11 && '
8
+ 'curl -O https://bootstrap.pypa.io/get-pip.py && '
9
+ 'sudo python3.11 get-pip.py' )
10
+
11
+ return self.ssh_execute.execute_command__return_stdout(execute_commands)
12
+
13
+ def pip_install(self, package_name):
14
+ return self.ssh_execute.execute_command__return_stdout(f'pip3.11 install {package_name}')
osbot_utils/utils/Misc.py CHANGED
@@ -384,6 +384,9 @@ def random_text(prefix:str=None,length:int=12, lowercase=False):
384
384
  def random_uuid():
385
385
  return str(uuid.uuid4())
386
386
 
387
+ def random_uuid_short():
388
+ return str(uuid.uuid4())[0:6]
389
+
387
390
  def remove(target_string, string_to_remove): # todo: refactor to str_*
388
391
  return replace(target_string, string_to_remove, '')
389
392
 
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.21.0
1
+ v1.22.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.21.0
3
+ Version: 1.22.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  Home-page: https://github.com/owasp-sbot/OSBot-Utils
6
6
  License: MIT
@@ -22,7 +22,7 @@ Description-Content-Type: text/markdown
22
22
 
23
23
  Powerful Python util methods and classes that simplify common apis and tasks.
24
24
 
25
- ![Current Release](https://img.shields.io/badge/release-v1.21.0-blue)
25
+ ![Current Release](https://img.shields.io/badge/release-v1.22.0-blue)
26
26
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
27
27
 
28
28
 
@@ -57,7 +57,7 @@ osbot_utils/graphs/mgraph/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
57
57
  osbot_utils/helpers/CFormat.py,sha256=1_XvqGwgU6qC97MbzcKF0o7s9mCXpU5Kq9Yf-1ixUwY,6808
58
58
  osbot_utils/helpers/CPrint.py,sha256=ztKPNmT8BGxeyPXSQKRs63PqqbgxKDz_BiZmzFMup9g,1413
59
59
  osbot_utils/helpers/Dict_To_Attr.py,sha256=NdhXl5mJH7-NaBk213amzc5Nfy3tJgW-N_uYIRE4hoc,208
60
- osbot_utils/helpers/Local_Cache.py,sha256=nxyorvXbXyWdlKkLeSeWmUhw1gE4SpOdso919IKfIE4,3046
60
+ osbot_utils/helpers/Local_Cache.py,sha256=0JZZX3fFImcwtbBvxAQl-EbBegSNJRhRMYF6ovTH6zY,3141
61
61
  osbot_utils/helpers/Local_Caches.py,sha256=HvuP5CURyVm_fVvJX-S4dml2bhRauzgA3be237yTaeY,1814
62
62
  osbot_utils/helpers/Print_Table.py,sha256=LEXbyqGg_6WSraI4cob4bNNSu18ddqvALp1zGK7bPhs,19126
63
63
  osbot_utils/helpers/Python_Audit.py,sha256=shpZlluJwqJBAlad6xN01FkgC1TsQ48RLvR5ZjmrKa4,1539
@@ -217,11 +217,12 @@ osbot_utils/helpers/sqlite/tables/Sqlite__Table__Files.py,sha256=ZlhTqroHd9T8vqN
217
217
  osbot_utils/helpers/sqlite/tables/Sqlite__Table__Nodes.py,sha256=GT8h3wD4hGvEtqQuBs0sBbcu2ydktRHTi95PEL2ffHQ,1721
218
218
  osbot_utils/helpers/sqlite/tables/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
219
219
  osbot_utils/helpers/ssh/SCP.py,sha256=9PgJbyWKfxJj00Ijaj7o6ffxPXuNoureb6JlHMPbHww,3330
220
- osbot_utils/helpers/ssh/SSH.py,sha256=El2Op9b_pcr7msolwbbtkW74R2f_BJN_jdf3SQk_gk8,1081
220
+ osbot_utils/helpers/ssh/SSH.py,sha256=YC3mwLjHxiCrt4t2s15xvAdFcz4yfQVMwqE8mByKmVU,1458
221
221
  osbot_utils/helpers/ssh/SSH__Cache__Requests.py,sha256=Dqh4biVcuaXbQVvn3Tx-kSGBGHiF-2wVsgu96EhD6gU,3359
222
- osbot_utils/helpers/ssh/SSH__Execute.py,sha256=2RjLEf8UuxsYjRoJDmbNdmx5LGgEN4pDS-DhXe3_mDs,6252
222
+ osbot_utils/helpers/ssh/SSH__Execute.py,sha256=D5tQGbSPaNsrMvhTVT0sZIHpqF1rIYXYiaWzGExcwm4,6849
223
223
  osbot_utils/helpers/ssh/SSH__Health_Check.py,sha256=WDmBD6ejNcBeicXfjpsiNzH-WR3Jejx0re3WfwjSWyQ,2083
224
224
  osbot_utils/helpers/ssh/SSH__Linux.py,sha256=O1uyKcklaj2tHqQZln7dVinzjl9-EI52KzP8ojQr244,4330
225
+ osbot_utils/helpers/ssh/SSH__Linux__Amazon.py,sha256=ZJFb7LFTvclAuhH5OoOtJ361NoX9ecHTaFX-iSmnzmk,596
225
226
  osbot_utils/helpers/ssh/SSH__Python.py,sha256=O2DAwkbXzwkis8lffoqIL2NPSfYcN44Mr8i9Ey2iMKk,2066
226
227
  osbot_utils/helpers/ssh/TestCase__SSH.py,sha256=rlhkiVr1OR_3uiwqK2dVZ-yBwZZpUhMq6BPT2p21H1s,1598
227
228
  osbot_utils/helpers/ssh/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -270,7 +271,7 @@ osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
270
271
  osbot_utils/utils/Json.py,sha256=UNaBazuH1R40fsHjpjuK8kmAANmUHoK9Q0PUeYmgPeY,6254
271
272
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
272
273
  osbot_utils/utils/Lists.py,sha256=CLEjgZwAixJAFlubWEKjnUUhUN85oqvR7UqExVW7rdY,5502
273
- osbot_utils/utils/Misc.py,sha256=5pVxQLCOcGNL3PtasOtQCN8ostg2X-H7mucdZjgg_ns,16580
274
+ osbot_utils/utils/Misc.py,sha256=ljscBemI5wOhfkl1BVpsqshacTOCKkOisV4er9xPCWM,16640
274
275
  osbot_utils/utils/Objects.py,sha256=SNtQ1nJnqihwTcmIf_Hg9P3V7fHjxcVHSzC7vKKI34Q,14419
275
276
  osbot_utils/utils/Png.py,sha256=V1juGp6wkpPigMJ8HcxrPDIP4bSwu51oNkLI8YqP76Y,1172
276
277
  osbot_utils/utils/Process.py,sha256=lr3CTiEkN3EiBx3ZmzYmTKlQoPdkgZBRjPulMxG-zdo,2357
@@ -281,8 +282,8 @@ osbot_utils/utils/Toml.py,sha256=-bg9srF7ef31UCNFa0aL3CDeDKp14XeUVwRMQzMb_dI,107
281
282
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
282
283
  osbot_utils/utils/Zip.py,sha256=YFahdBguVK71mLdYy4m7mqVAQ5al-60QnTmYK-txCfY,6784
283
284
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
284
- osbot_utils/version,sha256=o-_WEzInxIO2B4oYaxJD3HXoT3MWSTq6e3KoW9rZp-I,8
285
- osbot_utils-1.21.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
286
- osbot_utils-1.21.0.dist-info/METADATA,sha256=0aIOGo4sPuKtaD1s0iAq3KhhLvqy_rF2vGKgrCq5H9o,1266
287
- osbot_utils-1.21.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
288
- osbot_utils-1.21.0.dist-info/RECORD,,
285
+ osbot_utils/version,sha256=z7NTPYmQ0L2Y8UsRZopbRpNKn5uryAcux3sKpD_TKh0,8
286
+ osbot_utils-1.22.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
287
+ osbot_utils-1.22.0.dist-info/METADATA,sha256=iNHC9Qu30A7DwLcvMTVwBkWT_EHdzVUYP4XXooShCKI,1266
288
+ osbot_utils-1.22.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
289
+ osbot_utils-1.22.0.dist-info/RECORD,,