From 600f8311d55f2bd1358fb8ad4bbcda5b4cdc17e2 Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Sat, 15 Apr 2023 12:25:10 +0200 Subject: [PATCH] added an script to update the module documentation. this is only compatible with the Module class --- update_doc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 update_doc diff --git a/update_doc b/update_doc new file mode 100755 index 0000000..f21d90a --- /dev/null +++ b/update_doc @@ -0,0 +1,31 @@ +#!/usr/bin/python +import re +import pathlib +import importlib +import sys + +sys.path.append("plugins") +mindocstring = "DOCUMENTATION = ''''''" + +moduledir = pathlib.Path("plugins/modules") +regex = re.compile("DOCUMENTATION *= *r?(?P\"{3}|'{3})(---)?.*?(?P=quote)", re.MULTILINE | re.DOTALL) + +if __name__ == "__main__": + for modfile in moduledir.iterdir(): + if modfile.name in ( "__init__.py", "__pycache__"): + continue + mod = importlib.import_module("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 \ No newline at end of file