mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-18 10:26:29 +01:00
Added logging config
This commit is contained in:
parent
f5e21e894c
commit
958d6b9f9b
4 changed files with 24 additions and 16 deletions
|
@ -6,6 +6,7 @@ import tomli
|
||||||
import platform
|
import platform
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from slpkg.logging_config import LoggingConfig
|
||||||
|
|
||||||
|
|
||||||
class Load:
|
class Load:
|
||||||
|
@ -46,8 +47,6 @@ class Configs:
|
||||||
}
|
}
|
||||||
|
|
||||||
prog_name: str = 'slpkg'
|
prog_name: str = 'slpkg'
|
||||||
root_slpkg: Path = Path(Path.home(), f'.{prog_name}')
|
|
||||||
log_path: Path = Path(root_slpkg, 'logs')
|
|
||||||
os_arch: str = platform.machine()
|
os_arch: str = platform.machine()
|
||||||
tmp_path: str = '/tmp/'
|
tmp_path: str = '/tmp/'
|
||||||
tmp_slpkg: Path = Path(tmp_path, prog_name)
|
tmp_slpkg: Path = Path(tmp_path, prog_name)
|
||||||
|
@ -115,13 +114,13 @@ class Configs:
|
||||||
|
|
||||||
# Creating the paths if not exists
|
# Creating the paths if not exists
|
||||||
paths = [
|
paths = [
|
||||||
tmp_slpkg,
|
db_path,
|
||||||
log_path,
|
|
||||||
build_path,
|
|
||||||
download_only_path,
|
|
||||||
lib_path,
|
lib_path,
|
||||||
etc_path,
|
etc_path,
|
||||||
db_path,
|
build_path,
|
||||||
|
tmp_slpkg,
|
||||||
|
download_only_path,
|
||||||
|
LoggingConfig.log_path
|
||||||
]
|
]
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
|
|
10
slpkg/logging_config.py
Normal file
10
slpkg/logging_config.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
class LoggingConfig:
|
||||||
|
root_slpkg: Path = Path(Path.home(), '.slpkg')
|
||||||
|
log_path: Path = Path(root_slpkg, 'logs')
|
||||||
|
log_file: Path = Path(log_path, 'errors_slpkg.log')
|
|
@ -2,7 +2,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
from packaging.version import parse, InvalidVersion
|
from packaging.version import parse, InvalidVersion
|
||||||
|
|
||||||
|
@ -10,6 +9,7 @@ from slpkg.configs import Configs
|
||||||
from slpkg.utilities import Utilities
|
from slpkg.utilities import Utilities
|
||||||
from slpkg.sbos.queries import SBoQueries
|
from slpkg.sbos.queries import SBoQueries
|
||||||
from slpkg.binaries.queries import BinQueries
|
from slpkg.binaries.queries import BinQueries
|
||||||
|
from slpkg.logging_config import LoggingConfig
|
||||||
|
|
||||||
|
|
||||||
class Upgrade(Configs):
|
class Upgrade(Configs):
|
||||||
|
@ -26,8 +26,7 @@ class Upgrade(Configs):
|
||||||
|
|
||||||
self.all_installed: list = self.utils.installed_package_names
|
self.all_installed: list = self.utils.installed_package_names
|
||||||
|
|
||||||
log_file: Path = Path(self.log_path, 'error_upgrade.log')
|
logging.basicConfig(filename=LoggingConfig.log_file,
|
||||||
logging.basicConfig(filename=log_file,
|
|
||||||
encoding='utf-8',
|
encoding='utf-8',
|
||||||
level=logging.DEBUG)
|
level=logging.DEBUG)
|
||||||
|
|
||||||
|
@ -72,6 +71,6 @@ class Upgrade(Configs):
|
||||||
if parse(repo_version) == parse(inst_version) and parse(repo_build) > parse(inst_build):
|
if parse(repo_version) == parse(inst_version) and parse(repo_build) > parse(inst_build):
|
||||||
return True
|
return True
|
||||||
except InvalidVersion as err:
|
except InvalidVersion as err:
|
||||||
logging.error(err)
|
logging.error(f'{self.__class__.__name__}: {Upgrade.is_package_upgradeable.__name__}: {err}')
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -14,6 +14,7 @@ from slpkg.blacklist import Blacklist
|
||||||
from slpkg.sbos.queries import SBoQueries
|
from slpkg.sbos.queries import SBoQueries
|
||||||
from slpkg.repositories import Repositories
|
from slpkg.repositories import Repositories
|
||||||
from slpkg.binaries.queries import BinQueries
|
from slpkg.binaries.queries import BinQueries
|
||||||
|
from slpkg.logging_config import LoggingConfig
|
||||||
|
|
||||||
|
|
||||||
class Utilities:
|
class Utilities:
|
||||||
|
@ -36,8 +37,7 @@ class Utilities:
|
||||||
self.installed_packages: list = list(self.all_installed())
|
self.installed_packages: list = list(self.all_installed())
|
||||||
self.installed_package_names: list = list(self.all_installed_names())
|
self.installed_package_names: list = list(self.all_installed_names())
|
||||||
|
|
||||||
log_file: Path = Path(self.configs.log_path, 'error_utilities.log')
|
logging.basicConfig(filename=LoggingConfig.log_file,
|
||||||
logging.basicConfig(filename=log_file,
|
|
||||||
encoding='utf-8',
|
encoding='utf-8',
|
||||||
level=logging.DEBUG)
|
level=logging.DEBUG)
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ class Utilities:
|
||||||
|
|
||||||
if not name.startswith('.') and name not in self.black.packages():
|
if not name.startswith('.') and name not in self.black.packages():
|
||||||
yield file.name
|
yield file.name
|
||||||
except ValueError:
|
except ValueError as err:
|
||||||
pass
|
logging.error(f'{self.__class__.__name__}: {Utilities.all_installed.__name__}: {err}')
|
||||||
|
|
||||||
def all_installed_names(self) -> Generator:
|
def all_installed_names(self) -> Generator:
|
||||||
""" Return all installed packages names from /val/log/packages folder. """
|
""" Return all installed packages names from /val/log/packages folder. """
|
||||||
|
@ -75,7 +75,7 @@ class Utilities:
|
||||||
if not name.startswith('.') and name not in self.black.packages():
|
if not name.startswith('.') and name not in self.black.packages():
|
||||||
yield name
|
yield name
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
logging.error(f'all_installed_names: {err}')
|
logging.error(f'{self.__class__.__name__}: {Utilities.all_installed_names.__name__}: {err}')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_file_if_exists(path: Path, file: str) -> None:
|
def remove_file_if_exists(path: Path, file: str) -> None:
|
||||||
|
|
Loading…
Reference in a new issue