X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Fpresentation%2Fpal_utils.py;h=3efa00af2cffe5b1abf197bd81aed6fd5d9a4cde;hb=4f4441a7ae175cda9ac55dc23a94099617bea293;hp=45fd2770480adeb7a8e6feb67c1583dc1f80c613;hpb=b55e324d526e5b05baef015c3614b9743c955992;p=csit.git
diff --git a/resources/tools/presentation/pal_utils.py b/resources/tools/presentation/pal_utils.py
index 45fd277048..3efa00af2c 100644
--- a/resources/tools/presentation/pal_utils.py
+++ b/resources/tools/presentation/pal_utils.py
@@ -297,24 +297,51 @@ def classify_anomalies(data):
return classification, avgs
-def convert_csv_to_pretty_txt(csv_file_name, txt_file_name):
+def convert_csv_to_pretty_txt(csv_file_name, txt_file_name, delimiter=u","):
"""Convert the given csv table to pretty text table.
:param csv_file_name: The path to the input csv file.
:param txt_file_name: The path to the output pretty text file.
+ :param delimiter: Delimiter for csv file.
:type csv_file_name: str
:type txt_file_name: str
+ :type delimiter: str
"""
txt_table = None
- with open(csv_file_name, u"rt") as csv_file:
- csv_content = csv.reader(csv_file, delimiter=u',', quotechar=u'"')
+ with open(csv_file_name, u"rt", encoding='utf-8') as csv_file:
+ csv_content = csv.reader(csv_file, delimiter=delimiter, quotechar=u'"')
for row in csv_content:
if txt_table is None:
txt_table = prettytable.PrettyTable(row)
else:
txt_table.add_row(row)
- txt_table.align[u"Test case"] = u"l"
- if txt_table:
- with open(txt_file_name, u"wt") as txt_file:
+ txt_table.align = u"r"
+ txt_table.align[u"Test Case"] = u"l"
+ txt_table.align[u"RCA"] = u"l"
+ txt_table.align[u"RCA1"] = u"l"
+ txt_table.align[u"RCA2"] = u"l"
+ txt_table.align[u"RCA3"] = u"l"
+
+ if not txt_table:
+ return
+
+ if txt_file_name.endswith(u".txt"):
+ with open(txt_file_name, u"wt", encoding='utf-8') as txt_file:
txt_file.write(str(txt_table))
+ elif txt_file_name.endswith(u".rst"):
+ with open(txt_file_name, u"wt") as txt_file:
+ txt_file.write(
+ u"\n"
+ u".. |br| raw:: html\n\n
\n\n\n"
+ u".. |prein| raw:: html\n\n
\n\n\n" + u".. |preout| raw:: html\n\n\n\n" + ) + txt_file.write( + u"\n.. only:: html\n\n" + u" .. csv-table::\n" + u" :header-rows: 1\n" + u" :widths: auto\n" + u" :align: center\n" + f" :file: {csv_file_name.split(u'/')[-1]}\n" + )