doc_infra/parsers/debian.py

44 lines
1.3 KiB
Python
Raw Normal View History

#!/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
2025-02-28 10:34:41 +01:00
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:
2025-02-14 21:11:21 +01:00
result[current_section] += line + "\n"
2025-02-27 11:25:49 +01:00
for section in result:
print(" parsing {}...".format(section))
2025-02-28 11:03:49 +01:00
if section in ["resolvconf","services","routes", "docker"]:
2025-02-27 11:25:49 +01:00
result[section] = loads(result[section])
2025-02-14 21:11:21 +01:00
result["ip"] = parse_ip(result["ip"])
2025-02-27 11:47:34 +01:00
result["os"] = loads(result["version"])
2025-02-14 21:11:21 +01:00
return result
if __name__ == "__main__":
main()