2023-04-15 10:25:10 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
import importlib
|
2023-04-20 20:09:58 +00:00
|
|
|
import pathlib
|
|
|
|
import re
|
2023-04-15 10:25:10 +00:00
|
|
|
import sys
|
|
|
|
|
2023-04-15 17:02:20 +00:00
|
|
|
sys.path.append(".")
|
2023-04-15 22:10:13 +00:00
|
|
|
mindocstring = "DOCUMENTATION = ''''''"
|
2023-04-15 10:25:10 +00:00
|
|
|
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():
|
2023-04-23 07:36:24 +00:00
|
|
|
if modfile.name in ( "__init__.py", "__pycache__", "unit.py.example"):
|
2023-04-15 10:25:10 +00:00
|
|
|
continue
|
2023-04-15 22:10:13 +00:00
|
|
|
mod = importlib.import_module(".".join((modfile.parts[:-1])+(modfile.stem,)))
|
2023-04-15 10:25:10 +00:00
|
|
|
if hasattr(mod, "Module"):
|
|
|
|
module = mod.Module
|
|
|
|
elif hasattr(mod, "__module_name__"):
|
|
|
|
module = getattr(mod, mod.__module_name__)
|
2023-04-15 22:10:13 +00:00
|
|
|
else:
|
|
|
|
print("Error loading Module of File: {}. No Module or __module_name__ defined".format(modfile))
|
|
|
|
continue
|
2023-04-20 20:09:58 +00:00
|
|
|
try:
|
|
|
|
moddoc = module.doc()
|
|
|
|
except AttributeError:
|
|
|
|
print("Broken module. skipping {}".format(modfile))
|
2023-04-20 20:10:43 +00:00
|
|
|
continue
|
2023-04-20 22:17:54 +00:00
|
|
|
except Exception as e:
|
|
|
|
print("Error in documentation of module {}: {}".format(modfile, e))
|
|
|
|
continue
|
2023-04-15 10:25:10 +00:00
|
|
|
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)
|
2023-04-23 07:36:24 +00:00
|
|
|
print("updated the documentation of module {}".format(module.name))
|
2023-04-15 10:25:10 +00:00
|
|
|
|
2023-04-20 22:17:54 +00:00
|
|
|
# code: python
|