-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (46 loc) · 1.61 KB
/
main.py
File metadata and controls
56 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# main.py
try:
import setup_path # يضيف مجلد المشروع إلى sys.path
except ImportError:
import os, sys
ROOT = os.path.abspath(os.path.dirname(__file__))
if ROOT not in sys.path:
sys.path.insert(0, ROOT)
import os
import importlib
def show_main_menu():
print("=== Project Tools ===")
base_package = "tools.db"
base_path = os.path.join(os.path.dirname(__file__), "tools", "db")
# البحث عن مجلدات فيها main.py
entries = [
name for name in os.listdir(base_path)
if os.path.isdir(os.path.join(base_path, name))
and "main.py" in os.listdir(os.path.join(base_path, name))
]
actions = {}
print("0. Quit")
for i, entry in enumerate(entries, start=1):
label = entry.replace("_", " ").capitalize()
actions[str(i)] = entry
print(f"{i}. {label}")
choice = input("Select: ").strip()
if choice == "0":
print("Goodbye!")
return
elif choice in actions:
module_name = f"{base_package}.{actions[choice]}.main"
try:
module = importlib.import_module(module_name)
# يبحث عن دالة تشغيل مناسبة
for fn in ("run", "main", "start", "menu", "show_menu"):
if hasattr(module, fn):
getattr(module, fn)()
return
print(f"❌ Module '{module_name}' has no entry point.")
except Exception as e:
print(f"❌ Failed to load module '{module_name}': {e}")
else:
print("Invalid choice.")
if __name__ == "__main__":
show_main_menu()