Repository navigation
Expand file tree
/
Copy pathlauncher.py
More file actions
109 lines (92 loc) · 3.17 KB
/
Copy pathlauncher.py
File metadata and controls
109 lines (92 loc) · 3.17 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
"""
KnowledgeDigest -- GUI Launcher.
Erstellt fehlende Ordner/Dateien und startet die GUI.
Wird zu einer EXE kompiliert fuer einfachen Start per Doppelklick.
"""
import os
import sys
import json
from pathlib import Path
def get_base_dir():
"""Ermittelt das Basisverzeichnis (neben der EXE oder neben launcher.py)."""
if getattr(sys, "frozen", False):
# PyInstaller EXE
return Path(sys.executable).parent
else:
return Path(__file__).parent
def ensure_structure(base: Path):
"""Erstellt fehlende Ordner und Dateien."""
# Ordner
dirs = [
base / "data",
base / "data" / "inbox",
base / "data" / "archive",
]
for d in dirs:
d.mkdir(parents=True, exist_ok=True)
# Config-Datei
config_path = base / "data" / "knowledgedigest.json"
if not config_path.exists():
default_config = {
"db_path": "",
"indexed_directories": [],
"inbox_dir": "",
"archive_dir": "",
"bach_db_path": "",
"bach_enabled": False,
"chunk_size": 350,
"chunk_overlap": 0,
"auto_archive": True,
"recursive_scan": True,
"min_words": 10,
"summarize_model": "claude-haiku-4-5",
"summarize_delay": 0.5,
"web_port": 8787,
"web_auto_open": True,
"window_geometry": None,
"window_state": None,
"splitter_sizes": [220, 350, 430],
"theme": "dark",
"font_size": 10,
"recent_searches": [],
}
config_path.write_text(json.dumps(default_config, indent=2, ensure_ascii=False), encoding="utf-8")
print(f"Config erstellt: {config_path}")
# .gitkeep
gitkeep = base / "data" / ".gitkeep"
if not gitkeep.exists():
gitkeep.touch()
def main():
base = get_base_dir()
print("KnowledgeDigest Launcher")
print(f"Basis: {base}")
# Struktur sicherstellen
ensure_structure(base)
# Sicherstellen dass das Paket importierbar ist.
# Das Package liegt im Ordner ".db" (kein gueltiger Python-Name), wird aber
# als "KnowledgeDigest" importiert. Loesung: .db-Verzeichnis direkt importieren
# und unter dem Alias "KnowledgeDigest" in sys.modules registrieren.
if str(base.parent) not in sys.path:
sys.path.insert(0, str(base.parent))
if str(base) not in sys.path:
sys.path.insert(0, str(base))
# Alias: ".db"-Package als "KnowledgeDigest" im Import-System registrieren
import importlib.util
if "KnowledgeDigest" not in sys.modules:
spec = importlib.util.spec_from_file_location(
"KnowledgeDigest",
str(base / "__init__.py"),
submodule_search_locations=[str(base)],
)
pkg = importlib.util.module_from_spec(spec)
pkg.__path__ = [str(base)]
pkg.__package__ = "KnowledgeDigest"
sys.modules["KnowledgeDigest"] = pkg
spec.loader.exec_module(pkg)
# GUI starten
os.environ["PYTHONIOENCODING"] = "utf-8"
from KnowledgeDigest.gui.app import launch_gui
sys.exit(launch_gui())
if __name__ == "__main__":
main()