Skip to content

Commit

Permalink
added yaml and boolean outputs
Browse files Browse the repository at this point in the history
added yaml and boolean outputs and defaulted to yaml much like salt.
test.ping will default to boolean.

use `--out boolean` to use the boolean outputer for anything else. and
`--out json` to use the json outputter to get the full return
informaiton in a json output
  • Loading branch information
whytewolf committed Nov 13, 2024
1 parent a78cc5a commit 75a9175
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 28 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: 3.12
cache: true
- uses: pre-commit/[email protected]
- name: Install dependencies
run: pdm install
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.2
rev: v0.7.3
hooks:
# Run the linter.
- id: ruff
Expand All @@ -38,6 +38,7 @@ repos:
rev: v1.13.0
hooks:
- id: mypy
additional_dependencies: [types-PyYAML]
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.2
hooks:
Expand Down
21 changes: 16 additions & 5 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 4 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies = [
"httpx[http2]>=0.27.2",
"tomli>=2.0.2",
"httpx-sse>=0.4.0",
"PyYAML>=6.0.2",
]
requires-python = ">=3.12"
readme = "README.md"
Expand All @@ -33,20 +34,6 @@ distribution = true
[tool.pdm.version]
source = "scm"

[tool.pdm.dev-dependencies]
dev = [
"pytest-httpx>=0.32.0",
"pytest>=8.3.3",
"coverage>=7.6.1",
"coverage[toml]>=7.6.1",
"pre-commit>=4.0.1",
"mypy>=1.11.2",
"bandit>=1.7.10",
"pdm-backend>=2.4.3",
"pytest-asyncio>=0.24.0",
"pytest-cov>=6.0.0",
]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
Expand All @@ -57,3 +44,6 @@ exclude_dirs = ["tests", ".venv"]
[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = "function"
markers = ["buildargs_data: pass data to buildargs fixture"]

[dependency-groups]
dev = ["pytest-httpx>=0.32.0", "pytest>=8.3.3", "coverage>=7.6.1", "coverage[toml]>=7.6.1", "pre-commit>=4.0.1", "mypy>=1.11.2", "bandit>=1.7.10", "pdm-backend>=2.4.3", "pytest-asyncio>=0.24.0", "pytest-cov>=6.0.0", "types-PyYAML>=6.0.12.20240917"]
2 changes: 1 addition & 1 deletion src/guajillo/utils/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async def check_outputer(self, fun: str) -> str:
return self.parser.parsed_args.output
if fun in defined_outputers:
return defined_outputers[fun]
return "json"
return "yaml"

async def taskMan(self, async_comms: dict["str", Any]) -> None:
"""
Expand Down
33 changes: 26 additions & 7 deletions src/guajillo/utils/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import logging
from typing import Any

import yaml
from rich.console import Console
from rich.status import Status
from rich.syntax import Syntax

from guajillo.exceptions import TerminateTaskGroup

Expand All @@ -22,6 +24,11 @@ def __init__(self, console: Console, parser=None, config=None) -> None:
async def json(self, event: dict["str", Any]) -> None:
self.console.print_json(json.dumps(event))

async def yaml(self, event: dict["str", Any]) -> None:
yaml_output = yaml.dump(event["return"][0])
syntax = Syntax(yaml_output, "yaml", line_numbers=True)
self.console.print(syntax)

async def status(self, event: dict[str, Any]) -> None:
if "Minions" in event["info"][0]:
queued = f"{len(list(event['return'][0].keys()))}/{len(event["info"][0]["Minions"])}"
Expand All @@ -31,14 +38,26 @@ async def status(self, event: dict[str, Any]) -> None:
self.cstatus.update(msg)

async def boolean(self, event: dict[str, Any]) -> None:
nonreturned = []
output = event["return"][0]
items = event["info"][0]["Minions"]
returned = [f"[green]✔[/green] {x}" for x in items if x in output]
nonreturned = [f"[red]✘[/red] {x}" for x in items if x not in output]
for item in returned:
self.console.print(item)
for item in nonreturned:
self.console.print(item)
if "Minions" in event["info"][0]:
items = event["info"][0]["Minions"]
nonreturned = [x for x in items if x not in output]
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"]
):
self.console.print(f"[green]✔ {item}[/green]")
else:
self.console.print(f"[red]:-1: {item}[/red]")
if len(nonreturned) > 0:
self.console.print("[red]Minions that did not return[/red]")
for item in nonreturned:
self.console.print(f"[red]✘ {item}[/red]")

async def taskMan(self, async_comms: dict[str, Any]) -> None:
try:
Expand Down

0 comments on commit 75a9175

Please sign in to comment.