Qwael 3.9.5__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.5
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
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import json
3
+ import time
3
4
 
4
5
  # --- KIVY ANDROID DOSYA DESTEĞİ EKLENDİ ---
5
6
  try:
@@ -16,7 +17,13 @@ class MultiDB:
16
17
  # --- Android için doğru klasör ayarı ---
17
18
  if platform == "android":
18
19
  app = App.get_running_app()
19
- filename = os.path.join(app.user_data_dir, filename)
20
+
21
+ if app:
22
+ # App çalışıyorsa user_data_dir kullan
23
+ filename = os.path.join(app.user_data_dir, filename)
24
+ else:
25
+ # App başlamamışsa geçici güvenli klasör
26
+ filename = os.path.join(os.getcwd(), filename)
20
27
  # ---------------------------------------
21
28
 
22
29
  self.filename = filename
@@ -30,12 +37,18 @@ class MultiDB:
30
37
  # LOCK SYSTEM
31
38
  # -----------------------------
32
39
  def _lock(self):
40
+ while os.path.exists(self.lockfile):
41
+ time.sleep(0.05)
42
+
33
43
  with open(self.lockfile, "w") as f:
34
44
  f.write("locked")
35
45
 
36
46
  def _unlock(self):
37
47
  if os.path.exists(self.lockfile):
38
- os.remove(self.lockfile)
48
+ try:
49
+ os.remove(self.lockfile)
50
+ except Exception:
51
+ pass
39
52
 
40
53
  # -----------------------------
41
54
  # FILE I/O
@@ -77,31 +90,32 @@ class MultiDB:
77
90
  # -----------------------------
78
91
  def create_table(self, name, columns):
79
92
  self._lock()
80
- lines = self._read()
93
+ try:
94
+ lines = self._read()
81
95
 
82
- if self._find_table(lines, name) != -1:
83
- self._unlock()
84
- raise ValueError("Bu tablo zaten var!")
96
+ if self._find_table(lines, name) != -1:
97
+ raise ValueError("Bu tablo zaten var!")
85
98
 
86
- col_names = []
87
- rules = {}
99
+ col_names = []
100
+ rules = {}
88
101
 
89
- for col in columns:
90
- if isinstance(col, dict):
91
- key = list(col.keys())[0]
92
- rule = col[key]
93
- col_names.append(key)
94
- rules[key] = rule
95
- else:
96
- col_names.append(col)
97
- 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] = ""
98
111
 
99
- lines.append(f"[TABLE {name}]")
100
- lines.append(json.dumps(col_names, ensure_ascii=False))
101
- 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))
102
115
 
103
- self._write(lines)
104
- self._unlock()
116
+ self._write(lines)
117
+ finally:
118
+ self._unlock()
105
119
 
106
120
  # -----------------------------
107
121
  # VALIDATION
@@ -146,8 +160,8 @@ class MultiDB:
146
160
  if not isinstance(values, (list, tuple)):
147
161
  values = [values]
148
162
 
163
+ self._lock()
149
164
  try:
150
- self._lock()
151
165
  lines = self._read()
152
166
 
153
167
  tpos = self._find_table(lines, table)
@@ -159,12 +173,19 @@ class MultiDB:
159
173
 
160
174
  final_values = []
161
175
 
176
+ # Eğer ID otomatik eklenecekse
162
177
  if len(values) + 1 == len(col_names) and "ID" in rules.values():
163
178
  auto_id = 1
164
179
  idx = tpos + 3
165
180
  while idx < len(lines) and not lines[idx].startswith("[TABLE"):
166
- row = json.loads(lines[idx])
167
- 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
168
189
  idx += 1
169
190
 
170
191
  final_values.append(str(auto_id))
@@ -176,14 +197,18 @@ class MultiDB:
176
197
  else:
177
198
  final_values = list(values)
178
199
 
200
+ # validation
179
201
  for i, col in enumerate(col_names):
