mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-12-17 06:13:00 +00:00
Finished optimization for today
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
import os
|
||||
import yaml
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
def convert_md_to_rst(md_content):
|
||||
"""Convert Markdown content to reStructuredText using Pandoc."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["pandoc", "-f", "markdown", "-t", "rst"],
|
||||
input=md_content.encode("utf-8"),
|
||||
capture_output=True,
|
||||
check=True
|
||||
)
|
||||
return result.stdout.decode("utf-8")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Error converting Markdown to reStructuredText:", e)
|
||||
return md_content # Falls Pandoc fehlschlägt, nutze das Original als Fallback
|
||||
|
||||
def generate_ansible_roles_doc(roles_dir, output_dir):
|
||||
"""Generates reStructuredText documentation for Ansible roles."""
|
||||
@@ -18,18 +33,27 @@ def generate_ansible_roles_doc(roles_dir, output_dir):
|
||||
|
||||
role_doc = os.path.join(output_dir, f"{role}.rst")
|
||||
with open(role_doc, "w", encoding="utf-8") as f:
|
||||
# Hauptüberschrift
|
||||
f.write(f"{role.capitalize()} Role\n")
|
||||
f.write("=" * (len(role) + 7) + "\n\n")
|
||||
|
||||
f.write(f"**Description:** {meta_data.get('description', 'No description available')}\n\n")
|
||||
|
||||
f.write("### Variables\n")
|
||||
# Unterüberschrift für Variablen
|
||||
f.write("Variables\n")
|
||||
f.write("---------\n\n")
|
||||
|
||||
for key, value in meta_data.get('galaxy_info', {}).items():
|
||||
f.write(f"- **{key}**: {value}\n")
|
||||
|
||||
# README falls vorhanden konvertieren und einfügen
|
||||
if os.path.exists(readme_file):
|
||||
f.write("\n### README\n")
|
||||
f.write("\nREADME\n")
|
||||
f.write("------\n\n")
|
||||
with open(readme_file, "r", encoding="utf-8") as readme:
|
||||
f.write("\n" + readme.read())
|
||||
markdown_content = readme.read()
|
||||
rst_content = convert_md_to_rst(markdown_content)
|
||||
f.write(rst_content)
|
||||
|
||||
print(f"Ansible roles documentation has been generated in {output_dir}")
|
||||
|
||||
@@ -40,3 +64,4 @@ if __name__ == "__main__":
|
||||
|
||||
args = parser.parse_args()
|
||||
generate_ansible_roles_doc(args.roles_dir, args.output_dir)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user