Added log file for upgrade

This commit is contained in:
Dimitris Zlatanidis 2024-04-01 16:04:52 +03:00
parent e7d6407ed1
commit 25aaaf2055
3 changed files with 17 additions and 1 deletions

View file

@ -32,6 +32,7 @@ class Configs:
deps_log_file: Path = Path(log_path, 'deps.log')
slpkg_log_file: Path = Path(log_path, 'slpkg.log')
upgrade_log_file: Path = Path(log_path, 'upgrade.log')
file_list_suffix: str = '.pkgs'
installpkg: str = 'upgradepkg --install-new'

View file

@ -42,6 +42,10 @@ class Upgrade(Configs):
def packages(self) -> Generator:
""" Returns the upgradable packages. """
# Delete log file before starts.
if self.upgrade_log_file.is_file():
self.upgrade_log_file.unlink()
self.load_installed_packages(self.repository)
for inst in self.installed_packages:
@ -60,6 +64,7 @@ class Upgrade(Configs):
yield name
def is_package_upgradeable(self, installed: str) -> bool:
""" Returns True for upgradeable packages. """
inst_name: str = self.utils.split_package(installed)['name']
if self.data.get(inst_name):
repo_version: str = self.data[inst_name]['version']
@ -72,10 +77,19 @@ class Upgrade(Configs):
if parse(repo_version) == parse(inst_version) and int(repo_build) > int(inst_build):
return True
except InvalidVersion:
except InvalidVersion as err:
self._write_log_file(installed, inst_name, err)
return False
return False
def _write_log_file(self, installed: str, name: str, err: InvalidVersion) -> None:
""" Writes a log file for invalid versions. """
if self.log_path.is_dir():
with self.upgrade_log_file.open('a') as log:
log.write(f"Installed: {installed}, "
f"Repository: {self.data[name]['package']}, "
f"Error: {err}\n")
def check_packages(self) -> None:
repo_data: dict = {}
found_packages: dict = {}

View file

@ -22,6 +22,7 @@ class TestConfigs(unittest.TestCase):
self.assertEqual(Path('/var/log/slpkg/deps.log'), self.configs.deps_log_file)
self.assertEqual(Path('/var/log/slpkg/slpkg.log'), self.configs.slpkg_log_file)
self.assertEqual(Path('/var/log/slpkg/upgrade.log'), self.configs.upgrade_log_file)
self.assertEqual('.pkgs', self.configs.file_list_suffix)
self.assertEqual('upgradepkg --install-new', self.configs.installpkg)