mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-19 10:27:07 +01:00
Added log file for upgrade
This commit is contained in:
parent
e7d6407ed1
commit
25aaaf2055
3 changed files with 17 additions and 1 deletions
|
@ -32,6 +32,7 @@ class Configs:
|
||||||
|
|
||||||
deps_log_file: Path = Path(log_path, 'deps.log')
|
deps_log_file: Path = Path(log_path, 'deps.log')
|
||||||
slpkg_log_file: Path = Path(log_path, 'slpkg.log')
|
slpkg_log_file: Path = Path(log_path, 'slpkg.log')
|
||||||
|
upgrade_log_file: Path = Path(log_path, 'upgrade.log')
|
||||||
|
|
||||||
file_list_suffix: str = '.pkgs'
|
file_list_suffix: str = '.pkgs'
|
||||||
installpkg: str = 'upgradepkg --install-new'
|
installpkg: str = 'upgradepkg --install-new'
|
||||||
|
|
|
@ -42,6 +42,10 @@ class Upgrade(Configs):
|
||||||
|
|
||||||
def packages(self) -> Generator:
|
def packages(self) -> Generator:
|
||||||
""" Returns the upgradable packages. """
|
""" 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)
|
self.load_installed_packages(self.repository)
|
||||||
|
|
||||||
for inst in self.installed_packages:
|
for inst in self.installed_packages:
|
||||||
|
@ -60,6 +64,7 @@ class Upgrade(Configs):
|
||||||
yield name
|
yield name
|
||||||
|
|
||||||
def is_package_upgradeable(self, installed: str) -> bool:
|
def is_package_upgradeable(self, installed: str) -> bool:
|
||||||
|
""" Returns True for upgradeable packages. """
|
||||||
inst_name: str = self.utils.split_package(installed)['name']
|
inst_name: str = self.utils.split_package(installed)['name']
|
||||||
if self.data.get(inst_name):
|
if self.data.get(inst_name):
|
||||||
repo_version: str = self.data[inst_name]['version']
|
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):
|
if parse(repo_version) == parse(inst_version) and int(repo_build) > int(inst_build):
|
||||||
return True
|
return True
|
||||||
except InvalidVersion:
|
except InvalidVersion as err:
|
||||||
|
self._write_log_file(installed, inst_name, err)
|
||||||
return False
|
return False
|
||||||
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:
|
def check_packages(self) -> None:
|
||||||
repo_data: dict = {}
|
repo_data: dict = {}
|
||||||
found_packages: dict = {}
|
found_packages: dict = {}
|
||||||
|
|
|
@ -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/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/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('.pkgs', self.configs.file_list_suffix)
|
||||||
self.assertEqual('upgradepkg --install-new', self.configs.installpkg)
|
self.assertEqual('upgradepkg --install-new', self.configs.installpkg)
|
||||||
|
|
Loading…
Reference in a new issue