From 351c12eed18c6e594f514976653876c8cf50cf74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Ricart?= Date: Fri, 28 Feb 2025 10:34:41 +0100 Subject: [PATCH] [DEBIAN] add docker parsing json --- parsers/base.py | 12 +++++++++--- parsers/debian.py | 9 ++++++++- template/base.rst.j2 | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/parsers/base.py b/parsers/base.py index 4b4c85d..55f6798 100644 --- a/parsers/base.py +++ b/parsers/base.py @@ -35,14 +35,20 @@ def main(): current_os = find_os(content) if "freebsd" in current_os: infos = parse_freebsd(content) + infos["extend_exists"] = False template = env.get_template('freebsd.rst.j2') - output = template.render(**infos) elif "debian" in current_os: infos = parse_debian(content) + infos["extend_exists"] = False template = env.get_template('debian.rst.j2') - output = template.render(**infos) else: - parse_freebox(content) + infos = parse_freebox(content) + infos = { + "hostname":"Freebox", + "os":{"NAME":"FreeboxOS","VERSION":"None"}, + } + infos["extend_exists"] = False + output = template.render(**infos) with open("../source/devices/{host}.rst".format(host=infos["hostname"].replace("\n","")), "w") as f: f.write(output) diff --git a/parsers/debian.py b/parsers/debian.py index 5144f96..c660720 100644 --- a/parsers/debian.py +++ b/parsers/debian.py @@ -13,6 +13,13 @@ def parse_ip(raw_ip): 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 = {} @@ -24,7 +31,7 @@ def parse_debian(content): if current_section: result[current_section] += line + "\n" for section in result: - if section in ["services","routes"]: + if section in ["services","routes", "docker"]: result[section] = loads(result[section]) result["ip"] = parse_ip(result["ip"]) result["os"] = loads(result["version"]) diff --git a/template/base.rst.j2 b/template/base.rst.j2 index 6822a35..8e1a2d8 100644 --- a/template/base.rst.j2 +++ b/template/base.rst.j2 @@ -5,3 +5,5 @@ :os: {{ os["NAME"] }} :version: {{ os["VERSION"] }} +{% if extend_exists %}{% include "{hostname}.rst.j2".format(hostname=hostname) %}{% endif %} +