-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapply_setup_config.py
More file actions
63 lines (54 loc) · 3.01 KB
/
Copy pathapply_setup_config.py
File metadata and controls
63 lines (54 loc) · 3.01 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
"""
apply_setup_config.py — Applique la configuration IA + fédération
Appelé par SETUP.bat après la saisie interactive des paramètres.
Lit les variables d'environnement définies par le BAT et met à jour config.js.
"""
import os, sys, re
config_js_path = os.path.join(os.path.dirname(__file__), 'app', 'static', 'config.js')
if not os.path.exists(config_js_path):
print("[WARN] config.js introuvable - sera généré au prochain setup.py")
sys.exit(0)
with open(config_js_path, 'r', encoding='utf-8') as f:
cjs = f.read()
changes = []
# ── IA ──────────────────────────────────────────────────────────────
ia_fournisseur = os.environ.get('IA_FOURNISSEUR', '').strip()
ia_key = os.environ.get('IA_KEY', '').strip()
ia_url = os.environ.get('IA_URL', '').strip()
ia_model = os.environ.get('IA_MODEL', '').strip()
if ia_fournisseur and ia_fournisseur != '4':
if ia_fournisseur in ('albert','openai','anthropic','mistral','gemini','ollama','openai_compat'):
cjs = re.sub(r'(ia_fournisseur\s*:\s*")[^"]*(")', f'\\g<1>{ia_fournisseur}\\2', cjs)
changes.append(f"IA: {ia_fournisseur}")
if ia_key and ia_key != 'none':
cjs = re.sub(r'(ia_cle_api\s*:\s*")[^"]*(")', f'\\g<1>{ia_key}\\2', cjs)
changes.append("cle API configuree")
if ia_url:
cjs = re.sub(r'(ia_url_base\s*:\s*")[^"]*(")', f'\\g<1>{ia_url}\\2', cjs)
if ia_model:
cjs = re.sub(r'(ia_modele\s*:\s*")[^"]*(")', f'\\g<1>{ia_model}\\2', cjs)
# ── FEDERATION ──────────────────────────────────────────────────────
fed_enabled = os.environ.get('FED_ENABLED', 'false').strip().lower()
fed_ip = os.environ.get('FED_IP', '').strip()
fed_port = os.environ.get('FED_PORT', '9000').strip()
fed_token = os.environ.get('FED_TOKEN', '').strip()
sync_crise = os.environ.get('SYNC_CRISE', 'false').strip().lower()
sync_sanit = os.environ.get('SYNC_SANITAIRE', 'false').strip().lower()
if fed_enabled == 'true' and fed_ip:
url_push = f'http://{fed_ip}:{fed_port}/api/push'
cjs = re.sub(r'(federation_enabled\s*:\s*)[^,\n]+', r'\g<1>true', cjs)
cjs = re.sub(r'(collecteur_url\s*:\s*")[^"]*(")', f'\\g<1>{url_push}\\2', cjs)
if fed_token:
cjs = re.sub(r'(federation_token\s*:\s*")[^"]*(")', f'\\g<1>{fed_token}\\2', cjs)
cjs = re.sub(r'(sync_crise\s*:\s*)[^,\n]+', f'\\g<1>{sync_crise}', cjs)
cjs = re.sub(r'(sync_sanitaire\s*:\s*)[^,\n]+', f'\\g<1>{sync_sanit}', cjs)
changes.append(f"federation → {fed_ip}:{fed_port}")
if sync_crise == 'true': changes.append("sync crise")
if sync_sanit == 'true': changes.append("sync sanitaire")
with open(config_js_path, 'w', encoding='utf-8') as f:
f.write(cjs)
if changes:
for c in changes:
print(f" [OK] {c}")
else:
print(" [OK] Aucune modification (pas de parametre saisi)")