dmart 1.4.40.post32__py3-none-any.whl → 1.4.40.post33__py3-none-any.whl

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.
dmart/dmart.py CHANGED
@@ -9,6 +9,7 @@ import ssl
9
9
  import subprocess
10
10
  import sys
11
11
  import os
12
+ import secrets
12
13
  sys.path.append(os.path.dirname(__file__))
13
14
 
14
15
  import time
@@ -20,7 +21,6 @@ from pathlib import Path
20
21
 
21
22
  from hypercorn.config import Config
22
23
  from hypercorn.run import run
23
- from utils.settings import settings
24
24
 
25
25
  # freeze_support()
26
26
 
@@ -46,6 +46,109 @@ commands = """
46
46
 
47
47
  sentinel = object()
48
48
 
49
+ def ensure_dmart_home():
50
+ dmart_home = Path.home() / ".dmart"
51
+ dmart_home.mkdir(parents=True, exist_ok=True)
52
+
53
+ config_env = dmart_home / "config.env"
54
+ if not config_env.exists():
55
+ try:
56
+ (dmart_home / "logs").mkdir(parents=True, exist_ok=True)
57
+ (dmart_home / "spaces").mkdir(parents=True, exist_ok=True)
58
+ (dmart_home / "spaces" / "custom_plugins").mkdir(parents=True, exist_ok=True)
59
+
60
+ jwt_secret = secrets.token_urlsafe(32)
61
+
62
+ config_content = f"""# dmart configuration
63
+ JWT_SECRET="{jwt_secret}"
64
+ JWT_ALGORITHM="HS256"
65
+ LOG_FILE="{dmart_home / 'logs' / 'dmart.ljson.log'}"
66
+ WS_LOG_FILE="{dmart_home / 'logs' / 'websocket.ljson.log'}"
67
+
68
+ # Database configuration
69
+ ACTIVE_DATA_DB="file"
70
+ SPACES_FOLDER="{dmart_home / 'spaces'}"
71
+ DATABASE_DRIVER="sqlite+pysqlite"
72
+ DATABASE_NAME="{dmart_home / 'dmart.db'}"
73
+
74
+ # Server configuration
75
+ LISTENING_HOST="0.0.0.0"
76
+ LISTENING_PORT=8282
77
+ """
78
+ config_env.write_text(config_content)
79
+ print(f"Created default config.env at {config_env}")
80
+ except Exception as e:
81
+ print(f"Warning: Failed to create default config.env at {config_env}: {e}")
82
+
83
+ cli_ini = dmart_home / "cli.ini"
84
+ if not cli_ini.exists():
85
+ try:
86
+ default_config = ""
87
+ sample_path = Path(__file__).resolve().parent / "config.ini.sample"
88
+ if sample_path.exists():
89
+ with open(sample_path, "r") as f:
90
+ default_config = f.read()
91
+ else:
92
+ default_config = (
93
+ 'url = "http://localhost:8282"\n'
94
+ 'shortname = "dmart"\n'
95
+ 'password = "xxxx"\n'
96
+ 'query_limit = 50\n'
97
+ 'retrieve_json_payload = True\n'
98
+ 'default_space = "management"\n'
99
+ 'pagination = 50\n'
100
+ )
101
+
102
+ login_creds_path = dmart_home / "login_creds.sh"
103
+ if login_creds_path.exists():
104
+ try:
105
+ with open(login_creds_path, "r") as f:
106
+ creds_content = f.read()
107
+
108
+ match = re.search(r"export SUPERMAN='(.*?)'", creds_content)
109
+ if match:
110
+ creds_json = match.group(1)
111
+ creds = json.loads(creds_json)
112
+ if "shortname" in creds:
113
+ default_config = re.sub(r'shortname = ".*"', f'shortname = "{creds["shortname"]}"', default_config)
114
+ if "password" in creds:
115
+ default_config = re.sub(r'password = ".*"', f'password = "{creds["password"]}"', default_config)
116
+ except Exception as e:
117
+ print(f"Warning: Failed to parse login_creds.sh: {e}")
118
+
119
+ with open(cli_ini, "w") as f:
120
+ f.write(default_config)
121
+ print(f"Created default cli.ini at {cli_ini}")
122
+ except Exception as e:
123
+ print(f"Warning: Failed to create default cli.ini at {cli_ini}: {e}")
124
+
125
+ cxb_config = dmart_home / "config.json"
126
+ if not cxb_config.exists():
127
+ try:
128
+ sample_cxb_path = Path(__file__).resolve().parent / "cxb" / "config.sample.json"
129
+ if sample_cxb_path.exists():
130
+ shutil.copy2(sample_cxb_path, cxb_config)
131
+ print(f"Created default config.json at {cxb_config}")
132
+ else:
133
+ default_cxb_config = {
134
+ "title": "DMART Unified Data Platform",
135
+ "footer": "dmart.cc unified data platform",
136
+ "short_name": "dmart",
137
+ "display_name": "dmart",
138
+ "description": "dmart unified data platform",
139
+ "default_language": "en",
140
+ "languages": { "ar": "العربية", "en": "English" },
141
+ "backend": "http://localhost:8282",
142
+ "websocket": "ws://0.0.0.0:8484/ws"
143
+ }
144
+ with open(cxb_config, "w") as f:
145
+ json.dump(default_cxb_config, f, indent=2)
146
+ print(f"Created default config.json at {cxb_config}")
147
+ except Exception as e:
148
+ print(f"Warning: Failed to create default config.json at {cxb_config}: {e}")
149
+
150
+ ensure_dmart_home()
151
+ from utils.settings import settings
49
152
 
50
153
  def hypercorn_main() -> int:
51
154
  parser = argparse.ArgumentParser()
@@ -433,49 +536,6 @@ def main():
433
536
  home_config = Path.home() / ".dmart" / "cli.ini"
434
537
  if home_config.exists():
435
538
  config_file = str(home_config)
436
- else:
437
- try:
438
- home_config.parent.mkdir(parents=True, exist_ok=True)
439
-
440
- default_config = ""
441
- sample_path = Path(__file__).resolve().parent / "config.ini.sample"
442
- if sample_path.exists():
443
- with open(sample_path, "r") as f:
444
- default_config = f.read()
445
- else:
446
- default_config = (
447
- 'url = "http://localhost:8282"\n'
448
- 'shortname = "dmart"\n'
449
- 'password = "xxxx"\n'
450
- 'query_limit = 50\n'
451
- 'retrieve_json_payload = True\n'
452
- 'default_space = "management"\n'
453
- 'pagination = 50\n'
454
- )
455
-
456
- login_creds_path = Path.home() / ".dmart" / "login_creds.sh"
457
- if login_creds_path.exists():
458
- try:
459
- with open(login_creds_path, "r") as f:
460
- creds_content = f.read()
461
-
462
- match = re.search(r"export SUPERMAN='(.*?)'", creds_content)
463
- if match:
464
- creds_json = match.group(1)
465
- creds = json.loads(creds_json)
466
- if "shortname" in creds:
467
- default_config = re.sub(r'shortname = ".*"', f'shortname = "{creds["shortname"]}"', default_config)
468
- if "password" in creds:
469
- default_config = re.sub(r'password = ".*"', f'password = "{creds["password"]}"', default_config)
470
- except Exception as e:
471
- print(f"Warning: Failed to parse login_creds.sh: {e}")
472
-
473
- with open(home_config, "w") as f:
474
- f.write(default_config)
475
- print(f"Created default config at {home_config}")
476
- config_file = str(home_config)
477
- except Exception as e:
478
- print(f"Warning: Failed to create default config at {home_config}: {e}")
479
539
 
480
540
  if config_file:
481
541
  os.environ["BACKEND_ENV"] = config_file
@@ -723,9 +783,9 @@ def main():
723
783
  if not sample_spaces_path.exists():
724
784
  print("Error: Sample spaces not found in the package.")
725
785
  sys.exit(1)
726
-
786
+
727
787
  target_path = Path.home() / ".dmart" / "spaces"
728
-
788
+
729
789
  try:
730
790
  if target_path.exists():
731
791
  shutil.rmtree(target_path)
dmart/main.py CHANGED
@@ -41,6 +41,7 @@ from api.public.router import router as public
41
41
  from api.user.router import router as user
42
42
  from api.info.router import router as info, git_info
43
43
  from utils.internal_error_code import InternalErrorCode
44
+ from pathlib import Path
44
45
 
45
46
 
46
47
  class SPAStaticFiles(StaticFiles):
@@ -503,6 +504,10 @@ if os.path.isdir(cxb_path):
503
504
  if user_config.exists():
504
505
  return FileResponse(user_config)
505
506
 
507
+ home_config = Path.home() / ".dmart" / "config.json"
508
+ if home_config.exists():
509
+ return FileResponse(home_config)
510
+
506
511
  bundled_config = os.path.join(cxb_path, "config.json")
507
512
  if os.path.exists(bundled_config):
508
513
  return FileResponse(bundled_config)
dmart/utils/settings.py CHANGED
@@ -5,7 +5,6 @@ import os
5
5
  import random
6
6
  import re
7
7
  import string
8
- import secrets
9
8
  from venv import logger
10
9
 
11
10
  from pydantic import Field
@@ -25,36 +24,6 @@ def get_env_file():
25
24
  dmart_home = Path.home() / ".dmart"
26
25
  home_config = dmart_home / "config.env"
27
26
 
28
- if not home_config.exists():
29
- if not (os.path.exists(".git") or os.path.exists("setup.py")):
30
- try:
31
- dmart_home.mkdir(parents=True, exist_ok=True)
32
- (dmart_home / "logs").mkdir(parents=True, exist_ok=True)
33
- (dmart_home / "spaces").mkdir(parents=True, exist_ok=True)
34
- (dmart_home / "spaces" / "custom_plugins").mkdir(parents=True, exist_ok=True)
35
-
36
- jwt_secret = secrets.token_urlsafe(32)
37
-
38
- config_content = f"""# dmart configuration
39
- JWT_SECRET="{jwt_secret}"
40
- JWT_ALGORITHM="HS256"
41
- LOG_FILE="{dmart_home / 'logs' / 'dmart.ljson.log'}"
42
- WS_LOG_FILE="{dmart_home / 'logs' / 'websocket.ljson.log'}"
43
-
44
- # Database configuration
45
- ACTIVE_DATA_DB="file"
46
- SPACES_FOLDER="{dmart_home / 'spaces'}"
47
- DATABASE_DRIVER="sqlite+pysqlite"
48
- DATABASE_NAME="{dmart_home / 'dmart.db'}"
49
-
50
- # Server configuration
51
- LISTENING_HOST="0.0.0.0"
52
- LISTENING_PORT=8282
53
- """
54
- home_config.write_text(config_content)
55
- except Exception:
56
- pass
57
-
58
27
  if home_config.exists():
59
28
  return str(home_config)
60
29
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dmart
3
- Version: 1.4.40.post32
3
+ Version: 1.4.40.post33
4
4
  Requires-Python: >=3.11
5
5
  Requires-Dist: fastapi
6
6
  Requires-Dist: pydantic
@@ -8,13 +8,13 @@ dmart/conftest.py,sha256=0ry_zeCmdBNLbm5q115b-pkOrUFYxdsOUXbIMkr7E5Y,362
8
8
  dmart/curl.pypi.sh,sha256=KQ-kgV3_d5mwqoLd4XOwz5s2wRQ7LDVX3z-kvjvp9hA,15631
9
9
  dmart/curl.sh,sha256=lmHSFVr5ft-lc5Aq9LfvKyWfntrfYbnirhzx1EGjp_A,15743
10
10
  dmart/data_generator.py,sha256=CnE-VHEeX7-lAXtqCgbRqR9WHjTuOgeiZcviYrHAmho,2287
11
- dmart/dmart.py,sha256=woSheqlEHQPGmBPLcOPjjo0tDq8s6XINTUqYX2G4PVM,32105
11
+ dmart/dmart.py,sha256=IJ1PIoP0OcxXWnIhAugWwSq73gYA4dwI8D4-1LSbuK8,33797
12
12
  dmart/get_settings.py,sha256=Sbe2WCoiK398E7HY4SNLfDN_GmE8knR4M-YJWF31jcg,153
13
13
  dmart/hypercorn_config.toml,sha256=-eryppEG8HBOM_KbFc4dTQePnpyfoW9ZG5aUATU_6yM,50
14
14
  dmart/info.json,sha256=MM4SvhU44LXhSt8jMf8RX_XxQlfPAJkeQSshgBUjz0o,124
15
15
  dmart/login_creds.sh,sha256=Aht1LwL11uzR13sa8p3BdeUCprIa9tq0vzOoplJjH5U,235
16
16
  dmart/login_creds.sh.sample,sha256=Sb43HNNn1g11rrJrtDsPgAxcXu3_wJvdNn--8S62dTE,227
17
- dmart/main.py,sha256=yvbEoPfcUdzE65OCiDkP143AQvXWWsnVjlLPfZ9DFzA,19907
17
+ dmart/main.py,sha256=EMsrV57yAf_LZbM-dY9ZkD6oEAFmdhIUQn9l81vmVn4,20072
18
18
  dmart/manifest.sh,sha256=K3mY5MsUlrTyHa5cARslkShegvXh-UeqJcE2UZobdrE,544
19
19
  dmart/migrate.py,sha256=hn1MZoVby_Jjqhc7y3CrLcGD619QmVZv3PONNvO7VKQ,665
20
20
  dmart/password_gen.py,sha256=xjx8wi105ZYvhLBBQj7_rugACpxifGXHse6f7YlGXWQ,196
@@ -476,15 +476,15 @@ dmart/utils/query_policies_helper.py,sha256=Bf5qriQJ8CpUqPaQg5cdvNrn-92l_jKxHwsv
476
476
  dmart/utils/regex.py,sha256=cv9b_l_e8tz42mKckeeyDgypKqh2e71E28co2iuEVxA,2286
477
477
  dmart/utils/repository.py,sha256=9L-IvQ0Js0SQ5OR-Rh0i2Wdu4H9H06r8eE84hfBIu7Q,18313
478
478
  dmart/utils/router_helper.py,sha256=Tgoq3oakejdEeyeVieTNk38JsPZ8x5RuR0kw2THc1mI,604
479
- dmart/utils/settings.py,sha256=_8WH9EvvO6R3Y7ddoWYTvvdFqVJM1-qeq-c6EV72968,7193
479
+ dmart/utils/settings.py,sha256=TOlW_ZWYQ_KyelPWCDg30V-fa1jsgazlek8agAPgkQ0,6036
480
480
  dmart/utils/sms_notifier.py,sha256=04D6D_ldk3S9SojI7_381pqLc8v9lligeNHAysohz7w,550
481
481
  dmart/utils/social_sso.py,sha256=Dm1W6U9OwKbAeUwM-kwJBHFEoreeoN-s-RHdOZ1-cNg,2216
482
482
  dmart/utils/ticket_sys_utils.py,sha256=9QAlW2iiy8KyxQRBDj_WmzS5kKb0aYJmGwd4qzmGVqo,7005
483
483
  dmart/utils/web_notifier.py,sha256=QM87VVid2grC5lK3NdS1yzz0z1wXljr4GChJOeK86W4,843
484
484
  dmart/utils/templates/activation.html.j2,sha256=XAMKCdoqONoc4ZQucD0yV-Pg5DlHHASZrTVItNS-iBE,640
485
485
  dmart/utils/templates/reminder.html.j2,sha256=aoS8bTs56q4hjAZKsb0jV9c-PIURBELuBOpT_qPZNVU,639
486
- dmart-1.4.40.post32.dist-info/METADATA,sha256=bXhmZ_knI4V33rfMalEMvh4WgR2lZbDJr7MwUAV8boE,839
487
- dmart-1.4.40.post32.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
488
- dmart-1.4.40.post32.dist-info/entry_points.txt,sha256=N832M4wG8d2GDw1xztKRVM3TnxpY2QDzvdFE8XaWaG8,43
489
- dmart-1.4.40.post32.dist-info/top_level.txt,sha256=zJo4qk9fUW0BGIR9f4DCfpxaXbvQXH9izIOom6JsyAo,6
490
- dmart-1.4.40.post32.dist-info/RECORD,,
486
+ dmart-1.4.40.post33.dist-info/METADATA,sha256=vst7VgejZJeBryCl7eW3Oln7i6Fa4cKa1JNQrHTKSOg,839
487
+ dmart-1.4.40.post33.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
488
+ dmart-1.4.40.post33.dist-info/entry_points.txt,sha256=N832M4wG8d2GDw1xztKRVM3TnxpY2QDzvdFE8XaWaG8,43
489
+ dmart-1.4.40.post33.dist-info/top_level.txt,sha256=zJo4qk9fUW0BGIR9f4DCfpxaXbvQXH9izIOom6JsyAo,6
490
+ dmart-1.4.40.post33.dist-info/RECORD,,