osbot-utils 1.34.0__py3-none-any.whl → 1.36.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,12 +1,13 @@
1
+ from osbot_utils.base_classes.Type_Safe import Type_Safe
1
2
  from osbot_utils.utils.Misc import timestamp_utc_now
2
3
 
3
4
 
4
- class capture_duration():
5
- def __init__(self):
6
- self.duration = None
7
- self.start_timestamp = None
8
- self.end_timestamp = None
9
- self.seconds = None
5
+ class capture_duration(Type_Safe):
6
+ action_name : str
7
+ duration : float
8
+ start_timestamp : int
9
+ end_timestamp : int
10
+ seconds : float
10
11
 
11
12
  def __enter__(self):
12
13
  self.start_timestamp = timestamp_utc_now()
@@ -23,7 +24,10 @@ class capture_duration():
23
24
 
24
25
  def print(self):
25
26
  print()
26
- print(f'action took: {self.seconds} seconds')
27
+ if self.action_name:
28
+ print(f'action "{self.action_name}" took: {self.seconds} seconds')
29
+ else:
30
+ print(f'action took: {self.seconds} seconds')
27
31
 
28
32
  class print_duration(capture_duration):
29
33
 
@@ -1,7 +1,7 @@
1
1
  from pathlib import Path
2
2
  from typing import Dict, List
3
3
  from osbot_utils.helpers.Local_Cache import Local_Cache
4
- from osbot_utils.utils.Files import current_temp_folder, path_combine,folder_exists, folder_delete
4
+ from osbot_utils.utils.Files import current_temp_folder, path_combine, folder_exists, folder_delete, file_extension
5
5
  from osbot_utils.utils.Misc import random_text
6
6
 
7
7
 
@@ -41,8 +41,9 @@ class Local_Caches:
41
41
  cache_names = []
42
42
  for f in self.path_local_caches().iterdir():
43
43
  if f.is_file():
44
- cache_name = f.name.replace('.json', '')
45
- cache_names.append(cache_name)
44
+ if file_extension(f.name) == '.json':
45
+ cache_name = f.name.replace('.json', '')
46
+ cache_names.append(cache_name)
46
47
  return cache_names
47
48
 
48
49
  #@cache_on_self
@@ -124,10 +124,12 @@ class Sqlite__Database(Kwargs_To_Self):
124
124
  def tables_raw(self):
125
125
  return self.cursor().tables()
126
126
 
127
- def tables_names(self, include_sqlite_master=False):
127
+ def tables_names(self, include_sqlite_master=False, include_indexes=True):
128
128
  table_names = self.table__sqlite_master().select_field_values('name')
129
129
  if include_sqlite_master:
130
130
  table_names.append('sqlite_master')
131
+ if include_indexes is False:
132
+ return [table_name for table_name in table_names if table_name.startswith('idx') is False]
131
133
  return table_names
132
134
 
133
135
  def purge_database(self): # this fells like a better name than vacuum :)
@@ -0,0 +1,34 @@
1
+ from typing import Dict, Type
2
+
3
+ from osbot_utils.decorators.methods.cache_on_self import cache_on_self
4
+ from osbot_utils.helpers.sqlite.Sqlite__Database import Sqlite__Database
5
+ from osbot_utils.helpers.sqlite.tables.Sqlite__Table__Config import Sqlite__Table__Config, SQLITE__TABLE_NAME__CONFIG, \
6
+ Schema__Table__Config
7
+
8
+
9
+ class Sqlite__DB(Sqlite__Database):
10
+
11
+ # methods to override
12
+ def tables_to_add(self): # use this to define the tables that should be automatically created on setup
13
+ return {}
14
+
15
+ def db_not_configured(self):
16
+ return self.tables_names() == []
17
+
18
+ @cache_on_self
19
+ def table_config(self):
20
+ return Sqlite__Table__Config(database=self)
21
+
22
+
23
+
24
+ def tables_names(self, include_sqlite_master=False, include_indexes=False):
25
+ return super().tables_names(include_sqlite_master=include_sqlite_master, include_indexes=include_indexes)
26
+
27
+ def setup(self):
28
+ if self.db_not_configured():
29
+ self.table_config().setup()
30
+ for table_name, row_schema in self.tables_to_add().items():
31
+ table = self.table(table_name)
32
+ table.row_schema = row_schema
33
+ table.create()
34
+ return self
@@ -21,11 +21,18 @@ class Sqlite__DB__Files(Sqlite__DB__Local):
21
21
  def file(self, path, include_contents=False):
