Clean from logging

This commit is contained in:
Dimitris Zlatanidis 2024-03-14 21:45:09 +02:00
parent 9c566be3d1
commit e79e1e6fda
12 changed files with 10 additions and 87 deletions

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import hashlib import hashlib
import logging
from pathlib import Path from pathlib import Path
from typing import Union from typing import Union
from urllib.parse import unquote from urllib.parse import unquote
@ -11,7 +10,6 @@ from slpkg.utilities import Utilities
from slpkg.error_messages import Errors from slpkg.error_messages import Errors
from slpkg.views.views import View from slpkg.views.views import View
from slpkg.views.asciibox import AsciiBox from slpkg.views.asciibox import AsciiBox
from slpkg.logging_config import LoggingConfig
class Md5sum: class Md5sum:
@ -23,11 +21,6 @@ class Md5sum:
self.utils = Utilities() self.utils = Utilities()
self.view = View(flags) self.view = View(flags)
logging.basicConfig(filename=LoggingConfig.log_file,
filemode=LoggingConfig.filemode,
encoding=LoggingConfig.encoding,
level=LoggingConfig.level)
def md5sum(self, path: Union[str, Path], source: str, checksum: str) -> None: def md5sum(self, path: Union[str, Path], source: str, checksum: str) -> None:
""" Checksum the source. """ """ Checksum the source. """
source_file = unquote(source) source_file = unquote(source)
@ -47,7 +40,4 @@ class Md5sum:
with open(filename, 'rb') as file: with open(filename, 'rb') as file:
return file.read() return file.read()
except FileNotFoundError: except FileNotFoundError:
logger = logging.getLogger(LoggingConfig.date_time)
logger.exception(f'{self.__class__.__name__}: '
f'{self.__class__.read_binary_file.__name__}')
self.errors.raise_error_message(f"No such file or directory: '{filename}'", exit_status=20) self.errors.raise_error_message(f"No such file or directory: '{filename}'", exit_status=20)

View file

@ -7,7 +7,6 @@ from typing import Any
from pathlib import Path from pathlib import Path
from dataclasses import dataclass from dataclasses import dataclass
from slpkg.logging_config import LoggingConfig
from slpkg.toml_error_message import TomlErrors from slpkg.toml_error_message import TomlErrors
@ -148,7 +147,6 @@ class Configs:
tmp_slpkg, tmp_slpkg,
slpkg_log_path, slpkg_log_path,
download_only_path, download_only_path,
LoggingConfig.log_path
] ]
for path in paths: for path in paths:

View file

@ -10,7 +10,7 @@ from slpkg.views.asciibox import AsciiBox
class Dependees(Configs): class Dependees(Configs):
""" Prints the packages that depend on. """ """ Prints the packages that depend on. """
def __init__(self, data: dict, packages: list, flags: list, repository: str): def __init__(self, data: dict, packages: list, flags: list):
super(Configs, self).__init__() super(Configs, self).__init__()
self.data: dict = data self.data: dict = data
self.packages: list = packages self.packages: list = packages
@ -24,8 +24,6 @@ class Dependees(Configs):
self.var: str = self.ascii.vertical_and_right self.var: str = self.ascii.vertical_and_right
self.package_version: str = '' self.package_version: str = ''
self.is_binary: bool = self.utils.is_binary_repo(repository)
self.option_for_full_reverse: bool = self.utils.is_option( self.option_for_full_reverse: bool = self.utils.is_option(
('-E', '--full-reverse'), flags) ('-E', '--full-reverse'), flags)
@ -48,7 +46,7 @@ class Dependees(Configs):
def find_requires(self, package: str) -> Generator: def find_requires(self, package: str) -> Generator:
""" Find requires that package dependees. """ """ Find requires that package dependees. """
for name, data in self.data.items(): for name, data in self.data.items():
if package in data['requires'].split(): if package in data['requires']:
yield name, data['requires'] yield name, data['requires']
def view_the_title(self) -> None: def view_the_title(self) -> None:

View file

@ -36,7 +36,6 @@ class DownloadOnly(Configs):
self.repos.ponce_repo_name: self.repos.ponce_repo_path self.repos.ponce_repo_name: self.repos.ponce_repo_path
} }
self.is_binary: bool = self.utils.is_binary_repo(repository)
self.option_for_directory: bool = self.utils.is_option( self.option_for_directory: bool = self.utils.is_option(
('-z', '--directory='), flags) ('-z', '--directory='), flags)
@ -48,7 +47,7 @@ class DownloadOnly(Configs):
start: float = time.time() start: float = time.time()
for pkg in packages: for pkg in packages:
if self.is_binary: if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]:
self.save_binary_sources(pkg) self.save_binary_sources(pkg)
else: else:
self.save_slackbuild_sources(pkg) self.save_slackbuild_sources(pkg)

View file

