From 39be0d7f962dc5bb55946a5034d239709e799592 Mon Sep 17 00:00:00 2001 From: jyejare Date: Thu, 11 Jan 2024 15:57:49 +0530 Subject: [PATCH] Non tabular output denied for CSV conversion --- robottelo/cli/hammer.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/robottelo/cli/hammer.py b/robottelo/cli/hammer.py index 661042050e6..cf14cd2f0d7 100644 --- a/robottelo/cli/hammer.py +++ b/robottelo/cli/hammer.py @@ -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)]