Qwael 3.9.6__tar.gz → 3.9.7__tar.gz
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.
- {qwael-3.9.6 → qwael-3.9.7}/PKG-INFO +1 -1
- {qwael-3.9.6 → qwael-3.9.7}/Qwael/MultiDB.py +173 -102
- {qwael-3.9.6 → qwael-3.9.7}/Qwael.egg-info/PKG-INFO +1 -1
- {qwael-3.9.6 → qwael-3.9.7}/setup.py +1 -1
- {qwael-3.9.6 → qwael-3.9.7}/LICENSE +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/Qwael/DR/304/260VE.py" +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/Qwael/DoIP.py +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/Qwael/__init__.py +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/Qwael/filesz.py +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/Qwael.egg-info/SOURCES.txt +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/Qwael.egg-info/dependency_links.txt +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/Qwael.egg-info/requires.txt +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/Qwael.egg-info/top_level.txt +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/README.md +0 -0
- {qwael-3.9.6 → qwael-3.9.7}/setup.cfg +0 -0
|
@@ -18,7 +18,7 @@ class MultiDB:
|
|
|
18
18
|
if platform == "android":
|
|
19
19
|
app = App.get_running_app()
|
|
20
20
|
|
|
21
|
-
if app:
|
|
21
|
+
if app:
|
|
22
22
|
# App çalışıyorsa user_data_dir kullan
|
|
23
23
|
filename = os.path.join(app.user_data_dir, filename)
|
|
24
24
|
else:
|
|
@@ -45,7 +45,10 @@ class MultiDB:
|
|
|
45
45
|
|
|
46
46
|
def _unlock(self):
|
|
47
47
|
if os.path.exists(self.lockfile):
|
|
48
|
-
|
|
48
|
+
try:
|
|
49
|
+
os.remove(self.lockfile)
|
|
50
|
+
except Exception:
|
|
51
|
+
pass
|
|
49
52
|
|
|
50
53
|
# -----------------------------
|
|
51
54
|
# FILE I/O
|
|
@@ -87,31 +90,32 @@ class MultiDB:
|
|
|
87
90
|
# -----------------------------
|
|
88
91
|
def create_table(self, name, columns):
|
|
89
92
|
self._lock()
|
|
90
|
-
|
|
93
|
+
try:
|
|
94
|
+
lines = self._read()
|
|
91
95
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
raise ValueError("Bu tablo zaten var!")
|
|
96
|
+
if self._find_table(lines, name) != -1:
|
|
97
|
+
raise ValueError("Bu tablo zaten var!")
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
col_names = []
|
|
100
|
+
rules = {}
|
|
98
101
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
for col in columns:
|
|
103
|
+
if isinstance(col, dict):
|
|
104
|
+
key = list(col.keys())[0]
|
|
105
|
+
rule = col[key]
|
|
106
|
+
col_names.append(key)
|
|
107
|
+
rules[key] = rule
|
|
108
|
+
else:
|
|
109
|
+
col_names.append(col)
|
|
110
|
+
rules[col] = ""
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
lines.append(f"[TABLE {name}]")
|
|
113
|
+
lines.append(json.dumps(col_names, ensure_ascii=False))
|
|
114
|
+
lines.append(json.dumps(rules, ensure_ascii=False))
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
self._write(lines)
|
|
117
|
+
finally:
|
|
118
|
+
self._unlock()
|
|
115
119
|
|
|
116
120
|
# -----------------------------
|
|
117
121
|
# VALIDATION
|
|
@@ -156,8 +160,8 @@ class MultiDB:
|
|
|
156
160
|
if not isinstance(values, (list, tuple)):
|
|
157
161
|
values = [values]
|
|
158
162
|
|
|
163
|
+
self._lock()
|
|
159
164
|
try:
|
|
160
|
-
self._lock()
|
|
161
165
|
lines = self._read()
|
|
162
166
|
|
|
163
167
|
tpos = self._find_table(lines, table)
|
|
@@ -169,12 +173,19 @@ class MultiDB:
|
|
|
169
173
|
|
|
170
174
|
final_values = []
|
|
171
175
|
|
|
176
|
+
# Eğer ID otomatik eklenecekse
|
|
172
177
|
if len(values) + 1 == len(col_names) and "ID" in rules.values():
|
|
173
178
|
auto_id = 1
|
|
174
179
|
idx = tpos + 3
|
|
175
180
|
while idx < len(lines) and not lines[idx].startswith("[TABLE"):
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
try:
|
|
182
|
+
row = json.loads(lines[idx])
|
|
183
|
+
# güvenli int dönüşümü: boş/bozuk değerleri atla
|
|
184
|
+
if isinstance(row[0], str) and row[0].isdigit():
|
|
185
|
+
auto_id = max(auto_id, int(row[0]) + 1)
|
|
186
|
+
except Exception:
|
|
187
|
+
# bozuk satır varsa atla
|
|
188
|
+
pass
|
|
178
189
|
idx += 1
|
|
179
190
|
|
|
180
191
|
final_values.append(str(auto_id))
|
|
@@ -186,14 +197,18 @@ class MultiDB:
|
|
|
186
197
|
else:
|
|
187
198
|
final_values = list(values)
|
|
188
199
|
|
|
200
|
+
# validation
|
|
189
201
|
for i, col in enumerate(col_names):
|
|
190
|
-
rule = rules
|
|
202
|
+
rule = rules.get(col, "")
|
|
203
|
+
# eğer final_values eksikse hatayı fırlat
|
|
204
|
+
if i >= len(final_values):
|
|
205
|
+
raise ValueError("Eksik veri!")
|
|
191
206
|
if not self._validate(final_values[i], rule, lines, tpos, i):
|
|
192
207
|
raise ValueError(f"{col} alanı için veri kurala uymuyor: {rule}")
|
|
193
208
|
|
|
209
|
+
# insert
|
|
194
210
|
lines.insert(tpos + 3, json.dumps(final_values, ensure_ascii=False))
|
|
195
211
|
self._write(lines)
|
|
196
|
-
self._unlock()
|
|
197
212
|
|
|
198
213
|
if output_list is not None:
|
|
199
214
|
output_list.append(True)
|
|
@@ -230,91 +245,93 @@ class MultiDB:
|
|
|
230
245
|
# -----------------------------
|
|
231
246
|
def clear_full(self, table):
|
|
232
247
|
self._lock()
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
248
|
+
try:
|
|
249
|
+
lines = self._read()
|
|
250
|
+
tpos = self._find_table(lines, table)
|
|
251
|
+
if tpos == -1:
|
|
252
|
+
raise ValueError("Tablo bulunamadı!")
|
|
238
253
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
254
|
+
new_lines = []
|
|
255
|
+
i = 0
|
|
256
|
+
while i < len(lines):
|
|
257
|
+
if i != tpos:
|
|
258
|
+
new_lines.append(lines[i])
|
|
259
|
+
i += 1
|
|
260
|
+
continue
|
|
246
261
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
262
|
+
new_lines.append(lines[i])
|
|
263
|
+
new_lines.append(lines[i + 1])
|
|
264
|
+
new_lines.append(lines[i + 2])
|
|
250
265
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
266
|
+
j = i + 3
|
|
267
|
+
while j < len(lines) and not lines[j].startswith("[TABLE"):
|
|
268
|
+
j += 1
|
|
269
|
+
i = j
|
|
255
270
|
|
|
256
|
-
|
|
257
|
-
|
|
271
|
+
self._write(new_lines)
|
|
272
|
+
finally:
|
|
273
|
+
self._unlock()
|
|
258
274
|
|
|
259
275
|
# -----------------------------
|
|
260
276
|
# UPDATE TABLE
|
|
261
277
|
# -----------------------------
|
|
262
278
|
def table_update(self, table, columns):
|
|
263
279
|
self._lock()
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
else:
|
|
278
|
-
col_names.append(col)
|
|
279
|
-
rules[col] = ""
|
|
280
|
-
|
|
281
|
-
data_rows = []
|
|
282
|
-
idx = tpos + 3
|
|
283
|
-
while idx < len(lines) and not lines[idx].startswith("[TABLE"):
|
|
284
|
-
data_rows.append(json.loads(lines[idx]))
|
|
285
|
-
idx += 1
|
|
286
|
-
|
|
287
|
-
new_data_rows = []
|
|
288
|
-
old_cols = json.loads(lines[tpos + 1])
|
|
289
|
-
for row in data_rows:
|
|
290
|
-
new_row = []
|
|
291
|
-
for col in col_names:
|
|
292
|
-
if col in old_cols:
|
|
293
|
-
new_row.append(row[old_cols.index(col)])
|
|
280
|
+
try:
|
|
281
|
+
lines = self._read()
|
|
282
|
+
tpos = self._find_table(lines, table)
|
|
283
|
+
if tpos == -1:
|
|
284
|
+
raise ValueError("Böyle bir tablo yok!")
|
|
285
|
+
|
|
286
|
+
col_names = []
|
|
287
|
+
rules = {}
|
|
288
|
+
for col in columns:
|
|
289
|
+
if isinstance(col, dict):
|
|
290
|
+
key = list(col.keys())[0]
|
|
291
|
+
col_names.append(key)
|
|
292
|
+
rules[key] = col[key]
|
|
294
293
|
else:
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
294
|
+
col_names.append(col)
|
|
295
|
+
rules[col] = ""
|
|
296
|
+
|
|
297
|
+
data_rows = []
|
|
298
|
+
idx = tpos + 3
|
|
299
|
+
while idx < len(lines) and not lines[idx].startswith("[TABLE"):
|
|
300
|
+
data_rows.append(json.loads(lines[idx]))
|
|
301
|
+
idx += 1
|
|
302
|
+
|
|
303
|
+
new_data_rows = []
|
|
304
|
+
old_cols = json.loads(lines[tpos + 1])
|
|
305
|
+
for row in data_rows:
|
|
306
|
+
new_row = []
|
|
307
|
+
for col in col_names:
|
|
308
|
+
if col in old_cols:
|
|
309
|
+
new_row.append(row[old_cols.index(col)])
|
|
310
|
+
else:
|
|
311
|
+
new_row.append("")
|
|
312
|
+
new_data_rows.append(new_row)
|
|
313
|
+
|
|
314
|
+
new_lines = []
|
|
315
|
+
i = 0
|
|
316
|
+
while i < len(lines):
|
|
317
|
+
if i == tpos:
|
|
318
|
+
new_lines.append(f"[TABLE {table}]")
|
|
319
|
+
new_lines.append(json.dumps(col_names, ensure_ascii=False))
|
|
320
|
+
new_lines.append(json.dumps(rules, ensure_ascii=False))
|
|
321
|
+
for row in new_data_rows:
|
|
322
|
+
new_lines.append(json.dumps(row, ensure_ascii=False))
|
|
323
|
+
|
|
324
|
+
j = tpos + 3
|
|
325
|
+
while j < len(lines) and not lines[j].startswith("[TABLE"):
|
|
326
|
+
j += 1
|
|
327
|
+
i = j
|
|
328
|
+
else:
|
|
329
|
+
new_lines.append(lines[i])
|
|
330
|
+
i += 1
|
|
315
331
|
|
|
316
|
-
|
|
317
|
-
|
|
332
|
+
self._write(new_lines)
|
|
333
|
+
finally:
|
|
334
|
+
self._unlock()
|
|
318
335
|
|
|
319
336
|
# -----------------------------
|
|
320
337
|
# CONTROL SYSTEM
|
|
@@ -357,7 +374,7 @@ class MultiDB:
|
|
|
357
374
|
|
|
358
375
|
lines = self._read()
|
|
359
376
|
tpos = self._find_table(lines, table)
|
|
360
|
-
if tpos == -
|
|
377
|
+
if tpos == -1:
|
|
361
378
|
raise ValueError("Tablo bulunamadı!")
|
|
362
379
|
|
|
363
380
|
col_names = json.loads(lines[tpos + 1])
|
|
@@ -416,4 +433,58 @@ class MultiDB:
|
|
|
416
433
|
if output_list is not None:
|
|
417
434
|
output_list.append(found_value)
|
|
418
435
|
|
|
419
|
-
return found_value
|
|
436
|
+
return found_value
|
|
437
|
+
|
|
438
|
+
# -----------------------------
|
|
439
|
+
# REMOVE / DELETE ROW
|
|
440
|
+
# -----------------------------
|
|
441
|
+
def remove(self, table, row_id, output_list=None):
|
|
442
|
+
self._lock()
|
|
443
|
+
try:
|
|
444
|
+
lines = self._read()
|
|
445
|
+
|
|
446
|
+
tpos = self._find_table(lines, table)
|
|
447
|
+
if tpos == -1:
|
|
448
|
+
raise ValueError("Tablo bulunamadı!")
|
|
449
|
+
|
|
450
|
+
new_lines = []
|
|
451
|
+
removed = False
|
|
452
|
+
|
|
453
|
+
idx = 0
|
|
454
|
+
while idx < len(lines):
|
|
455
|
+
# tabloyu bulduk
|
|
456
|
+
if idx == tpos:
|
|
457
|
+
new_lines.append(lines[idx]) # [TABLE ...]
|
|
458
|
+
new_lines.append(lines[idx + 1]) # columns
|
|
459
|
+
new_lines.append(lines[idx + 2]) # rules
|
|
460
|
+
|
|
461
|
+
j = idx + 3
|
|
462
|
+
# tablonun satırlarını dönen döngü
|
|
463
|
+
while j < len(lines) and not lines[j].startswith("[TABLE"):
|
|
464
|
+
row = json.loads(lines[j])
|
|
465
|
+
if row[0] != str(row_id):
|
|
466
|
+
new_lines.append(lines[j])
|
|
467
|
+
else:
|
|
468
|
+
removed = True
|
|
469
|
+
j += 1
|
|
470
|
+
|
|
471
|
+
idx = j
|
|
472
|
+
continue
|
|
473
|
+
|
|
474
|
+
new_lines.append(lines[idx])
|
|
475
|
+
idx += 1
|
|
476
|
+
|
|
477
|
+
self._write(new_lines)
|
|
478
|
+
|
|
479
|
+
if output_list is not None:
|
|
480
|
+
output_list.append(removed)
|
|
481
|
+
|
|
482
|
+
return removed
|
|
483
|
+
|
|
484
|
+
except Exception:
|
|
485
|
+
if output_list is not None:
|
|
486
|
+
output_list.append(False)
|
|
487
|
+
raise
|
|
488
|
+
|
|
489
|
+
finally:
|
|
490
|
+
self._unlock()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|