@ -1,18 +0,0 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import logging
from pathlib import Path
from datetime import datetime
class LoggingConfig:
date_now = datetime.now()
level = logging.INFO
filemode: str = 'w'
encoding: str = 'utf-8'
log_path: Path = Path('/var/log/slpkg/')
log_file: Path = Path(log_path, 'slpkg_runtime.log')
date: str = f'{date_now.day}/{date_now.month}/{date_now.year}'
time: str = f'{date_now.hour}:{date_now.minute}:{date_now.second}'
date_time: str = f'{date} {time}'

View file

@ -3,7 +3,6 @@
import sys import sys
import json import json
import logging
from pathlib import Path from pathlib import Path
from slpkg.checks import Check from slpkg.checks import Check
@ -26,7 +25,6 @@ from slpkg.dialog_configs import FormConfigs
from slpkg.check_updates import CheckUpdates from slpkg.check_updates import CheckUpdates
from slpkg.download_only import DownloadOnly from slpkg.download_only import DownloadOnly
from slpkg.sbos.slackbuild import Slackbuilds from slpkg.sbos.slackbuild import Slackbuilds
from slpkg.logging_config import LoggingConfig
from slpkg.find_installed import FindInstalled from slpkg.find_installed import FindInstalled
from slpkg.views.view_package import ViewPackage from slpkg.views.view_package import ViewPackage
from slpkg.remove_packages import RemovePackages from slpkg.remove_packages import RemovePackages
@ -302,16 +300,6 @@ class Menu(Configs):
self.check = Check(self.repository) self.check = Check(self.repository)
self.choose = Choose(self.repository) self.choose = Choose(self.repository)
logging.basicConfig(filename=LoggingConfig.log_file,
filemode=LoggingConfig.filemode,
encoding=LoggingConfig.encoding,
level=LoggingConfig.level)
logger = logging.getLogger(LoggingConfig.date_time)
logger.info(f'{self.__class__.__name__}: '
f'{self.__class__.__init__.__name__}: '
f'{args=}, {self.flags=}, {self.repository=}')
def load_database(self): def load_database(self):
if self.repository != '*' and not self.data: if self.repository != '*' and not self.data:
print('\rDatabase loading... ', end='') print('\rDatabase loading... ', end='')
@ -690,9 +678,6 @@ class Menu(Configs):
flags: list = self.commands[self.args[1]] flags: list = self.commands[self.args[1]]
Help(self.args[1], flags).view() Help(self.args[1], flags).view()
except KeyError: except KeyError:
logger = logging.getLogger(LoggingConfig.date_time)
logger.exception(f'{self.__class__.__name__}: '
f'{self.__class__.help_for_commands.__name__}')
self.usage.help_minimal(f"{self.prog_name}: invalid argument '{''.join(self.args[1])}'") self.usage.help_minimal(f"{self.prog_name}: invalid argument '{''.join(self.args[1])}'")
else: else:
self.usage.help_short(1) self.usage.help_short(1)

View file

@ -34,7 +34,7 @@ class MultiProcess(Configs):
failed: str = f'{self.red}{self.ascii.failed}{self.endc}' failed: str = f'{self.red}{self.ascii.failed}{self.endc}'
# Starting multiprocessing # Starting multiprocessing
process_1 = Process(target=self.utils.process, args=(command, self.stderr, self.stdout, filename)) process_1 = Process(target=self.utils.process, args=(command, self.stderr, self.stdout,))
process_2 = Process(target=self.progress.progress_bar, args=(progress_message, filename)) process_2 = Process(target=self.progress.progress_bar, args=(progress_message, filename))
process_1.start() process_1.start()
@ -54,4 +54,4 @@ class MultiProcess(Configs):
# Restore the terminal cursor # Restore the terminal cursor
print('\x1b[?25h', self.endc) print('\x1b[?25h', self.endc)
else: else:
self.utils.process(command, self.stderr, self.stdout, filename) self.utils.process(command, self.stderr, self.stdout)

View file

@ -41,7 +41,6 @@ class RemovePackages(Configs):
('-y', '--yes'), flags) ('-y', '--yes'), flags)
def remove(self) -> None: def remove(self) -> None:
self.query_logs_dependencies()
self.add_packages_for_remove() self.add_packages_for_remove()
self.save_dependencies_for_remove() self.save_dependencies_for_remove()
self.remove_doubles_dependencies() self.remove_doubles_dependencies()
@ -104,7 +103,6 @@ class RemovePackages(Configs):
continue continue
self.multi_proc.process(command, package, progress_message) self.multi_proc.process(command, package, progress_message)
self.delete_package_from_logs(name)
def is_dependency(self, name: str) -> list: def is_dependency(self, name: str) -> list:
dependencies: list = [] dependencies: list = []
@ -132,18 +130,6 @@ class RemovePackages(Configs):
if i > 1: if i > 1:
print(f"{'':>8}{self.cyan}{dependency}{self.endc}") print(f"{'':>8}{self.cyan}{dependency}{self.endc}")
def query_logs_dependencies(self) -> None:
package_requires: tuple = self.session.query(
LogsDependencies.name, LogsDependencies.requires).all()
for package in package_requires:
self.logs_dependencies[package[0]] = package[1].split()
def delete_package_from_logs(self, package) -> None:
if not self.option_for_resolve_off:
self.session.query(LogsDependencies).filter(
LogsDependencies.name == package).delete()
self.session.commit()
def choose_dependencies_for_remove(self) -> None: def choose_dependencies_for_remove(self) -> None:
if self.dependencies and self.dialog: if self.dependencies and self.dialog:
height: int = 10 height: int = 10

