q2rad 0.1.231__tar.gz → 0.1.232__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.

Potentially problematic release.


This version of q2rad might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: q2rad
3
- Version: 0.1.231
3
+ Version: 0.1.232
4
4
  Summary: RAD - database, GUI, reports
5
5
  Author: Andrei Puchko
6
6
  Author-email: andrei.puchko@gmx.de
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "q2rad"
3
- version = "0.1.231"
3
+ version = "0.1.232"
4
4
  description = "RAD - database, GUI, reports"
5
5
  authors = ["Andrei Puchko <andrei.puchko@gmx.de>"]
6
6
  readme = "README.md"
@@ -22,6 +22,8 @@ from q2rad import Q2Form
22
22
  from q2terminal.q2terminal import Q2Terminal
23
23
  from q2rad.q2raddb import insert, update, get
24
24
  from datetime import datetime
25
+ from urllib.parse import urlparse
26
+ from q2rad.q2utils import ftp_upload
25
27
 
26
28
  import json
27
29
  import os
@@ -313,16 +315,46 @@ class AppManager(Q2Form):
313
315
  if app_name == "demo_app":
314
316
  self.export_data(f"{self.q2_app.q2market_path}/demo_data.json")
315
317
 
316
- trm = Q2Terminal(callback=print)
317
-
318
- def worker():
319
- trm.run(f"cd {self.q2_app.q2market_path}")
320
- trm.run("git add -A")
321
- trm.run(f"""git commit -a -m"{version}" """)
318
+ if os.path.isdir(f"{self.q2_app.q2market_path}/.git"):
319
+ trm = Q2Terminal(callback=print)
320
+
321
+ def worker():
322
+ trm.run(f"cd {self.q2_app.q2market_path}")
323
+ trm.run("git add -A")
324
+ trm.run(f"""git commit -a -m"{version}" """)
325
+
326
+ q2working(worker, "Commiting")
327
+ q2Mess(trm.run("""git push"""))
328
+ trm.close()
329
+ else: # try FTP
330
+ if os.path.isfile(".ftp"):
331
+ login, password = open(".ftp").read().split("\n")
332
+ else:
333
+ login, password = (
334
+ "",
335
+ "",
336
+ )
322
337
 
323
- q2working(worker, "Commiting")
324
- q2Mess(trm.run("""git push"""))
325
- trm.close()
338
+ app_file = f"{self.q2_app.q2market_path}/{os.path.basename(self.q2_app.app_url)}"
339
+ app_file_json = f"{app_file}.json"
340
+ app_file_version = f"{app_file}.version"
341
+ server = urlparse(self.q2_app.app_url).netloc
342
+ if server in self.q2_app.app_url:
343
+ workdir = os.path.dirname(self.q2_app.app_url.split(server)[1])
344
+ else:
345
+ workdir = ""
346
+ ftp_creds = Q2Form("FTP credentials")
347
+ ftp_creds.add_control("server", "Server", datalen=100, data=server)
348
+ ftp_creds.add_control("login", "Login", datalen=100, data=login)
349
+ ftp_creds.add_control("password", "Password", pic="*", datalen=100, data=password)
350
+ ftp_creds.ok_button = 1
351
+ ftp_creds.cancel_button = 1
352
+ ftp_creds.run()
353
+ if ftp_creds.ok_pressed:
354
+ try:
355
+ ftp_upload([app_file_json, app_file_version], server, workdir, login, password)
356
+ except Exception as error:
357
+ q2Mess(f"Error while uploading: {error}")
326
358
 
327
359
  def export_app(self, file="", app_json=None):
328
360
  filetype = "JSON(*.json)"
@@ -924,7 +924,7 @@ class Q2RadApp(Q2App):
924
924
  if self.frozen:
925
925
  return
926
926
 
927
- if not os.path.isdir(self.q2market_path) and self.app_url and self.app_version or force_update:
927
+ if not os.path.isdir(self.q2market_path) and self.app_url or force_update:
928
928
  try:
929
929
  market_version = read_url(self.app_url + ".version").decode("utf-8") # noqa F405
930
930
  except Exception as e: # noqa F841
@@ -27,7 +27,7 @@ from q2gui.q2model import Q2Model
27
27
  from q2gui.q2dialogs import q2ask
28
28
  from q2gui.q2model import Q2CursorModel
29
29
  from q2gui import q2app
30
- from q2gui.q2dialogs import q2working, q2Mess
30
+ from q2gui.q2dialogs import q2working, q2Mess, q2wait
31
31
  from q2gui.q2app import Q2Actions
32
32
  from q2gui.q2app import Q2Controls
33
33
  from q2gui.q2utils import int_
@@ -37,6 +37,9 @@ from logging.handlers import TimedRotatingFileHandler
37
37
 
38
38
  import gettext
39
39
 
40
+ import math
41
+ from ftplib import FTP
42
+
40
43
 
41
44
  _ = gettext.gettext
