commit 8090c2e5eab69a48aeb34a1be64d7a2471d03325 Author: George Date: Fri Jun 19 16:37:34 2026 +0530 feat: --Addded version manager --Parser diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e1144ad --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +venv/ + +# Docker compose file +compose_changes.json + +docker-compose.yml + +# Python cache +__pycache__/ +*.pyc + + +# IDE files +.vscode/ +.idea/ \ No newline at end of file diff --git a/dockerConfig.py b/dockerConfig.py new file mode 100644 index 0000000..04ba71b --- /dev/null +++ b/dockerConfig.py @@ -0,0 +1,71 @@ +import re +import json +import os +from datetime import datetime + +COMPOSE_FILE = "docker-compose.yml" +JSON_FILE = "compose_changes.json" + + + +def read_json(): + if not os.path.exists(JSON_FILE): + return {"file": "docker-compose.yml", "version": 0} + with open(JSON_FILE) as f: + return json.load(f) + + + +def write_json(changes): + data = read_json() + data["version"] += 1 + data["last_updated"] = datetime.now().isoformat() + with open(JSON_FILE, "w") as f: + json.dump(data, f, indent=2) + return data["version"] + +def update_compose( + icesecretwrite=None, + icesecretread=None, + dbDriver=None, + dbHost=None, + dbPort=None, + database=None, + dbUsername=None, + dbPassword=None +): + with open(COMPOSE_FILE, "r") as f: + content = f.read() + + changes = { + "MUMBLE_CONFIG_icesecretwrite": icesecretwrite, + "MUMBLE_CONFIG_icesecretread": icesecretread, + "MUMBLE_CONFIG_dbDriver": dbDriver, + "MUMBLE_CONFIG_dbHost": dbHost, + "MUMBLE_CONFIG_dbPort": dbPort, + "MUMBLE_CONFIG_database": database, + "MUMBLE_CONFIG_dbUsername": dbUsername, + "MUMBLE_CONFIG_dbPassword": dbPassword, + } + + for key, value in changes.items(): + if value is None: + continue # skip fields not passed in + # replace the value after the = sign + content = re.sub( + rf"({key}=).*", + rf"\g<1>{value}", + content + ) + + with open(COMPOSE_FILE, "w") as f: + f.write(content) + version = write_json(changes) + print(f"[✓] docker-compose.yml updated") + +# --- usage --- +update_compose( + dbHost="172.test.test.test", + dbPassword="testpassword", + dbPort="5437test" +) \ No newline at end of file