kisa-utils 0.42.7__py3-none-any.whl → 0.42.9__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.
- kisa_utils/config.py +7 -5
- kisa_utils/db.py +24 -3
- kisa_utils/queues/persistent.py +11 -6
- {kisa_utils-0.42.7.dist-info → kisa_utils-0.42.9.dist-info}/METADATA +1 -1
- {kisa_utils-0.42.7.dist-info → kisa_utils-0.42.9.dist-info}/RECORD +7 -7
- {kisa_utils-0.42.7.dist-info → kisa_utils-0.42.9.dist-info}/WHEEL +0 -0
- {kisa_utils-0.42.7.dist-info → kisa_utils-0.42.9.dist-info}/top_level.txt +0 -0
kisa_utils/config.py
CHANGED
|
@@ -13,11 +13,12 @@ def _getTopicPath(topic:str):
|
|
|
13
13
|
|
|
14
14
|
return fout
|
|
15
15
|
def _initTopic(topic:str):
|
|
16
|
-
|
|
17
|
-
if not os.path.isfile(
|
|
18
|
-
|
|
16
|
+
foutPath = _getTopicPath(topic)
|
|
17
|
+
if not os.path.isfile(foutPath):
|
|
18
|
+
with open(foutPath,'wb') as fout:
|
|
19
|
+
pickle.dump({}, fout)
|
|
19
20
|
|
|
20
|
-
return
|
|
21
|
+
return foutPath
|
|
21
22
|
|
|
22
23
|
def _getTopicAndKey(path:str) -> list[str,str]:
|
|
23
24
|
'''
|
|
@@ -39,7 +40,8 @@ def getValue(path:str) -> Any|None:
|
|
|
39
40
|
|
|
40
41
|
topic, key = _getTopicAndKey(path)
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
with open(_initTopic(topic),'rb') as fin:
|
|
44
|
+
return pickle.load(fin).get(key)
|
|
43
45
|
|
|
44
46
|
def setValue(path:str, value:Any) -> bool:
|
|
45
47
|
'''
|
kisa_utils/db.py
CHANGED
|
@@ -222,6 +222,8 @@ class Api:
|
|
|
222
222
|
self._path = path
|
|
223
223
|
|
|
224
224
|
if path not in RAM_DB_PATHS:
|
|
225
|
+
path = storage.Path.getAbsolutePath(path)
|
|
226
|
+
|
|
225
227
|
while path.endswith('/'): path = path[:-1]
|
|
226
228
|
if not path.endswith(f'.{__EXT__}') and not os.path.isfile(path):
|
|
227
229
|
path += f'.{__EXT__}'
|
|
@@ -642,12 +644,13 @@ class Api:
|
|
|
642
644
|
|
|
643
645
|
#---------------------------------------------------------------------------
|
|
644
646
|
@__checkContext
|
|
645
|
-
def execute(self, cmd:str, cmdData:list=[]) -> dict[str,bool|str|int|sqlite3.Cursor] | Response:
|
|
647
|
+
def execute(self, cmd:str, cmdData:list=[], executingMultiple:bool=False) -> dict[str,bool|str|int|sqlite3.Cursor] | Response:
|
|
646
648
|
'''
|
|
647
649
|
attempt to execute arbitrary SQLite3 commands
|
|
648
650
|
Args:
|
|
649
651
|
cmd(str): SQLite command to run
|
|
650
652
|
cmdData(list): list to hold the values for the `?` placeholders in `cmd`
|
|
653
|
+
executingMultiple(bool): indicate if we're executing/inserting multiple statements/rows at ago. this allows us to use cursor.executemany instead of cursor.execute
|
|
651
654
|
Returns:
|
|
652
655
|
```
|
|
653
656
|
# if a dict is returned
|
|
@@ -685,7 +688,7 @@ class Api:
|
|
|
685
688
|
return reply if not self.__returnKISAResponse else Error(reply['log'])
|
|
686
689
|
|
|
687
690
|
try:
|
|
688
|
-
cursor = self.cursor.execute(cmd,cmdData)
|
|
691
|
+
cursor = (self.cursor.execute if not executingMultiple else self.cursor.executemany)(cmd,cmdData)
|
|
689
692
|
affectedRows = cursor.rowcount
|
|
690
693
|
|
|
691
694
|
if affectedRows < 0:
|
|
@@ -704,6 +707,20 @@ class Api:
|
|
|
704
707
|
reply['status'] = True
|
|
705
708
|
return reply if not self.__returnKISAResponse else Ok({'cursor':reply['cursor'], 'affectedRows':reply['affectedRows']})
|
|
706
709
|
|
|
710
|
+
@__checkContext
|
|
711
|
+
def executeScript(self, sql:str) -> Response:
|
|
712
|
+
'''
|
|
713
|
+
directly execute complex sql commands. this is useful when for you need to execute complex transactions example
|
|
714
|
+
Args:
|
|
715
|
+
sql(str): the sql to execute
|
|
716
|
+
'''
|
|
717
|
+
|
|
718
|
+
try:
|
|
719
|
+
self.db.executescript(sql)
|
|
720
|
+
except Exception as e:
|
|
721
|
+
return Error(f'{e}')
|
|
722
|
+
return Ok()
|
|
723
|
+
|
|
707
724
|
@__checkContext
|
|
708
725
|
def __createFetchResultsGenerator(self, results:sqlite3.Cursor, columnTitles:list, parseJson:bool, mode:str) -> Generator[tuple|dict|SimpleNamespace,None,None]:
|
|
709
726
|
|
|
@@ -867,7 +884,7 @@ class Api:
|
|
|
867
884
|
'''
|
|
868
885
|
insert a new row(s) into the database
|
|
869
886
|
Args:
|
|
870
|
-
table(str): the table
|
|
887
|
+
table(str): the table into which to insert data
|
|
871
888
|
data(list): 1d/2d list of the data to insert
|
|
872
889
|
+ 1d = insert single row
|
|
873
890
|
+ 2d = insert multple row
|
|
@@ -1370,5 +1387,9 @@ class Table:
|
|
|
1370
1387
|
if __name__=='__main__':
|
|
1371
1388
|
# Column('ab', int)
|
|
1372
1389
|
|
|
1390
|
+
with Api('/tmp/bukman/database.db2') as handle:
|
|
1391
|
+
print(handle.fetch('keys',['*'],'',[]))
|
|
1392
|
+
# Column('ab', int)
|
|
1393
|
+
|
|
1373
1394
|
with Api('/tmp/bukman/database.db2') as handle:
|
|
1374
1395
|
print(handle.fetch('keys',['*'],'',[]))
|
kisa_utils/queues/persistent.py
CHANGED
|
@@ -48,9 +48,10 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
48
48
|
|
|
49
49
|
__schema = {
|
|
50
50
|
'data': '''
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
52
|
+
tstamp VARCHAR(30) NOT NULL,
|
|
53
|
+
dataType VARCHAR(30) NOT NULL,
|
|
54
|
+
data JSON NOT NULL
|
|
54
55
|
''',
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -107,6 +108,9 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
107
108
|
'''
|
|
108
109
|
return self.__length
|
|
109
110
|
|
|
111
|
+
def __len__(self) -> int:
|
|
112
|
+
return self.length
|
|
113
|
+
|
|
110
114
|
def __load__(self) -> Response:
|
|
111
115
|
'''
|
|
112
116
|
load underlying queue database
|
|
@@ -148,6 +152,7 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
148
152
|
|
|
149
153
|
with Handle(self.dbPath, readonly=False, returnKISAResponse=True) as handle:
|
|
150
154
|
if not (resp := handle.insert('data', [
|
|
155
|
+
None,
|
|
151
156
|
dates.currentTimestamp(),
|
|
152
157
|
dataType,
|
|
153
158
|
data
|
|
@@ -165,7 +170,7 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
165
170
|
index = resp.data
|
|
166
171
|
|
|
167
172
|
with Handle(self.dbPath, returnKISAResponse=True) as handle:
|
|
168
|
-
if not (resp := handle.fetch('data', ['dataType', 'data'],'',[],limit=1, offset=index, parseJson=True)):
|
|
173
|
+
if not (resp := handle.fetch('data', ['dataType', 'data'],'1 order by id',[],limit=1, offset=index, parseJson=True)):
|
|
169
174
|
return resp
|
|
170
175
|
|
|
171
176
|
dataType, data = resp.data[0]
|
|
@@ -185,7 +190,7 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
185
190
|
index = resp.data
|
|
186
191
|
|
|
187
192
|
with Handle(self.dbPath, readonly=False, returnKISAResponse=True) as handle:
|
|
188
|
-
if not (resp := handle.fetch('data', ['
|
|
193
|
+
if not (resp := handle.fetch('data', ['id','dataType', 'data'],'1 order by id',[],limit=1, offset=index, parseJson=True)):
|
|
189
194
|
return resp
|
|
190
195
|
|
|
191
196
|
rowId, dataType, data = resp.data[0]
|
|
@@ -195,7 +200,7 @@ class PersistentQueue(metaclass=__PersistentQueueSingleton):
|
|
|
195
200
|
except:
|
|
196
201
|
return Error(f'failed to convert value to data-type `{dataType}`. the database was most likely corrupted')
|
|
197
202
|
|
|
198
|
-
if not (resp := handle.delete('data','
|
|
203
|
+
if not (resp := handle.delete('data','id=?',[rowId])):
|
|
199
204
|
return resp
|
|
200
205
|
|
|
201
206
|
self.__length -= 1
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
kisa_utils/__init__.py,sha256=-g5gBmI4gV840-Brg1V1aZ_R_r3n_csB-PlRRdUV_UQ,745
|
|
2
2
|
kisa_utils/cache.py,sha256=WOL3e0wvoyESXTtlbVnUg9TYUoLzg64sLP9J4b4ti9k,7377
|
|
3
3
|
kisa_utils/codes.py,sha256=PV_S53Skggf4XetOdYoIKtEmM8cpN5wZwUlxje70WZY,904
|
|
4
|
-
kisa_utils/config.py,sha256=
|
|
4
|
+
kisa_utils/config.py,sha256=vfwka6Wuz80su6_GgjuKhxolnzj1enw8cpgQPYm17l8,2357
|
|
5
5
|
kisa_utils/dataStructures.py,sha256=ZgLpttJ66jfpU1NWzLDD1Czqxzj6sWereffgTQWhlV8,2679
|
|
6
6
|
kisa_utils/dates.py,sha256=JN0vm-7_fOdpzLtondVmpjpWoePPJn4aGK0NkBuyF8I,14142
|
|
7
|
-
kisa_utils/db.py,sha256
|
|
7
|
+
kisa_utils/db.py,sha256=fQfvpSJz1A0KFpgXOjo_fyHcLwp9-d9GcDfyH6zhvMY,55788
|
|
8
8
|
kisa_utils/encryption.py,sha256=nFzNpzWV_D9uSEq4FsgCnlS7FQtqWP9fvM_81rsfcLo,4218
|
|
9
9
|
kisa_utils/figures.py,sha256=pYIpQzu1OXRSsY1d98GhgPifnIRmgl-r7S32ai-Ms0c,3731
|
|
10
10
|
kisa_utils/functionUtils.py,sha256=PlXjnmU1uJWNdISlJJ3SCgavTsgNBoebaa9dtWSFhRA,6553
|
|
@@ -18,7 +18,7 @@ kisa_utils/token.py,sha256=Y2qglWYWpmHxoXBh-TH0r1as0uPV5LLqMNcunLvM4vM,7850
|
|
|
18
18
|
kisa_utils/permissions/__config__.py,sha256=i3ELkOydDnjKx2ozQTxLZdZ8DXSeUncnl2kRxANjFmM,613
|
|
19
19
|
kisa_utils/permissions/__init__.py,sha256=iAsGEf5Ktw3gPJ5ZKL8BnuqX8e_S4QgsCVgfaRYi4Qg,48068
|
|
20
20
|
kisa_utils/queues/__init__.py,sha256=VvhceyN5qeiMel1JFQwLRuVk48oBXaWvDtriCubDOms,48
|
|
21
|
-
kisa_utils/queues/persistent.py,sha256=
|
|
21
|
+
kisa_utils/queues/persistent.py,sha256=KueLVqkVcTqvVe5yt9DEM_PvtUEannukixRS8icONTI,6872
|
|
22
22
|
kisa_utils/queues/callables/__init__.py,sha256=OJL3AQnaAS1Eek4H6WBH3WefA2wf-x03cwFmRSK8hoU,141
|
|
23
23
|
kisa_utils/queues/callables/enqueueFunctionCalls.py,sha256=VIliaMvw4MUdOqts0dXdZCYNxs-QrOVjIRAR3scGrRM,11786
|
|
24
24
|
kisa_utils/queues/callables/executorQueues.py,sha256=x6bAqxBSZRZ_kL8CK1lSN6JYAYFLxzM84LC1RmwaOLw,6626
|
|
@@ -27,7 +27,7 @@ kisa_utils/servers/flask.py,sha256=XZYY1pWnP1mSvaS5Uv8G3EFJV5BJBQtU2gDbO8suvLc,4
|
|
|
27
27
|
kisa_utils/structures/__init__.py,sha256=JBU1j3A42jQ62ALKnsS1Hav9YXcYwjDw1wQJtohXPbU,83
|
|
28
28
|
kisa_utils/structures/utils.py,sha256=665rXIapGwFqejizeJwy3DryeskCQOdgP25BCdLkGvk,2898
|
|
29
29
|
kisa_utils/structures/validator.py,sha256=JhD9jcfbjTwBr_7OfuNaJd_cYr7wR2emFhsCEo5MCHQ,4323
|
|
30
|
-
kisa_utils-0.42.
|
|
31
|
-
kisa_utils-0.42.
|
|
32
|
-
kisa_utils-0.42.
|
|
33
|
-
kisa_utils-0.42.
|
|
30
|
+
kisa_utils-0.42.9.dist-info/METADATA,sha256=ggmPfO1oysfdUkAExab5IOmqtA6pgvrD5O_orx1WzaU,477
|
|
31
|
+
kisa_utils-0.42.9.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
32
|
+
kisa_utils-0.42.9.dist-info/top_level.txt,sha256=GFOLXZYqpBG9xtscGa2uGJAEiZ5NwsqHBH9NylnB29M,11
|
|
33
|
+
kisa_utils-0.42.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|