Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
These include resolving a problem with interactive edits on mac not
working. This was likely due to a quirk with the NamedTemporaryFile
implementation. I insteda switched to manually creating a temporary file
and that worked.

It also includes an early escape for when a user's inventory is empty.
  • Loading branch information
JacobCallahan committed Oct 15, 2024
1 parent 55d312a commit 82dfa34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions broker/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ def inventory(details, _list, sync, filter):
)
for host in inventory
]
if not curated_host_info:
CONSOLE.print("No hosts found in inventory.")
return
table = helpers.dictlist_to_table(curated_host_info, "Host Inventory", _id=True)
if _list:
table.title = None
Expand Down
11 changes: 5 additions & 6 deletions broker/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
import pkgutil
import sys
from tempfile import NamedTemporaryFile

import click
from logzero import logger
Expand Down Expand Up @@ -56,11 +55,11 @@ def __init__(self, settings_path=None):

def _interactive_edit(self, chunk):
"""Write the chunk data to a temporary file and open it in an editor."""
with NamedTemporaryFile(mode="w+", suffix=".yaml") as tmp:
yaml.dump(chunk, tmp)
click.edit(filename=tmp.name)
tmp.seek(0)
new_data = tmp.read()
temp_file = Path("temp_settings.yaml")
yaml.dump(chunk, temp_file)
click.edit(filename=str(temp_file))
new_data = temp_file.read_text()
temp_file.unlink()
# first try to load it as yaml
try:
return yaml.load(new_data)
Expand Down

0 comments on commit 82dfa34

Please sign in to comment.