Updated for logging

This commit is contained in:
Dimitris Zlatanidis 2023-04-27 11:45:22 +03:00
parent 0daa4a9d87
commit c1147dc087
2 changed files with 63 additions and 4 deletions

View file

@ -1,11 +1,13 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import logging
from pathlib import Path
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
from slpkg.logging_config import LoggingConfig
from slpkg.models.models import session as Session
from slpkg.models.models import (SBoTable, PonceTable,
BinariesTable, LastRepoUpdated)
@ -19,6 +21,11 @@ class InstallData(Configs):
self.utils = Utilities()
self.repos = Repositories()
logging.basicConfig(filename=LoggingConfig.log_file,
filemode=LoggingConfig.filemode,
encoding=LoggingConfig.encoding,
level=LoggingConfig.level)
def last_updated(self, repo_file: Path) -> str:
""" Reads the first date of the changelog file."""
lines: list = self.utils.read_file(repo_file)
@ -124,6 +131,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slack_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[2]):
@ -212,6 +222,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slack_extra_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[2]):
@ -300,6 +313,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slack_patches_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[2]):
@ -389,6 +405,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_alien_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -482,6 +501,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_multilib_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -570,6 +592,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_restricted_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -659,6 +684,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_gnome_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[2]):
@ -747,6 +775,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_msb_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -835,6 +866,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_csb_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -925,6 +959,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_conraid_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[2]):
@ -1014,6 +1051,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slackonly_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -1108,6 +1148,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_salixos_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -1211,6 +1254,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_salixos_extra_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -1314,6 +1360,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_salixos_patches_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -1416,6 +1465,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slackel_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):
@ -1518,6 +1570,9 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slint_data.__name__)
cache.append('error checksum')
if line.startswith(pkg_tag[1]):

View file

@ -124,7 +124,8 @@ class Utilities(Configs):
except FileNotFoundError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__, self.__class__.read_packages_from_file.__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.read_packages_from_file.__name__)
self.errors.raise_error_message(f"No such file or directory: '{file}'", exit_status=20)
def read_file(self, file: Union[str, Path]) -> list:
@ -134,7 +135,8 @@ class Utilities(Configs):
return f.readlines()
except FileNotFoundError:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__, self.__class__.read_file.__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.read_file.__name__)
self.errors.raise_error_message(f"No such file or directory: '{file}'", exit_status=20)
def process(self, command: str, stderr=None, stdout=None) -> None:
@ -143,7 +145,8 @@ class Utilities(Configs):
subprocess.call(command, shell=True, stderr=stderr, stdout=stdout)
except subprocess.CalledProcessError as error:
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__, self.__class__.process.__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.process.__name__)
self.errors.raise_error_message(str(error), exit_status=20)
except KeyboardInterrupt:
raise SystemExit(1)
@ -186,7 +189,8 @@ class Utilities(Configs):
repo: list = list(data.values())[0][11]
except (IndexError, AttributeError):
logger = logging.getLogger(__name__)
logger.exception('%s: %s:', self.__class__.__name__, self.__class__.repository_name.__name__)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.repository_name.__name__)
# Slackbuilds repository name 'sbo | ponce'
repo: str = self.repos.sbo_enabled_repo_name