42
45
 
@@ -361,7 +364,11 @@ def q2choice(records=[], title="Make your choice", column_title=["Column"]):
361
364
 
362
365
  def choice_table():
363
366
  return q2choice(
364
- [{"table": x} for x in q2app.q2_app.db_data.db_schema.get_schema_tables() if not x.startswith("log_")],
367
+ [
368
+ {"table": x}
369
+ for x in q2app.q2_app.db_data.db_schema.get_schema_tables()
370
+ if not x.startswith("log_")
371
+ ],
365
372
  title="Select table",
366
373
  column_title="Table",
367
374
  )
@@ -531,8 +538,17 @@ class auto_filter:
531
538
  col["control"] = "line"
532
539
  col = Q2Controls.validate(col)
533
540
  self.filter_columns.append(cu.r.column)
534
-
535
- if col["datatype"] in ["date"] or (col.get("num") and col.get("to_form", "") == ""):
541
+ if col["datatype"] in ["date"] or (
542
+ col.get("num")
543
+ and col.get("to_form", "") == ""
544
+ and col.get("control", "")
545
+ not in (
546
+ "radio",
547
+ "vradio",
548
+ "list",
549
+ "combo",
550
+ )
551
+ ):
536
552
  self.mem.add_control("/h", cu.r.label, check=1)
537
553
  col["label"] = "from"
538
554
  co = col["column"]
@@ -543,6 +559,8 @@ class auto_filter:
543
559
  self.mem.add_control(**col)
544
560
  self.mem.add_control("/s")
545
561
  self.mem.add_control("/")
562
+ # elif col.get("control", "") == "check":
563
+ # pass
546
564
  else:
547
565
  col["label"] = cu.r.label
548
566
  col["check"] = 1
@@ -554,52 +572,28 @@ class auto_filter:
554
572
  def valid(self):
555
573
  where = []
556
574
  for x in self.filter_columns:
557
- where.append(self.prepare_where(x))
575
+ where.append(self.mem.prepare_where(x))
558
576
  where_string = " and ".join([x for x in where if x])
559
577
  q2app.q2_app.run_form(self.form_name, where=where_string)
560
578
  return False
561
579
 
562
- def prepare_where(self, column=None, control1=None, control2=None):
563
- mem_widgets = self.mem.widgets().keys()
564
- if control1 is None:
565
- if column in mem_widgets:
566
- control1 = column
567
- elif column + "____1" in mem_widgets:
568
- control1 = column + "____1"
569
- if control1 not in mem_widgets:
570
- return ""
571
-
572
- if not self.mem.w.__getattr__(control1).is_checked():
573
- return ""
574
-
575
- date_control = self.mem.controls.c.__getattr__(control1)["datatype"] == "date"
576
- num_control = self.mem.controls.c.__getattr__(control1).get("num")
577
- control1_value = self.mem.s.__getattr__(control1)
578
- if control2 is None:
579
- if control1.endswith("____1"):
580
- control2 = control1[:-5] + "____2"
581
- control2_value = self.mem.s.__getattr__(control2)
582
- else:
583
- control2_value = None
584
- if date_control:
585
- if control1_value == "0000-00-00":
586
- control1_value = ""
587
- if control2_value == "0000-00-00":
588
- control2_value = ""
589
- elif num_control:
590
- control1_value = num(control1_value)
591
- if control2_value:
592
- control2_value = num(control2_value)
593
-
594
- if (control2_value is None) or control1_value == control2_value:
595
- if date_control or num_control:
596
- return f"{column} = '{control1_value}'"
597
- else:
598
- return f"{column} like '%{control1_value}%'"
599
- elif (control1_value and not control2_value) or (control2_value and control1_value > control2_value):
600
- return f"{column} >= '{control1_value}'"
601
- elif not control1_value and control2_value:
602
- return f"{column} <= '{control2_value}'"
603
- elif control1_value and control2_value:
604
- return f"{column} >= '{control1_value}' and {column}<='{control2_value}'"
605
- return ""
580
+
581
+ def ftp_upload(files=[], server="", workdir="", login="", password=""):
582
+ chunks = sum([math.ceil(os.path.getsize(x) / 1000) for x in files])
583
+ w = q2wait(chunks)
584
+ connection = FTP(server)
585
+ connection.login(login, password)
586
+ connection.cwd(workdir)
587
+
588
+ def send_call_back(w=w):
589
+ def realDo(chunk):
590
+ w.step()
591
+
592
+ return realDo
593
+
594
+ for x in files:
595
+ localfile = open(x, "rb")
596
+ connection.storbinary(f"STOR {os.path.basename(x)}", localfile, 1024, send_call_back())
597
+ localfile.close()
598
+ connection.quit()
599
+ w.close()
@@ -0,0 +1 @@
1
+ __version__ = "0.1.232"
@@ -1 +0,0 @@
1
- __version__ = "0.1.231"
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes