Updated for date

This commit is contained in:
Dimitris Zlatanidis 2023-04-27 22:37:13 +03:00
parent 60dc3659f4
commit f196af56c9
8 changed files with 38 additions and 31 deletions

View file

@ -90,7 +90,7 @@ class CheckUpdates(Configs):
try: # Try to import PySocks if it's installed.
from urllib3.contrib.socks import SOCKSProxyManager
except (ModuleNotFoundError, ImportError):
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.compare_dates.__name__)
raise SystemExit()
@ -106,7 +106,7 @@ class CheckUpdates(Configs):
repo_size: int = int(repo.headers['Content-Length'])
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.info('%s: %s: %s:', self.__class__.__name__,
self.__class__.compare_dates.__name__,
f'{local_chg_txt=}, {local_size=}, '

View file

@ -52,7 +52,7 @@ class Md5sum:
with open(filename, 'rb') as f:
return f.read()
except FileNotFoundError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.read_file.__name__)
self.errors.raise_error_message(f"No such file or directory: '{filename}'", exit_status=20)

View file

@ -131,7 +131,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slack_data.__name__)
cache.append('error checksum')
@ -222,7 +222,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slack_extra_data.__name__)
cache.append('error checksum')
@ -313,7 +313,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slack_patches_data.__name__)
cache.append('error checksum')
@ -405,7 +405,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_alien_data.__name__)
cache.append('error checksum')
@ -501,7 +501,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_multilib_data.__name__)
cache.append('error checksum')
@ -592,7 +592,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_restricted_data.__name__)
cache.append('error checksum')
@ -684,7 +684,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_gnome_data.__name__)
cache.append('error checksum')
@ -775,7 +775,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_msb_data.__name__)
cache.append('error checksum')
@ -866,7 +866,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_csb_data.__name__)
cache.append('error checksum')
@ -959,7 +959,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_conraid_data.__name__)
cache.append('error checksum')
@ -1051,7 +1051,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slackonly_data.__name__)
cache.append('error checksum')
@ -1148,7 +1148,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_salixos_data.__name__)
cache.append('error checksum')
@ -1254,7 +1254,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_salixos_extra_data.__name__)
cache.append('error checksum')
@ -1360,7 +1360,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_salixos_patches_data.__name__)
cache.append('error checksum')
@ -1465,7 +1465,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slackel_data.__name__)
cache.append('error checksum')
@ -1570,7 +1570,7 @@ class InstallData(Configs):
try:
cache.append(checksums_dict[package_name])
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.install_slint_data.__name__)
cache.append('error checksum')

View file

@ -1,13 +1,19 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import logging
from pathlib import Path
from datetime import datetime
class LoggingConfig:
dt = datetime.now()
level = logging.INFO
filemode: str = 'w'
encoding: str = 'utf-8'
log_path: Path = Path('/tmp/slpkg/logs')
log_file: Path = Path(log_path, 'slpkg.log')
d: str = '%s/%s/%s' % (dt.day, dt.month, dt.year)
t: str = '%s:%s:%s' % (dt.hour, dt.minute, dt.second)
date: str = f'{d} {t}'

View file

@ -292,8 +292,8 @@ class Argparse(Configs):
encoding=LoggingConfig.encoding,
level=LoggingConfig.level)
logger = logging.getLogger(__name__)
logger.info('%s: %s: %s:', self.__class__.__name__,
logger = logging.getLogger(LoggingConfig.date)
logger.info('%s: %s: %s', self.__class__.__name__,
self.__class__.__init__.__name__,
f'{args=}, {self.flags=}, {self.binary_repo=}')
@ -347,7 +347,7 @@ class Argparse(Configs):
if opt not in options:
invalid.append(opt)
except (KeyError, IndexError):
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.invalid_options.__name__)
self.usage.help_short(1)
@ -391,7 +391,7 @@ class Argparse(Configs):
try:
self.directory: str = self.args[self.args.index(arg) + 1]
except IndexError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.split_options_from_args.__name__)
self.directory: Path = self.tmp_slpkg
@ -406,7 +406,7 @@ class Argparse(Configs):
try:
self.binary_repo: str = self.args[self.args.index(arg) + 1]
except IndexError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.split_options_from_args.__name__)
self.binary_repo = ''
@ -771,7 +771,7 @@ class Argparse(Configs):
flags = self.commands[self.args[1]]
Help(self.args[1], flags).view()
except KeyError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.help_for_commands.__name__)
self.usage.help_minimal(f"{self.prog_name}: invalid argument '{''.join(self.args[1])}'")
@ -831,7 +831,7 @@ def main() -> None:
try:
arguments[args[0]]()
except (KeyError, IndexError):
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s:', main.__name__)
usage.help_short(1)

View file

@ -285,7 +285,7 @@ class Slackbuilds(Configs):
try:
package: str = max(packages)
except ValueError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.package_for_install.__name__)
self.errors.raise_error_message(f"Package '{name}' not found for install", exit_status=20)

View file

@ -67,7 +67,7 @@ class Upgrade(Configs):
repo_pkg: str = f'{name}-{repo_version}'
inst_pkg: str = f'{name}-{inst_version}'
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.info('%s: %s: %s', self.__class__.__name__,
self.__class__.is_package_upgradeable.__name__,
f'{repo_tag=}, {repo_pkg=}, {inst_pkg=}, {parse(repo_pkg) > parse(inst_pkg)=}, '
@ -82,6 +82,7 @@ class Upgrade(Configs):
return True
except InvalidVersion:
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s: %s', self.__class__.__name__,
self.__class__.is_package_upgradeable.__name__,
f'{repo_tag=}, {repo_pkg=}, {inst_pkg=}, {repo_pkg > inst_pkg=}, '

View file

@ -123,7 +123,7 @@ class Utilities(Configs):
yield package
except FileNotFoundError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
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)
@ -134,7 +134,7 @@ class Utilities(Configs):
with open(file, 'r', encoding='utf-8', errors='replace') as f:
return f.readlines()
except FileNotFoundError:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
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)
@ -144,7 +144,7 @@ class Utilities(Configs):
try:
subprocess.call(command, shell=True, stderr=stderr, stdout=stdout)
except subprocess.CalledProcessError as error:
logger = logging.getLogger(__name__)
logger = logging.getLogger(LoggingConfig.date)
logger.exception('%s: %s:', self.__class__.__name__,
self.__class__.process.__name__)
self.errors.raise_error_message(str(error), exit_status=20)