2026-03-06 14:50:02 -05:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
import re
|
|
|
|
|
|
import sys
|
|
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
|
|
|
|
INPUT_FILE = Path("domains.yaml")
|
|
|
|
|
|
OUTPUT_DIR = Path("bpm")
|
2026-03-14 15:31:28 -04:00
|
|
|
|
OUTPUT_FILE = OUTPUT_DIR / "Life-NOC.conf"
|
2026-03-06 14:50:02 -05:00
|
|
|
|
HOST_NAME = "life-noc"
|
2026-03-14 15:31:28 -04:00
|
|
|
|
TITLE = "Life-NOC"
|
|
|
|
|
|
OWNER = "icingadmin"
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def slugify(value: str) -> str:
|
|
|
|
|
|
value = value.strip().lower()
|
|
|
|
|
|
replacements = {
|
|
|
|
|
|
"à": "a", "â": "a", "ä": "a",
|
|
|
|
|
|
"ç": "c",
|
|
|
|
|
|
"é": "e", "è": "e", "ê": "e", "ë": "e",
|
|
|
|
|
|
"î": "i", "ï": "i",
|
|
|
|
|
|
"ô": "o", "ö": "o",
|
|
|
|
|
|
"ù": "u", "û": "u", "ü": "u",
|
|
|
|
|
|
"ÿ": "y",
|
|
|
|
|
|
"œ": "oe",
|
|
|
|
|
|
"æ": "ae",
|
|
|
|
|
|
"'": "",
|
|
|
|
|
|
"’": "",
|
|
|
|
|
|
}
|
|
|
|
|
|
for old, new in replacements.items():
|
|
|
|
|
|
value = value.replace(old, new)
|
|
|
|
|
|
value = re.sub(r"[^a-z0-9\-]+", "-", value)
|
|
|
|
|
|
value = re.sub(r"-{2,}", "-", value)
|
|
|
|
|
|
return value.strip("-")
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
def aliasify(value: str) -> str:
|
|
|
|
|
|
value = value.strip().upper()
|
|
|
|
|
|
replacements = {
|
|
|
|
|
|
"À": "A", "Â": "A", "Ä": "A",
|
|
|
|
|
|
"Ç": "C",
|
|
|
|
|
|
"É": "E", "È": "E", "Ê": "E", "Ë": "E",
|
|
|
|
|
|
"Î": "I", "Ï": "I",
|
|
|
|
|
|
"Ô": "O", "Ö": "O",
|
|
|
|
|
|
"Ù": "U", "Û": "U", "Ü": "U",
|
|
|
|
|
|
"Ÿ": "Y",
|
|
|
|
|
|
"Œ": "OE",
|
|
|
|
|
|
"Æ": "AE",
|
|
|
|
|
|
"'": "",
|
|
|
|
|
|
"’": "",
|
2026-03-06 14:50:02 -05:00
|
|
|
|
}
|
2026-03-14 15:31:28 -04:00
|
|
|
|
for old, new in replacements.items():
|
|
|
|
|
|
value = value.replace(old, new)
|
|
|
|
|
|
value = re.sub(r"[^A-Z0-9\-]+", "-", value)
|
|
|
|
|
|
value = re.sub(r"-{2,}", "-", value)
|
|
|
|
|
|
return value.strip("-")
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
def header() -> str:
|
|
|
|
|
|
return f"""### Business Process Config File ###
|
|
|
|
|
|
#
|
|
|
|
|
|
# Title : {TITLE}
|
|
|
|
|
|
# Description :
|
|
|
|
|
|
# Owner : {OWNER}
|
|
|
|
|
|
# AddToMenu : yes
|
|
|
|
|
|
# Backend :
|
|
|
|
|
|
# Statetype : soft
|
|
|
|
|
|
#
|
|
|
|
|
|
###################################
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
"""
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> int:
|
|
|
|
|
|
if not INPUT_FILE.exists():
|
|
|
|
|
|
print(f"Erreur: fichier introuvable: {INPUT_FILE}", file=sys.stderr)
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
with INPUT_FILE.open("r", encoding="utf-8") as f:
|
|
|
|
|
|
data = yaml.safe_load(f)
|
|
|
|
|
|
|
|
|
|
|
|
if not isinstance(data, dict) or "domains" not in data:
|
|
|
|
|
|
print("Erreur: le YAML doit contenir une clé racine 'domains'.", file=sys.stderr)
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
domains = data["domains"]
|
|
|
|
|
|
if not isinstance(domains, dict):
|
|
|
|
|
|
print("Erreur: 'domains' doit être un objet YAML.", file=sys.stderr)
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
lines = [header()]
|
|
|
|
|
|
aliases = []
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
for raw_domain, items in domains.items():
|
|
|
|
|
|
if not isinstance(items, list):
|
2026-03-06 14:50:02 -05:00
|
|
|
|
print(f"Erreur: le domaine '{raw_domain}' doit contenir une liste.", file=sys.stderr)
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
domain_slug = slugify(str(raw_domain))
|
|
|
|
|
|
domain_alias = aliasify(str(raw_domain))
|
|
|
|
|
|
|
|
|
|
|
|
services = []
|
|
|
|
|
|
for idx, item in enumerate(items, start=1):
|
2026-03-06 14:50:02 -05:00
|
|
|
|
if not isinstance(item, dict):
|
|
|
|
|
|
print(f"Erreur: entrée invalide dans '{raw_domain}' à la position {idx}.", file=sys.stderr)
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
if "name" not in item:
|
|
|
|
|
|
print(f"Erreur: dans le domaine '{raw_domain}', entrée {idx}, champ manquant: name", file=sys.stderr)
|
|
|
|
|
|
return 1
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
item_name = slugify(str(item["name"]))
|
|
|
|
|
|
services.append(f"{HOST_NAME};{domain_slug}-{item_name}")
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
if not services:
|
|
|
|
|
|
print(f"Erreur: le domaine '{raw_domain}' ne contient aucun item.", file=sys.stderr)
|
|
|
|
|
|
return 1
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
expr = " & ".join(services)
|
|
|
|
|
|
lines.append(f"{domain_alias} = {expr}\n")
|
|
|
|
|
|
aliases.append((domain_alias, str(raw_domain).upper()))
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
lines.append("\n")
|
|
|
|
|
|
for alias, label in aliases:
|
|
|
|
|
|
lines.append(f"display 1;{alias};{label}\n")
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
2026-03-14 15:31:28 -04:00
|
|
|
|
OUTPUT_FILE.write_text("".join(lines), encoding="utf-8")
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
|
|
|
|
|
print(f"BPM généré: {OUTPUT_FILE}")
|
|
|
|
|
|
print("Processus générés :")
|
|
|
|
|
|
print(" - LIFE-NOC")
|
2026-03-14 15:31:28 -04:00
|
|
|
|
for alias, _label in aliases:
|
|
|
|
|
|
print(f" - {alias}")
|
2026-03-06 14:50:02 -05:00
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
raise SystemExit(main())
|