View file

@ -23,8 +23,6 @@ class SearchPackage(Configs):
self.repo_data: dict = {} self.repo_data: dict = {}
self.data_dict: dict = {} self.data_dict: dict = {}
self.is_binary: bool = self.utils.is_binary_repo(repository)
self.option_for_no_case: bool = self.utils.is_option( self.option_for_no_case: bool = self.utils.is_option(
('-m', '--no-case'), flags) ('-m', '--no-case'), flags)

View file

@ -6,6 +6,7 @@ from slpkg.utilities import Utilities
from slpkg.views.asciibox import AsciiBox from slpkg.views.asciibox import AsciiBox
from slpkg.sbos.dependencies import Requires from slpkg.sbos.dependencies import Requires
from slpkg.binaries.required import Required from slpkg.binaries.required import Required
from slpkg.repositories import Repositories
class Tracking(Configs): class Tracking(Configs):
@ -16,9 +17,11 @@ class Tracking(Configs):
self.data: dict = data self.data: dict = data
self.packages: list = packages self.packages: list = packages
self.flags: list = flags self.flags: list = flags
self.repository: str = repository
self.ascii = AsciiBox() self.ascii = AsciiBox()
self.utils = Utilities() self.utils = Utilities()
self.repos = Repositories()
self.llc: str = self.ascii.lower_left_corner self.llc: str = self.ascii.lower_left_corner
self.hl: str = self.ascii.horizontal_line self.hl: str = self.ascii.horizontal_line
@ -31,8 +34,6 @@ class Tracking(Configs):
self.count_requires: int = 0 self.count_requires: int = 0
self.require_length: int = 0 self.require_length: int = 0
self.is_binary: bool = self.utils.is_binary_repo(repository)
self.option_for_pkg_version: bool = self.utils.is_option( self.option_for_pkg_version: bool = self.utils.is_option(
('-p', '--pkg-version'), flags) ('-p', '--pkg-version'), flags)
@ -98,7 +99,7 @@ class Tracking(Configs):
self.package_version: str = self.data[package]['version'] self.package_version: str = self.data[package]['version']
def set_package_requires(self, package: str) -> None: def set_package_requires(self, package: str) -> None:
if self.is_binary: if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]:
self.package_requires: tuple = Required(self.data, package).resolve() self.package_requires: tuple = Required(self.data, package).resolve()
else: else:
self.package_requires: tuple = Requires(self.data, package).resolve() self.package_requires: tuple = Requires(self.data, package).resolve()

View file

@ -38,8 +38,6 @@ class UpdateRepositories(Configs):
self.repos_for_update: dict = {} self.repos_for_update: dict = {}
self.is_binary: bool = self.utils.is_binary_repo(repository)
self.option_for_repository: bool = self.utils.is_option( self.option_for_repository: bool = self.utils.is_option(
('-o', '--repository='), flags) ('-o', '--repository='), flags)

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging
from typing import Generator from typing import Generator
from pkg_resources import parse_version from pkg_resources import parse_version
@ -9,7 +8,6 @@ from slpkg.rules import Rules
from slpkg.configs import Configs from slpkg.configs import Configs
from slpkg.utilities import Utilities from slpkg.utilities import Utilities
from slpkg.repositories import Repositories from slpkg.repositories import Repositories
from slpkg.logging_config import LoggingConfig
class Upgrade(Configs): class Upgrade(Configs):
@ -24,11 +22,6 @@ class Upgrade(Configs):
self.repos = Repositories() self.repos = Repositories()
self.rules = Rules() self.rules = Rules()
logging.basicConfig(filename=LoggingConfig.log_file,
filemode=LoggingConfig.filemode,
encoding=LoggingConfig.encoding,
level=LoggingConfig.level)
def packages(self) -> Generator: def packages(self) -> Generator:
""" Returns the upgradable packages. """ """ Returns the upgradable packages. """
@ -76,12 +69,7 @@ class Upgrade(Configs):
return True return True
except ValueError: except ValueError:
logger = logging.getLogger(LoggingConfig.date_time) pass
logger.exception(f"{self.__class__.__name__}: "
f"{self.__class__.is_package_upgradeable.__name__}: "
f"{self.repos.repositories[self.repository]['repo_tag']}, "
f"{repository_package=}, {installed_package=}, {repository_package > installed_package}, "
f"{repository_package == installed_package and repo_package_build > inst_package_build}")
if repository_package > installed_package: if repository_package > installed_package:
return True return True