Skip to content

Commit

Permalink
[6.15.z] Non tabular output denied for CSV conversion (#13744)
Browse files Browse the repository at this point in the history
Non tabular output denied for CSV conversion

(cherry picked from commit 39be0d7)

Co-authored-by: jyejare <[email protected]>
  • Loading branch information
Satellite-QE and jyejare authored Jan 11, 2024
1 parent 08caa3a commit 25793b9
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 25793b9

Please sign in to comment.