180
- 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!")
181
206
  if not self._validate(final_values[i], rule, lines, tpos, i):
182
207
  raise ValueError(f"{col} alanı için veri kurala uymuyor: {rule}")
183
208
 
209
+ # insert
184
210
  lines.insert(tpos + 3, json.dumps(final_values, ensure_ascii=False))
185
211
  self._write(lines)
186
- self._unlock()
187
212
 
188
213
  if output_list is not None:
189
214
  output_list.append(True)
@@ -220,91 +245,93 @@ class MultiDB:
220
245
  # -----------------------------
221
246
  def clear_full(self, table):
222
247
  self._lock()
223
- lines = self._read()
224
- tpos = self._find_table(lines, table)
225
- if tpos == -1:
226
- self._unlock()
227
- 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ı!")
228
253
 
229
- new_lines = []
230
- i = 0
231
- while i < len(lines):
232
- if i != tpos:
233
- new_lines.append(lines[i])
234
- i += 1
235
- 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
236
261
 
237
- new_lines.append(lines[i])
238
- new_lines.append(lines[i + 1])
239
- 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])
240
265
 
241
- j = i + 3
242
- while j < len(lines) and not lines[j].startswith("[TABLE"):
243
- j += 1
244
- i = j
266
+ j = i + 3
267
+ while j < len(lines) and not lines[j].startswith("[TABLE"):
268
+ j += 1
269
+ i = j
245
270
 
246
- self._write(new_lines)
247
- self._unlock()
271
+ self._write(new_lines)
272
+ finally:
273
+ self._unlock()
248
274
 
249
275
  # -----------------------------
250
276
  # UPDATE TABLE
251
277
  # -----------------------------
252
278
  def table_update(self, table, columns):
253
279
  self._lock()
254
- lines = self._read()
255
- tpos = self._find_table(lines, table)
256
- if tpos == -1:
257
- self._unlock()
258
- raise ValueError("Böyle bir tablo yok!")
259
-
260
- col_names = []
261
- rules = {}
262
- for col in columns:
263
- if isinstance(col, dict):
264
- key = list(col.keys())[0]
265
- col_names.append(key)
266
- rules[key] = col[key]
267
- else:
268
- col_names.append(col)
269
- rules[col] = ""
270
-
271
- data_rows = []
272
- idx = tpos + 3
273
- while idx < len(lines) and not lines[idx].startswith("[TABLE"):
274
- data_rows.append(json.loads(lines[idx]))
275
- idx += 1
276
-
277
- new_data_rows = []
278
- old_cols = json.loads(lines[tpos + 1])
279
- for row in data_rows:
280
- new_row = []
281
- for col in col_names:
282
- if col in old_cols:
283
- 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]
284
293
  else:
285
- new_row.append("")
286
- new_data_rows.append(new_row)
287
-
288
- new_lines = []
289
- i = 0
290
- while i < len(lines):
291
- if i == tpos:
292
- new_lines.append(f"[TABLE {table}]")
293
- new_lines.append(json.dumps(col_names, ensure_ascii=False))
294
- new_lines.append(json.dumps(rules, ensure_ascii=False))
295
- for row in new_data_rows:
296
- new_lines.append(json.dumps(row, ensure_ascii=False))
297
-
298
- j = tpos + 3
299
- while j < len(lines) and not lines[j].startswith("[TABLE"):
300
- j += 1
301
- i = j
302
- else:
303
- new_lines.append(lines[i])
304
- 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
305
331
 
306
- self._write(new_lines)
307
- self._unlock()
332
+ self._write(new_lines)
333
+ finally:
334
+ self._unlock()
308
335
 
309
336
  # -----------------------------
310
337
  # CONTROL SYSTEM
@@ -406,4 +433,58 @@ class MultiDB:
406
433
  if output_list is not None:
407
434
  output_list.append(found_value)
408
435
 
409
- 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.5
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.5",
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