1
0
Fork 0
ansible-systemd/update_doc

33 Zeilen
1.2 KiB
Plaintext

#!/usr/bin/python
import re
import pathlib
import importlib
import sys
2023-04-15 17:02:20 +00:00
import ansible.module_utils
mindocstring = "DOCUMENTATION = ''''''"
2023-04-15 17:02:20 +00:00
sys.path.append("plugins/modules")
sys.path.append(".")
moduledir = pathlib.Path("plugins/modules")
regex = re.compile("DOCUMENTATION *= *r?(?P<quote>\"{3}|'{3})(---)?.*?(?P=quote)", re.MULTILINE | re.DOTALL)
if __name__ == "__main__":
for modfile in moduledir.iterdir():
if modfile.name in ( "__init__.py", "__pycache__"):
continue
2023-04-15 17:02:20 +00:00
mod = importlib.import_module("plugins.modules."+modfile.stem)
if hasattr(mod, "Module"):
module = mod.Module
elif hasattr(mod, "__module_name__"):
module = getattr(mod, mod.__module_name__)
moddoc = module.doc()
moddata = modfile.read_text()
match = regex.search(moddata)
if not match:
print("no Documentation set for module {}. Please add at least \"{}\" to the file".format(modfile.stem, mindocstring))
continue
newmod = "{pre}DOCUMENTATION = {quote}{doc}{quote}{post}".format(pre=moddata[:match.start()], quote=match.group("quote"), doc=moddoc, post=moddata[match.end():])
modfile.write_text(newmod)
# code: python