doc_infra/parsers/debian.py
Michaël Ricart 4aef2d63ef
All checks were successful
/ test (push) Successful in 13s
[DEBIAN] fix DNS template
2025-02-28 11:03:49 +01:00

42 lines
1.2 KiB
Python

#!/bin/env python3
from json import loads
def parse_ip(raw_ip):
result = []
ip = loads(raw_ip)
for interface in ip:
if not interface["ifname"].startswith("br-")\
and not interface["ifname"].startswith("vet") \
and not interface["ifname"].startswith("dock") \
and interface["operstate"] != "DOWN" \
:
result.append(interface)
return result
def parse_docker(raw_docker):
result = []
for line in raw_docker.splitlines():
print(line)
result.append(loads(line))
return result
def parse_debian(content):
current_section = ""
result = {}
for line in content.splitlines():
if line.startswith("#####") and line.endswith("#####"):
current_section = line.replace(" ","").replace("#","").lower()
result[current_section] = ""
else:
if current_section:
result[current_section] += line + "\n"
for section in result:
if section in ["resolvconf","services","routes", "docker"]:
result[section] = loads(result[section])
result["ip"] = parse_ip(result["ip"])
result["os"] = loads(result["version"])
return result
if __name__ == "__main__":
main()