-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7e06e1
commit 717c3b7
Showing
9 changed files
with
123 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{# Add autogenerated file comment #}<!--- This is an autogenerated file, see `scripts/build_docs.py` for more info. ---> | ||
# Vidimensional's Ansible collection | ||
|
||
![main workflow](https://github.com/Vidimensional/ansible_collection/actions/workflows/workflow_main.yaml/badge.svg) | ||
|
||
Collection of Ansible plugins and modules for my usage. But you can use them if you like :) | ||
|
||
## Installation | ||
|
||
```shell | ||
ansible-galaxy collection install vidimensional.collection | ||
``` | ||
|
||
## Content | ||
|
||
### plugins | ||
|
||
#### lookup | ||
{% for lookup in plugins_lookup %} | ||
- **[{{ lookup.documentation.name }}](docs/lookup_{{ lookup.documentation.name }}.md)** - {{ lookup.documentation.short_description }} | ||
{%- endfor %} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pytest | ||
j2cli | ||
pyyaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python | ||
|
||
import importlib | ||
import os | ||
import pkgutil | ||
import sys | ||
|
||
from types import ModuleType | ||
|
||
import jinja2 | ||
import yaml | ||
|
||
|
||
sys.path.append(os.getcwd()) | ||
import plugins.lookup | ||
|
||
|
||
def get_documentation_from_plugin_file(plugin_name: str) -> dict: | ||
plugin = importlib.import_module(plugin_name) | ||
|
||
return { | ||
"documentation": yaml.safe_load(plugin.DOCUMENTATION), | ||
"examples": str(plugin.EXAMPLES), | ||
} | ||
|
||
|
||
def get_plugin_type_documentation(plugin_type: ModuleType) -> list[dict]: | ||
plugins_path = plugin_type.__path__ | ||
sys.path += plugins_path | ||
|
||
return [ | ||
get_documentation_from_plugin_file(pkg.name) | ||
for pkg in pkgutil.iter_modules(plugins_path) | ||
] | ||
|
||
|
||
class Jinja2TemplateGenerator: | ||
def __init__(self, j2_env): | ||
self.j2_env = j2_env | ||
|
||
def generate_readme(self, doc): | ||
tpl = self.j2_env.get_template("README.md.j2") | ||
with open("README.md", "w") as md_file: | ||
md_file.write(tpl.render(doc)) | ||
|
||
def generate_plugin_documentation(self, plugin_type, plugins_info): | ||
tpl = self.j2_env.get_template(f"{plugin_type}.md.j2") | ||
for plugin in plugins_info: | ||
plugin_name = plugin["documentation"]["name"] | ||
with open(f"docs/{plugin_type}_{plugin_name}.md", "w") as md_file: | ||
md_file.write(tpl.render(plugin)) | ||
|
||
def generate_plugins_lookup_documentation(self, plugins_lookup_info): | ||
self.generate_plugin_documentation("lookup", plugins_lookup_info) | ||
|
||
|
||
if __name__ == "__main__": | ||
# a = get_plugins_doc(plugins.lookup) | ||
sys.path.append(os.getcwd()) | ||
lookups_module = importlib.import_module("plugins.lookup") | ||
doc = {"plugins_lookup": get_plugin_type_documentation(lookups_module)} | ||
|
||
j2 = Jinja2TemplateGenerator( | ||
jinja2.Environment( | ||
loader=jinja2.FileSystemLoader(["docs/templates", "."]), | ||
autoescape=jinja2.select_autoescape(), | ||
) | ||
) | ||
|
||
j2.generate_readme(doc) | ||
j2.generate_plugins_lookup_documentation(doc["plugins_lookup"]) |
This file was deleted.
Oops, something went wrong.