Qwael 3.9.6__tar.gz → 3.9.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Qwael
3
- Version: 3.9.6
3
+ Version: 3.9.8
4
4
  Summary: Qwael: İşlevsel ve kolaylaştırılmış Python kütüphanesi
5
5
  Author: Bedirhan
6
6
  Author-email: bedirhan.oytpass@gmail.com
@@ -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
- os.remove(self.lockfile)
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
- lines = self._read()
93
+ try:
94
+ lines = self._read()
91
95
 
92
- if self._find_table(lines, name) != -1:
93
- self._unlock()
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
- col_names = []
97
- rules = {}
99
+ col_names = []
100
+ rules = {}
98
101
 
99
- for col in columns:
100
- if isinstance(col, dict):
101
- key = list(col.keys())[0]
102
- rule = col[key]
103
- col_names.append(key)
104
- rules[key] = rule
105
- else:
106
- col_names.append(col)
107
- rules[col] = ""
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
- lines.append(f"[TABLE {name}]")
110
- lines.append(json.dumps(col_names, ensure_ascii=False))
111
- lines.append(json.dumps(rules, ensure_ascii=False))
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
- self._write(lines)
114
- self._unlock()
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
- row = json.loads(lines[idx])
177
- auto_id = max(auto_id, int(row[0]) + 1)
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[col]
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)
@@ -226,95 +241,117 @@ class MultiDB:
226
241
  return result
227
242
 
228
243
  # -----------------------------
229
- # CLEAR DATA
244
+ # CLEAR DATA (onay-listesi uyumlu)
230
245
  # -----------------------------
231
- def clear_full(self, table):
246
+ def clear_full(self, table, onay=None):
247
+ """
248
+ table: temizlenecek tablo adı
249
+ onay: eğer bir liste verilirse, işlem başarılıysa onay.append(True),
250
+ başarısızsa onay.append(False) yapılır.
251
+ Fonksiyon ayrıca True/False döndürür (diğer fonksiyonlarla uyumlu).
252
+ """
232
253
  self._lock()
233
- lines = self._read()
234
- tpos = self._find_table(lines, table)
235
- if tpos == -1:
236
- self._unlock()
237
- raise ValueError("Tablo bulunamadı!")
254
+ try:
255
+ lines = self._read()
256
+ tpos = self._find_table(lines, table)
257
+ if tpos == -1:
258
+ if isinstance(onay, list):
259
+ onay.append(False)
260
+ return False
261
+
262
+ new_lines = []
263
+ i = 0
264
+ while i < len(lines):
265
+ if i != tpos:
266
+ new_lines.append(lines[i])
267
+ i += 1
268
+ continue
238
269
 
239
- new_lines = []
240
- i = 0
241
- while i < len(lines):
242
- if i != tpos:
270
+ # tablo başlığını koru
243
271
  new_lines.append(lines[i])
244
- i += 1
245
- continue
272
+ new_lines.append(lines[i + 1])
273
+ new_lines.append(lines[i + 2])
246
274
 
247
- new_lines.append(lines[i])
248
- new_lines.append(lines[i + 1])
249
- new_lines.append(lines[i + 2])
275
+ # tablonun altındaki kayıtları atla
276
+ j = i + 3
277
+ while j < len(lines) and not lines[j].startswith("[TABLE"):
278
+ j += 1
279
+ i = j
280
+
281
+ self._write(new_lines)
282
+
283
+ if isinstance(onay, list):
284
+ onay.append(True)
285
+ return True
250
286
 
251
- j = i + 3
252
- while j < len(lines) and not lines[j].startswith("[TABLE"):
253
- j += 1
254
- i = j
287
+ except Exception:
288
+ if isinstance(onay, list):
289
+ onay.append(False)
290
+ raise
255
291
 
256
- self._write(new_lines)
257
- self._unlock()
292
+ finally:
293
+ self._unlock()
258
294
 
259
295
  # -----------------------------
260
296
  # UPDATE TABLE
261
297
  # -----------------------------
262
298
  def table_update(self, table, columns):
263
299
  self._lock()
264
- lines = self._read()
265
- tpos = self._find_table(lines, table)
266
- if tpos == -1:
267
- self._unlock()
268
- raise ValueError("Böyle bir tablo yok!")
269
-
270
- col_names = []
271
- rules = {}
272
- for col in columns:
273
- if isinstance(col, dict):
274
- key = list(col.keys())[0]
275
- col_names.append(key)
276
- rules[key] = col[key]
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)])
300
+ try:
301
+ lines = self._read()
302
+ tpos = self._find_table(lines, table)
303
+ if tpos == -1:
304
+ raise ValueError("Böyle bir tablo yok!")
305
+
306
+ col_names = []
307
+ rules = {}
308
+ for col in columns:
309
+ if isinstance(col, dict):
310
+ key = list(col.keys())[0]
311
+ col_names.append(key)
312
+ rules[key] = col[key]
294
313
  else:
295
- new_row.append("")
296
- new_data_rows.append(new_row)
297
-
298
- new_lines = []
299
- i = 0
300
- while i < len(lines):
301
- if i == tpos:
302
- new_lines.append(f"[TABLE {table}]")
303
- new_lines.append(json.dumps(col_names, ensure_ascii=False))
304
- new_lines.append(json.dumps(rules, ensure_ascii=False))
305
- for row in new_data_rows:
306
- new_lines.append(json.dumps(row, ensure_ascii=False))
307
-
308
- j = tpos + 3
309
- while j < len(lines) and not lines[j].startswith("[TABLE"):
310
- j += 1
311
- i = j
312
- else:
313
- new_lines.append(lines[i])
314
- i += 1
314
+ col_names.append(col)
315
+ rules[col] = ""
316
+
317
+ data_rows = []
318
+ idx = tpos + 3
319
+ while idx < len(lines) and not lines[idx].startswith("[TABLE"):
320
+ data_rows.append(json.loads(lines[idx]))
321
+ idx += 1
322
+
323
+ new_data_rows = []
324
+ old_cols = json.loads(lines[tpos + 1])
325
+ for row in data_rows:
326
+ new_row = []
327
+ for col in col_names:
328
+ if col in old_cols:
329
+ new_row.append(row[old_cols.index(col)])
330
+ else:
331
+ new_row.append("")
332
+ new_data_rows.append(new_row)
333
+
334
+ new_lines = []
335
+ i = 0
336
+ while i < len(lines):
337
+ if i == tpos:
338
+ new_lines.append(f"[TABLE {table}]")
339
+ new_lines.append(json.dumps(col_names, ensure_ascii=False))
340
+ new_lines.append(json.dumps(rules, ensure_ascii=False))
341
+ for row in new_data_rows:
342
+ new_lines.append(json.dumps(row, ensure_ascii=False))
343
+
344
+ j = tpos + 3
345
+ while j < len(lines) and not lines[j].startswith("[TABLE"):
346
+ j += 1
347
+ i = j
348
+ else:
349
+ new_lines.append(lines[i])
350
+ i += 1
315
351
 
316
- self._write(new_lines)
317
- self._unlock()
352
+ self._write(new_lines)
353
+ finally:
354
+ self._unlock()
318
355
 
319
356
  # -----------------------------
320
357
  # CONTROL SYSTEM
@@ -357,7 +394,7 @@ class MultiDB:
357
394
 
358
395
  lines = self._read()
359
396
  tpos = self._find_table(lines, table)
360
- if tpos == - -1:
397
+ if tpos == -1:
361
398
  raise ValueError("Tablo bulunamadı!")
362
399
 
363
400
  col_names = json.loads(lines[tpos + 1])
@@ -416,4 +453,97 @@ class MultiDB:
416
453
  if output_list is not None:
417
454
  output_list.append(found_value)
418
455
 
419
- return found_value
456
+ return found_value
457
+
458
+ # -----------------------------
459
+ # REMOVE / DELETE ROW
460
+ # -----------------------------
461
+ def remove(self, table, row_id, output_list=None):
462
+ self._lock()
463
+ try:
464
+ lines = self._read()
465
+
466
+ tpos = self._find_table(lines, table)
467
+ if tpos == -1:
468
+ raise ValueError("Tablo bulunamadı!")
469
+
470
+ new_lines = []
471
+ removed = False
472
+
473
+ idx = 0
474
+ while idx < len(lines):
475
+ # tabloyu bulduk
476
+ if idx == tpos:
477
+ new_lines.append(lines[idx]) # [TABLE ...]
478
+ new_lines.append(lines[idx + 1]) # columns
479
+ new_lines.append(lines[idx + 2]) # rules
480
+
481
+ j = idx + 3
482
+ # tablonun satırlarını dönen döngü
483
+ while j < len(lines) and not lines[j].startswith("[TABLE"):
484
+ row = json.loads(lines[j])
485
+ if row[0] != str(row_id):
486
+ new_lines.append(lines[j])
487
+ else:
488
+ removed = True
489
+ j += 1
490
+
491
+ idx = j
492
+ continue
493
+
494
+ new_lines.append(lines[idx])
495
+ idx += 1
496
+
497
+ self._write(new_lines)
498
+
499
+ if output_list is not None:
500
+ output_list.append(removed)
501
+
502
+ return removed
503
+
504
+ except Exception:
505
+ if output_list is not None:
506
+ output_list.append(False)
507
+ raise
508
+
509
+ finally:
510
+ self._unlock()
511
+
512
+ # -----------------------------
513
+ # ROMEVE - Tek tablo veya tüm tabloların verilerini temizle
514
+ # -----------------------------
515
+ def romeve(self, table_or_full, onay=None):
516
+ """
517
+ Kullanım:
518
+ x.romeve("kullanıcı", onay) -> sadece belirtilen tabloyu temizler (onay listesi varsa append eder)
519
+ x.romeve(full_var, onay) -> eğer table_or_full str değilse tüm tablolar temizlenir
520
+ (not: burada 'full' özel bir isim değil; str değilse 'tüm' olarak kabul edilir)
521
+ """
522
+ # TEK TABLO ise
523
+ if isinstance(table_or_full, str):
524
+ return self.clear_full(table_or_full, onay)
525
+
526
+ # TÜM TABLOLAR ise
527
+ try:
528
+ lines = self._read()
529
+ tables = []
530
+ for line in lines:
531
+ if line.startswith("[TABLE "):
532
+ name = line.replace("[TABLE ", "").replace("]", "")
533
+ tables.append(name)
534
+
535
+ success = True
536
+ for t in tables:
537
+ res = self.clear_full(t, onay=None) # tek tek temizle, fakat onay append'ini biz sonradan yapacağız
538
+ if not res:
539
+ success = False
540
+
541
+ if isinstance(onay, list):
542
+ onay.append(success)
543
+
544
+ return success
545
+
546
+ except Exception:
547
+ if isinstance(onay, list):
548
+ onay.append(False)
549
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Qwael
3
- Version: 3.9.6
3
+ Version: 3.9.8
4
4
  Summary: Qwael: İşlevsel ve kolaylaştırılmış Python kütüphanesi
5
5
  Author: Bedirhan
6
6
  Author-email: bedirhan.oytpass@gmail.com
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as f:
5
5
 
6
6
  setup(
7
7
  name="Qwael",
8
- version="3.9.6",
8
+ version="3.9.8",
9
9
  packages=find_packages(),
10
10
  install_requires=[
11
11
  "google-api-python-client",
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