22
22
  return self.table_files().file(path, include_contents=include_contents)
23
23
 
24
+ def file_contents(self, path):
25
+ return self.table_files().file_contents(path)
26
+
27
+ def file__with_content(self, path):
28
+ return self.file(path, include_contents=True)
29
+
24
30
  def file_exists(self, path):
25
31
  return self.table_files().file_exists(path)
26
32
 
27
33
  def file_names(self):
28
34
  return self.table_files().select_field_values('path')
35
+
29
36
  @cache_on_self
30
37
  def table_files(self):
31
38
  return Sqlite__Table__Files(database=self).setup()
@@ -67,6 +67,12 @@ class Sqlite__Table__Files(Sqlite__Table):
67
67
  fields = self.field_names_without_content()
68
68
  return self.row(where=dict(path=path), fields = fields)
69
69
 
70
+ def file_contents(self, path):
71
+ fields = ['contents']
72
+ row = self.row(where=dict(path=path), fields = fields)
73
+ if row:
74
+ return row.get('contents')
75
+
70
76
  def file_without_contents(self, path):
71
77
  return self.file(path, include_contents=False)
72
78
 
osbot_utils/utils/Misc.py CHANGED
@@ -174,7 +174,7 @@ def is_guid(value):
174
174
  try:
175
175
  uuid_obj = uuid.UUID(value)
176
176
  return str(uuid_obj) == value.lower()
177
- except ValueError:
177
+ except Exception:
178
178
  return False
179
179
 
