2025-02-12 17:36:12 +01:00
|
|
|
#!/bin/env python3
|
|
|
|
import sys
|
|
|
|
from os import listdir
|
|
|
|
from os.path import isfile, join
|
|
|
|
from debian import parse_debian
|
|
|
|
from freebsd import parse_freebsd
|
|
|
|
from freebox import parse_freebox
|
2025-02-14 21:11:21 +01:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
2025-02-12 17:36:12 +01:00
|
|
|
|
|
|
|
def find_os(content):
|
|
|
|
version = content.split("###### VERSION ######")[-1]
|
|
|
|
osystem = [line.split("=")[-1] for line in version.splitlines() if line.startswith("ID=")]
|
|
|
|
if osystem:
|
|
|
|
return osystem[0]
|
|
|
|
else:
|
|
|
|
return "freebox"
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
mypath = "../oxidized/"
|
|
|
|
|
|
|
|
onlyfiles = [mypath + f for f in listdir(mypath) if isfile(join(mypath, f))]
|
2025-02-14 21:11:21 +01:00
|
|
|
env = Environment(loader = FileSystemLoader('../template'))
|
2025-02-12 17:36:12 +01:00
|
|
|
|
|
|
|
for file in onlyfiles:
|
|
|
|
with open(file,"r") as f:
|
|
|
|
content = f.read()
|
|
|
|
current_os = find_os(content)
|
|
|
|
if "freebsd" in current_os:
|
2025-02-14 21:11:21 +01:00
|
|
|
infos = parse_freebsd(content)
|
|
|
|
template = env.get_template('freebsd.rst.j2')
|
|
|
|
output = template.render(**infos)
|
|
|
|
print(output)
|
2025-02-12 17:36:12 +01:00
|
|
|
elif "debian" in current_os:
|
2025-02-14 21:11:21 +01:00
|
|
|
infos = parse_debian(content)
|
|
|
|
template = env.get_template('debian.rst.j2')
|
|
|
|
output = template.render(**infos)
|
|
|
|
print(output)
|
|
|
|
|
2025-02-12 17:36:12 +01:00
|
|
|
else:
|
|
|
|
parse_freebox(content)
|
2025-02-14 21:11:21 +01:00
|
|
|
with open("../source/devices/{host}.rst".format(host=infos["hostname"].replace("\n","")), "w") as f:
|
|
|
|
f.write(output)
|
2025-02-12 17:36:12 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
|