-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from whytewolf/outputters
Outputters
- Loading branch information
Showing
16 changed files
with
271 additions
and
115 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,10 @@ | ||
[ | ||
{ | ||
"name": "guajillo test", | ||
"justMyCode": false, | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/src/guajillo/main.py", | ||
"args": ["salt", "salt00", "test.ping"] | ||
} | ||
] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,6 @@ | ||
import importlib | ||
import pkgutil | ||
|
||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__): | ||
module = importlib.import_module(f"{__name__}.{module_name}") | ||
globals()[module_name] = getattr(module, "render") |
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,25 @@ | ||
from typing import Any | ||
|
||
from rich.console import Group | ||
from rich.table import Table | ||
|
||
import guajillo.outputs | ||
|
||
|
||
async def render(event: dict[str, Any], console) -> None: | ||
result = Table(title="Results") | ||
result.add_column("Minion") | ||
result.add_column("Result") | ||
for item in event["info"][0]["Result"]: | ||
if ( | ||
"success" in event["info"][0]["Result"][item] | ||
and event["info"][0]["Result"][item]["success"] | ||
) or ( | ||
"success" in event["info"][0]["Result"][item]["return"] | ||
and event["info"][0]["Result"][item]["return"]["success"] | ||
): | ||
result.add_row(item, "[green]✔[/green]") | ||
else: | ||
result.add_row(item, "[red]✘[/red]") | ||
unknown = await guajillo.outputs.non_returns(event, console) | ||
return Group(result, unknown) |
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,43 @@ | ||
from typing import Any | ||
|
||
from rich.console import Group | ||
from rich.table import Table | ||
from rich.text import Text | ||
|
||
import guajillo.outputs | ||
|
||
|
||
async def render(event: dict[str, Any], console) -> None: | ||
output = event["info"][0]["Result"] | ||
if "Minions" in event["info"][0]: | ||
isMinion = True | ||
minions = Table(title="minion highstate", show_header=True) | ||
minions.add_column("Minion", style="cyan") | ||
minions.add_column("Highstate") | ||
for minion, returned in output.items(): | ||
highstate = Table(expand=True) | ||
highstate.add_column("id", style="magenta") | ||
highstate.add_column("name", style="magenta") | ||
highstate.add_column("function", style="magenta") | ||
highstate.add_column("result", style="magenta") | ||
highstate.add_column("changes", style="magenta") | ||
for id, results in returned["return"].items(): | ||
module, id, name, fun = id.split("_|-") | ||
if results["result"]: | ||
label = Text("✔", style="green") | ||
else: | ||
label = Text("✘", style="red") | ||
changes = await guajillo.outputs.yaml( | ||
{"return": [results.get("changes", "")]}, console | ||
) | ||
highstate.add_row( | ||
id, | ||
name, | ||
f"{module}.{fun}", | ||
label, | ||
changes, | ||
) | ||
minions.add_row(minion, highstate) | ||
|
||
nonreturned = await guajillo.outputs.non_returns(event, console) | ||
return Group(minions, nonreturned) |
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,8 @@ | ||
import json | ||
from typing import Any | ||
|
||
from rich.json import JSON | ||
|
||
|
||
async def render(event: dict["str", Any], console) -> None: | ||
return JSON(json.dumps(event)) |
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,15 @@ | ||
from rich.console import Group | ||
from rich.text import Text | ||
|
||
|
||
async def render(event, console): | ||
output = event["info"][0]["Result"] | ||
items = event["info"][0]["Minions"] | ||
nonreturned = [x for x in items if x not in output] | ||
if len(nonreturned) > 0: | ||
header = Text("[red]Minions that did not return[/red]\n") | ||
minions = Text( | ||
", ".join(list(map(lambda item: f"[red]✘ {item}[/red]", nonreturned))) | ||
) | ||
return Group(header, minions) | ||
return Text("All minions returned") |
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,55 @@ | ||
from typing import Any | ||
|
||
from rich.console import Group | ||
from rich.table import Table | ||
from rich.text import Text | ||
|
||
import guajillo.outputs | ||
|
||
|
||
async def render(event: dict[str, Any], console) -> None: | ||
output = event["info"][0]["Result"] | ||
isMinion = False | ||
if "Minions" in event["info"][0]: | ||
isMinion = True | ||
for minion, returned in output.items(): | ||
state = Table(title=f"{minion}", width=120, highlight=True) | ||
state.add_column("State", style="cyan") | ||
state.add_column("name", style="cyan") | ||
state.add_column("Function", style="cyan") | ||
state.add_column("Result") | ||
state.add_column("Duration", style="magenta") | ||
duration = "" | ||
total_duration = 0 | ||
good = 0 | ||
bad = 0 | ||
if isMinion: | ||
vexed = returned["return"] | ||
else: | ||
vexed = returned["return"]["return"]["data"][minion] | ||
|
||
for id, results in vexed.items(): | ||
module, id, name, fun = id.split("_|-") | ||
if results["result"]: | ||
result = Text("✔ ", style="green") | ||
good += 1 | ||
else: | ||
result = Text("✘", style="red") | ||
bad += 1 | ||
if "duration" in results: | ||
duration = Text( | ||
f"{results['duration']} ms", | ||
style="bold magenta", | ||
) | ||
total_duration += results["duration"] | ||
state.add_row(id, name, f"{module}.{fun}", result, duration) | ||
state.add_section() | ||
state.add_row( | ||
"Final Total", | ||
"", | ||
"", | ||
f"[red]{bad}[/red]/[green]{good}[/green] ({bad + good})", | ||
f"[bold magenta]{total_duration/1000:.4f} s[/bold magenta]", | ||
) | ||
nonreturned = await guajillo.outputs.non_returns(event, console) | ||
return Group(state, nonreturned) |
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,9 @@ | ||
from typing import Any | ||
|
||
import yaml | ||
from rich.syntax import Syntax | ||
|
||
|
||
async def render(event: dict[str, Any], console) -> None: | ||
yaml_output = yaml.dump(event["return"][0]) | ||
return Syntax(yaml_output, "yaml") |
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
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
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,6 +1,10 @@ | ||
Output images/demo.gif | ||
Set FontSize 24 | ||
Set Width 2400 | ||
Set Height 1200 | ||
Set Shell zsh | ||
Sleep 5ms | ||
Type "guajillo -t 10 salt '*' test.ping" | ||
Type "guajillo -t 10 --out profile salt salt00 state.apply" | ||
Enter | ||
Sleep 35s | ||
Sleep 15s | ||
Ctrl+D |