180
180
 
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.34.0
1
+ v1.36.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.34.0
3
+ Version: 1.36.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.34.0-blue)
25
+ ![Current Release](https://img.shields.io/badge/release-v1.36.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
 
@@ -6,7 +6,7 @@ osbot_utils/base_classes/Type_Safe.py,sha256=62eV2AnIAN-7VshhOpvWw0v_DZHJucLq10V
6
6
  osbot_utils/base_classes/Type_Safe__List.py,sha256=-80C9OhsK6iDR2dAG8yNLAZV0qg5x3faqvSUigFCMJw,517
7
7
  osbot_utils/base_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  osbot_utils/context_managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- osbot_utils/context_managers/capture_duration.py,sha256=l4l4UKC065Vi-zwyr4Ru_pVALsthCDQSXFR1mCl0DVQ,1187
9
+ osbot_utils/context_managers/capture_duration.py,sha256=sdWij3UJzDf1gDCogCO9RDg6Vijh1bZeeLSi3QmZeYs,1345
10
10
  osbot_utils/context_managers/disable_root_loggers.py,sha256=XDMbKATcRbmUQSMKaOhk68DANVdhbBvDxj15iXjIkw0,1056
11
11
  osbot_utils/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  osbot_utils/decorators/classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -59,7 +59,7 @@ osbot_utils/helpers/CPrint.py,sha256=ztKPNmT8BGxeyPXSQKRs63PqqbgxKDz_BiZmzFMup9g
59
59
  osbot_utils/helpers/Dict_To_Attr.py,sha256=NdhXl5mJH7-NaBk213amzc5Nfy3tJgW-N_uYIRE4hoc,208
60
60
  osbot_utils/helpers/Hashicorp_Secrets.py,sha256=zjXa_dQvfR9L1uoulWJ8nYYaDvznV6o_QPPS4zmb6mo,4235
61
61
  osbot_utils/helpers/Local_Cache.py,sha256=0JZZX3fFImcwtbBvxAQl-EbBegSNJRhRMYF6ovTH6zY,3141
62
- osbot_utils/helpers/Local_Caches.py,sha256=HvuP5CURyVm_fVvJX-S4dml2bhRauzgA3be237yTaeY,1814
62
+ osbot_utils/helpers/Local_Caches.py,sha256=aQmi1HSM0TH6WQPedG2fbz4KCCJ3DQTU9d18rB1jR0M,1885
63
63
  osbot_utils/helpers/Print_Table.py,sha256=LEXbyqGg_6WSraI4cob4bNNSu18ddqvALp1zGK7bPhs,19126
64
64
  osbot_utils/helpers/Python_Audit.py,sha256=shpZlluJwqJBAlad6xN01FkgC1TsQ48RLvR5ZjmrKa4,1539
65
65
  osbot_utils/helpers/Random_Seed.py,sha256=14btja8LDN9cMGWaz4fCNcMRU_eyx49gas-_PQvHgy4,634
@@ -184,7 +184,7 @@ osbot_utils/helpers/pubsub/schemas/Schema__PubSub__Client.py,sha256=yOQSn4o1bIsE
184
184
  osbot_utils/helpers/pubsub/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
185
185
  osbot_utils/helpers/sqlite/Capture_Sqlite_Error.py,sha256=GSuRYgs1yKQjxMszPoaI7fsfMfuUqhb64AaIysRE6Cs,1747
186
186
  osbot_utils/helpers/sqlite/Sqlite__Cursor.py,sha256=k5G9Tkk3nx6nHoSanLmpuJG_TceAmN7uRBCt0bo6sIc,3364
187
- osbot_utils/helpers/sqlite/Sqlite__Database.py,sha256=XcyZ7sqXQeV0dAyERiE3kYFeMubfhKidLbrlrZXLzQI,5432
187
+ osbot_utils/helpers/sqlite/Sqlite__Database.py,sha256=AAUaUXABiL1GE7urg20YpwbFGbRvRxqvv4D7IgCgvYw,5594
188
188
  osbot_utils/helpers/sqlite/Sqlite__Field.py,sha256=oBWglAOKN0EWVtaRwiQFxmR1FQ61lQ35yKkWXjSiihs,2911
189
189
  osbot_utils/helpers/sqlite/Sqlite__Globals.py,sha256=aP6uIy_y4xzl2soTUCFIJRjsb8JyfxfL6qIEZKIWy_4,230
190
190
  osbot_utils/helpers/sqlite/Sqlite__Table.py,sha256=FsFSolFN2N5V8DfZPp4gZL9xmCXaOhmG38wQmgRrvp8,15145
@@ -200,7 +200,8 @@ osbot_utils/helpers/sqlite/cache/Sqlite__Cache__Requests__Table.py,sha256=77uO-8
200
200
  osbot_utils/helpers/sqlite/cache/Sqlite__DB__Requests.py,sha256=CWB-hTcgly2T_7HOZM5gUgfdsvgMus5nX2M_wpjVLZs,1643
201
201
  osbot_utils/helpers/sqlite/cache/TestCase__Sqlite__Cache__Requests.py,sha256=TLUdQC6vsf5BcDP15CCeoYkipVG30bzqFcqEJpH4dWg,1645
202
202
  osbot_utils/helpers/sqlite/cache/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
203
- osbot_utils/helpers/sqlite/domains/Sqlite__DB__Files.py,sha256=tirQs4VjnjzGagaT17NigqprMuQiELHm5FwAE5PJT1U,1510
203
+ osbot_utils/helpers/sqlite/domains/Sqlite__DB.py,sha256=xyXnt4-GLYqMEPBZrNPI0dZnkl61KwLEIuYjebO20Jc,1210
204
+ osbot_utils/helpers/sqlite/domains/Sqlite__DB__Files.py,sha256=IyAbtHrpovNkIXaJKQ2vcg3yqF70XLQ-5mdIiN3vSK0,1696
204
205
  osbot_utils/helpers/sqlite/domains/Sqlite__DB__Graph.py,sha256=aGykK4Qll5Rn0xJR4RvF5bN6llNEjx-Vst52XTVSNio,1751
205
206
  osbot_utils/helpers/sqlite/domains/Sqlite__DB__Json.py,sha256=ILx1wOsmwmvV2yb_fMzLzo18uGNub8cxhBrRfYxCCqA,3808
206
207
  osbot_utils/helpers/sqlite/domains/Sqlite__DB__Local.py,sha256=liN_0gyXmQyqnsmiz0RYanSCRI0VoIbwSBf4buM0l-w,1093
@@ -215,7 +216,7 @@ osbot_utils/helpers/sqlite/sql_builder/SQL_Builder__Select.py,sha256=_5fszoWTknE
215
216
  osbot_utils/helpers/sqlite/sql_builder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
216
217
  osbot_utils/helpers/sqlite/tables/Sqlite__Table__Config.py,sha256=M-h6fYQgmX7Yaq3cSmpePutajLVeVy_IDUrDk97EH6U,2061
217
218
  osbot_utils/helpers/sqlite/tables/Sqlite__Table__Edges.py,sha256=YwlWj9GYBDeotqDFdjMOb6MyuHhPZKasndAtuHiLrkQ,1635
218
- osbot_utils/helpers/sqlite/tables/Sqlite__Table__Files.py,sha256=ZlhTqroHd9T8vqNwYpRv5cYHw7Fi-F6fxANh_Fr0nt4,3613
219
+ osbot_utils/helpers/sqlite/tables/Sqlite__Table__Files.py,sha256=4YguiuqzcfTadPWV67lN4IU_8xJzJF--ZRMqbEyzXqw,3800
219
220
  osbot_utils/helpers/sqlite/tables/Sqlite__Table__Nodes.py,sha256=GT8h3wD4hGvEtqQuBs0sBbcu2ydktRHTi95PEL2ffHQ,1721
220
221
  osbot_utils/helpers/sqlite/tables/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
221
222
  osbot_utils/helpers/ssh/SCP.py,sha256=9PgJbyWKfxJj00Ijaj7o6ffxPXuNoureb6JlHMPbHww,3330
@@ -274,7 +275,7 @@ osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
274
275
  osbot_utils/utils/Json.py,sha256=UNaBazuH1R40fsHjpjuK8kmAANmUHoK9Q0PUeYmgPeY,6254
275
276
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
276
277
  osbot_utils/utils/Lists.py,sha256=CLEjgZwAixJAFlubWEKjnUUhUN85oqvR7UqExVW7rdY,5502
277
- osbot_utils/utils/Misc.py,sha256=ljscBemI5wOhfkl1BVpsqshacTOCKkOisV4er9xPCWM,16640
278
+ osbot_utils/utils/Misc.py,sha256=AN-JTs9-Em2jVyoQ6Kd7dCA0eiqVQSlXajKjKxRAhyY,16639
278
279
  osbot_utils/utils/Objects.py,sha256=qAWNLISL-gYTl1Ihj4fBSZ9I6n-p-YPUhRZu9YQwqWQ,15235
279
280
  osbot_utils/utils/Png.py,sha256=V1juGp6wkpPigMJ8HcxrPDIP4bSwu51oNkLI8YqP76Y,1172
280
281
  osbot_utils/utils/Process.py,sha256=lr3CTiEkN3EiBx3ZmzYmTKlQoPdkgZBRjPulMxG-zdo,2357
@@ -286,8 +287,8 @@ osbot_utils/utils/Toml.py,sha256=dqiegndCJF7V1YT1Tc-b0-Bl6QWyL5q30urmQwMXfMQ,140
286
287
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
287
288
  osbot_utils/utils/Zip.py,sha256=riPLKkZJxQjVu8lCm19cOTx5uiLPm1HreB9_BzNXi30,12209
288
289
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
289
- osbot_utils/version,sha256=6TnKtA5LdTAs5O7GY4t2C4qn-h6U96yDc0iddfveSQ8,8
290
- osbot_utils-1.34.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
291
- osbot_utils-1.34.0.dist-info/METADATA,sha256=PcsPtdbnPio1BPKI-PeNDxw91YQ4URN5xP0lOuPrj6g,1266
292
- osbot_utils-1.34.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
293
- osbot_utils-1.34.0.dist-info/RECORD,,
290
+ osbot_utils/version,sha256=rMmpZHQMkGtmhxXxeNoUoWNY_rR9jHMl9gN-__ovf3A,8
291
+ osbot_utils-1.36.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
292
+ osbot_utils-1.36.0.dist-info/METADATA,sha256=QyYL2P7iaO1dC7rHFzfpsyfefApqQpbotMlC5uFhDeI,1266
293
+ osbot_utils-1.36.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
294
+ osbot_utils-1.36.0.dist-info/RECORD,,