56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
import pathlib
|
|
import datetime
|
|
|
|
# Some feedback with colours to make console output easier to read
|
|
C_INFO = "\u001b[96m*INFO*\u001b[0m\t" # Info - Cyan
|
|
C_WARN = "\u001b[33m*WARN*\u001b[0m\t" # Warning - Orange
|
|
C_ERR = "\u001b[31m*ERR*\u001b[0m\t" # Error - Red
|
|
C_USER = "\u001b[35m*USER*\u001b[0m\t" # User input - Purple
|
|
C_DONE = "\u001b[32m*DONE*\u001b[0m\t" # Done - Green
|
|
C_DBUG = "\u001b[94m*DBUG*\u001b[0m\t" # Debug - Blue
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
class CVSuiteLogger:
|
|
def __init__(self, path):
|
|
self.fileName = pathlib.Path(
|
|
path, f"result-{now.strftime('%Y-%m-%dT%H.%M.%S')}.csv"
|
|
)
|
|
self.file = open(self.fileName, encoding="utf-8", mode="x")
|
|
|
|
self.first = True
|
|
self.index = []
|
|
self.data = []
|
|
|
|
def add(self, name: str, value):
|
|
self.index.append(name)
|
|
self.data.append(value)
|
|
|
|
def csv(self, data):
|
|
result = ""
|
|
|
|
for idx, item in enumerate(data):
|
|
result += str(item)
|
|
if idx != (len(data) - 1):
|
|
result += ", "
|
|
result += "\n"
|
|
# print(result)
|
|
|
|
return result
|
|
|
|
def update(self):
|
|
if self.first:
|
|
self.first = False
|
|
self.file.write(self.csv(self.index))
|
|
|
|
self.file.write(self.csv(self.data))
|
|
self.clear()
|
|
|
|
def clear(self):
|
|
# Clear data
|
|
self.index = []
|
|
self.data = []
|
|
|
|
def __del__(self):
|
|
self.file.close()
|