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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Qwael
3
- Version: 3.9.6
3
+ Version: 3.9.7
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)
@@ -230,91 +245,93 @@ class MultiDB:
230
245
  # -----------------------------
231
246
  def clear_full(self, table):
232
247
  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ı!")
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
- new_lines = []
240
- i = 0
241
- while i < len(lines):
242
- if i != tpos:
243
- new_lines.append(lines[i])
244
- i += 1
245
- continue
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
- new_lines.append(lines[i])
248
- new_lines.append(lines[i + 1])
249
- new_lines.append(lines[i + 2])
262
+ new_lines.append(lines[i])
263
+ new_lines.append(lines[i + 1])
264
+ new_lines.append(lines[i + 2])
250
265
 
251
- j = i + 3
252
- while j < len(lines) and not lines[j].startswith("[TABLE"):
253
- j += 1
254
- i = j
266
+ j = i + 3
267
+ while j < len(lines) and not lines[j].startswith("[TABLE"):
268
+ j += 1
269
+ i = j
255
270
 
256
- self._write(new_lines)
257
- self._unlock()
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
- 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)])
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
- 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
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
- self._write(new_lines)
317
- self._unlock()
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 == - -1:
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Qwael
3
- Version: 3.9.6
3
+ Version: 3.9.7
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.7",
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