Skip to content

Commit

Permalink
Non tabular output denied for CSV conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare authored and pondrejk committed Jan 11, 2024
1 parent 73e1475 commit 39be0d7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions robottelo/cli/hammer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,23 @@ def _normalize_obj(obj):
return obj


def is_csv(output):
"""Verifies if the output string is eligible for converting into CSV"""
sniffer = csv.Sniffer()
try:
sniffer.sniff(output)
return True
except csv.Error:
return False


def parse_csv(output):
"""Parse CSV output from Hammer CLI and convert it to python dictionary."""
# ignore warning about puppet and ostree deprecation
output.replace('Puppet and OSTree will no longer be supported in Katello 3.16\n', '')
# Validate if the output is eligible for CSV conversions else return as it is
if not is_csv(output):
return output
reader = csv.reader(output.splitlines())
# Generate the key names, spaces will be converted to dashes "-"
keys = [_normalize(header) for header in next(reader)]
Expand Down

0 comments on commit 39be0d7

Please sign in to comment.