Updated log to json format

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2024-05-31 17:28:06 +03:00
parent 83e1a48180
commit 2dff175b39

View file

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import json
import shutil
import platform
from pathlib import Path
@ -137,12 +138,22 @@ class Upgrade(Configs): # pylint: disable=[R0902]
name (str): Package name.
err (InvalidVersion): InvalidVersion error.
"""
if self.log_path.is_dir():
with self.upgrade_log_file.open('a', encoding='utf-8') as log:
log.write(f"{self.cyan}Installed{self.endc}: {installed}, "
f"{self.yellow}Repository{self.endc}: {self.data[name]['package']}, "
f"{self.red}Error{self.endc}: {err}, "
f"Repo: {self.repository}\n")
if self.upgrade_log_file.is_file():
log: dict = self.utils.read_json_file(self.upgrade_log_file)
log[self.repository]: dict = {
'installed package': installed,
'repository package': self.data[name]['package'],
'error': err
}
self.upgrade_log_file.write_text(json.dumps(log, indent=4), encoding='utf-8')
# with self.upgrade_log_file.open('a', encoding='utf-8') as log:
# log.write(f"Installed: {installed}, "
# f"Repository: {self.data[name]['package']}, "
# f"Error: {err}, "
# f"Repo: {self.repository}\n")
def check_packages(self) -> None:
"""Check only which packages are upgradeable."""