From 9c566be3d1cf34d8546e0e3cc6315c0d8780b1ce Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 14 Mar 2024 21:32:22 +0200 Subject: [PATCH] Updated for repos --- slpkg/binaries/install.py | 6 ----- slpkg/checks.py | 1 - slpkg/choose_packages.py | 6 ++--- slpkg/cleanings.py | 1 - slpkg/logging_deps.py | 38 ----------------------------- slpkg/main.py | 11 ++++----- slpkg/sbos/slackbuild.py | 15 ------------ slpkg/upgrade.py | 4 +-- slpkg/utilities.py | 51 +++++---------------------------------- slpkg/views/views.py | 11 +++++---- 10 files changed, 21 insertions(+), 123 deletions(-) delete mode 100644 slpkg/logging_deps.py diff --git a/slpkg/binaries/install.py b/slpkg/binaries/install.py index c5b4e54b..8d86299b 100644 --- a/slpkg/binaries/install.py +++ b/slpkg/binaries/install.py @@ -14,7 +14,6 @@ from slpkg.utilities import Utilities from slpkg.dialog_box import DialogBox from slpkg.downloader import Downloader from slpkg.views.asciibox import AsciiBox -from slpkg.logging_deps import LoggingDeps from slpkg.repositories import Repositories from slpkg.multi_process import MultiProcess from slpkg.binaries.required import Required @@ -33,7 +32,6 @@ class Packages(Configs): self.repos = Repositories() self.dialogbox = DialogBox() self.multi_proc = MultiProcess(flags) - self.logs_deps = LoggingDeps(repository, data) self.upgrade = Upgrade(repository, data) self.view = View(flags, repository, data) self.check_md5 = Md5sum(flags) @@ -156,10 +154,6 @@ class Packages(Configs): command: str = f'{self.slackware_command} {self.tmp_slpkg}/{package}' self.multi_proc.process(command, package, self.progress_message) - if not self.option_for_resolve_off: - name: str = self.utils.split_package(Path(package).stem)['name'] - self.logs_deps.logging(name) - def set_progress_message(self) -> None: if self.mode == 'upgrade' or self.option_for_reinstall: self.progress_message: str = f'{self.cyan}Upgrading{self.endc}' diff --git a/slpkg/checks.py b/slpkg/checks.py index 0a2dce15..ba828d06 100644 --- a/slpkg/checks.py +++ b/slpkg/checks.py @@ -21,7 +21,6 @@ class Check(Configs): self.repos = Repositories() self.count_rows: int = 0 - self.is_binary: bool = self.utils.is_binary_repo(repository) def package_exists_in_the_database(self, packages: list, data: dict) -> None: not_packages: list = [] diff --git a/slpkg/choose_packages.py b/slpkg/choose_packages.py index ea76db04..01a7ab19 100644 --- a/slpkg/choose_packages.py +++ b/slpkg/choose_packages.py @@ -6,6 +6,7 @@ import os from slpkg.configs import Configs from slpkg.utilities import Utilities from slpkg.dialog_box import DialogBox +from slpkg.repositories import Repositories class Choose(Configs): @@ -17,14 +18,13 @@ class Choose(Configs): self.utils = Utilities() self.dialogbox = DialogBox() + self.repos = Repositories() self.choices: list = [] self.height: int = 10 self.width: int = 70 self.list_height: int = 0 - self.is_binary: bool = self.utils.is_binary_repo(repository) - def packages(self, data: dict, packages: list, method: str) -> list: if self.dialog: title: str = f' Choose packages you want to {method} ' @@ -73,7 +73,7 @@ class Choose(Configs): inst_package_build: str = self.utils.split_package(inst_package)['build'] repo_ver: str = data[package]['version'] - if self.is_binary: + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: binary_package: str = data[package]['package'] repo_build_tag: str = self.utils.split_package(binary_package[:-4])['build'] else: diff --git a/slpkg/cleanings.py b/slpkg/cleanings.py index e629bc53..bec1f977 100644 --- a/slpkg/cleanings.py +++ b/slpkg/cleanings.py @@ -15,7 +15,6 @@ class Cleanings(Configs): def __init__(self): super(Configs, self).__init__() - self.session = Session self.view = View() self.repos = Repositories() diff --git a/slpkg/logging_deps.py b/slpkg/logging_deps.py deleted file mode 100644 index 61eacc09..00000000 --- a/slpkg/logging_deps.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- - -from slpkg.utilities import Utilities -from slpkg.binaries.required import Required -from slpkg.sbos.dependencies import Requires - - -class LoggingDeps: - """ Logging installed dependencies. """ - - def __init__(self, repository: str, data: dict): - self.data: dict = data - - self.utils = Utilities() - - self.is_binary: bool = self.utils.is_binary_repo(repository) - - def logging(self, name: str) -> None: - exist = self.session.query(LogsDependencies.name).filter( - LogsDependencies.name == name).first() - - if self.is_binary: - requires: tuple = Required(self.data, name).resolve() - else: - requires: tuple = Requires(self.data, name).resolve() - - # Update the dependencies if exist else create it. - if exist: - self.session.query( - LogsDependencies).filter( - LogsDependencies.name == name).update( - {LogsDependencies.requires: ' '.join(requires)}) - - elif requires: - dependencies: list = LogsDependencies(name=name, requires=' '.join(requires)) - self.session.add(dependencies) - self.session.commit() diff --git a/slpkg/main.py b/slpkg/main.py index f6ab4f00..8f4233de 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -299,7 +299,6 @@ class Menu(Configs): self.invalid_options() self.check_for_repositories() - self.is_binary: bool = self.utils.is_binary_repo(self.repository) self.check = Check(self.repository) self.choose = Choose(self.repository) @@ -318,8 +317,8 @@ class Menu(Configs): print('\rDatabase loading... ', end='') json_data: Path = Path(f'{self.repos.repositories_path}/{self.repository}', self.repos.data_json) - if json_data.is_file(): - self.data: dict = json.loads(json_data.read_text()) + self.data: dict = json.loads(json_data.read_text()) + print(f'{self.yellow}{self.ascii.done}{self.endc}') def check_for_repositories(self) -> None: @@ -473,7 +472,7 @@ class Menu(Configs): print('\nEverything is up-to-date!\n') raise SystemExit(0) - if self.is_binary: + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: install = Packages( self.repository, self.data, packages, self.flags, mode=command ) @@ -542,7 +541,7 @@ class Menu(Configs): self.check.package_exists_in_the_database(packages, self.data) - if self.is_binary: + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: install = Packages(self.repository, self.data, packages, self.flags, mode=command) install.execute() else: @@ -622,7 +621,7 @@ class Menu(Configs): view = ViewPackage(self.flags, self.repository) - if self.is_binary: + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: view.package(self.data, packages) else: view.slackbuild(self.data, packages) diff --git a/slpkg/sbos/slackbuild.py b/slpkg/sbos/slackbuild.py index 918e3c98..637a86e0 100644 --- a/slpkg/sbos/slackbuild.py +++ b/slpkg/sbos/slackbuild.py @@ -4,7 +4,6 @@ import os import time import shutil -import logging from pathlib import Path from collections import OrderedDict @@ -19,11 +18,9 @@ from slpkg.dialog_box import DialogBox from slpkg.downloader import Downloader from slpkg.error_messages import Errors from slpkg.views.asciibox import AsciiBox -from slpkg.logging_deps import LoggingDeps from slpkg.repositories import Repositories from slpkg.multi_process import MultiProcess from slpkg.sbos.dependencies import Requires -from slpkg.logging_config import LoggingConfig class Slackbuilds(Configs): @@ -42,7 +39,6 @@ class Slackbuilds(Configs): self.utils = Utilities() self.dialogbox = DialogBox() self.multi_proc = MultiProcess(flags) - self.logs_deps = LoggingDeps(repository, data) self.upgrade = Upgrade(repository, data) self.view = View(flags, repository, data) self.check_md5 = Md5sum(flags) @@ -75,11 +71,6 @@ class Slackbuilds(Configs): if self.repos.repositories[repository]['patch_tag']: self.repo_tag: str = self.repos.repositories[repository]['repo_tag'] - logging.basicConfig(filename=LoggingConfig.log_file, - filemode=LoggingConfig.filemode, - encoding=LoggingConfig.encoding, - level=LoggingConfig.level) - def execute(self) -> None: self.creating_dependencies_list() self.remove_duplicate_from_dependencies_list() @@ -201,9 +192,6 @@ class Slackbuilds(Configs): if self.mode in ('install', 'upgrade'): self.install_package(sbo) - - if not self.option_for_resolve_off: - self.logs_deps.logging(sbo) else: installed_package: str = self.utils.is_package_installed(sbo) self.view.skipping_packages(installed_package) @@ -231,9 +219,6 @@ class Slackbuilds(Configs): try: return max(packages) except ValueError: - logger = logging.getLogger(LoggingConfig.date_time) - logger.exception(f'{self.__class__.__name__}: ' - f'{self.__class__.find_package_for_install.__name__}') self.errors.raise_error_message(f"Package '{name}' not found for install", exit_status=20) def build_the_script(self, path: Path, name: str) -> None: diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index 61cd090a..fb519b0a 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -24,8 +24,6 @@ class Upgrade(Configs): self.repos = Repositories() self.rules = Rules() - self.is_binary: bool = self.utils.is_binary_repo(repository) - logging.basicConfig(filename=LoggingConfig.log_file, filemode=LoggingConfig.filemode, encoding=LoggingConfig.encoding, @@ -52,7 +50,7 @@ class Upgrade(Configs): inst_package_build: str = self.utils.split_package(inst_package)['build'] repo_package_version: str = self.data[name]['version'] - if self.is_binary and self.data.get(name): + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name] and self.data.get(name): repo_package: str = self.data[name]['package'] repo_package_build: str = self.utils.split_package(repo_package)['build'] else: diff --git a/slpkg/utilities.py b/slpkg/utilities.py index c0a86d7d..cf6f2901 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -6,17 +6,15 @@ import re import time import shutil import fnmatch -import logging import subprocess from pathlib import Path -from typing import Generator +from typing import Generator, Union from slpkg.configs import Configs from slpkg.blacklist import Blacklist from slpkg.views.version import Version from slpkg.error_messages import Errors from slpkg.repositories import Repositories -from slpkg.logging_config import LoggingConfig class Utilities(Configs): @@ -32,13 +30,6 @@ class Utilities(Configs): self.prog_version = Version() self.installed_packages: dict = dict(self.all_installed()) - self.process_log_date = LoggingConfig.date.replace('/', '_') - self.process_log_time = LoggingConfig.time.replace(':', '_') - - logging.basicConfig(filename=LoggingConfig.log_file, - filemode=LoggingConfig.filemode, - encoding=LoggingConfig.encoding, - level=LoggingConfig.level) def is_package_installed(self, name: str) -> str: """ Returns the installed package binary. """ @@ -130,11 +121,6 @@ class Utilities(Configs): package = package.split('#')[0].strip() yield package except FileNotFoundError: - logger = logging.getLogger(LoggingConfig.date_time) - logger.exception( - f'{self.__class__.__name__}: ' - f'{self.__class__.read_packages_from_file.__name__}' - ) self.errors.raise_error_message(f"No such file or directory: '{file}'", exit_status=20) def read_text_file(self, file: Path) -> list: @@ -143,42 +129,22 @@ class Utilities(Configs): with open(file, 'r', encoding='utf-8', errors='replace') as text_file: return text_file.readlines() except FileNotFoundError: - logger = logging.getLogger(LoggingConfig.date_time) - logger.exception( - f'{self.__class__.__name__}: ' - f'{self.__class__.read_text_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, filename=None) -> None: + @staticmethod + def process(command: str, stderr=None, stdout=None) -> None: """ Handle the processes. """ - output = tee = '' - if filename and filename.endswith('.SlackBuild') and self.process_log: - self.header_process_log(filename) - tee: str = ( - f' | tee -a {self.slpkg_log_path}/{filename}_' - f'{self.process_log_date}_{self.process_log_time}.log' - ) + output: Union = 0 try: - output = subprocess.run(f'{command}{tee}', shell=True, stderr=stderr, stdout=stdout) + output = subprocess.run(f'{command}', shell=True, stderr=stderr, stdout=stdout) except subprocess.CalledProcessError as error: - logger = logging.getLogger(LoggingConfig.date_time) - logger.exception( - f'{self.__class__.__name__}: ' - f'{self.__class__.process.__name__}: ' - f'{error}' - ) + print(error) except KeyboardInterrupt: raise SystemExit(1) if output.returncode != 0: raise SystemExit(output.returncode) - def header_process_log(self, filename: str) -> None: - """ Creates the build log file and the header. """ - with open(f'{self.slpkg_log_path}/{filename}_{self.process_log_date}_{self.process_log_time}.log', 'w') as f: - f.write(f'{LoggingConfig.date_time}: {filename}: Version: {self.prog_name} {self.prog_version.version}\n') - def get_file_size(self, file: Path) -> str: """ Get the local file size and converted to units. """ size: int = file.stat().st_size @@ -209,11 +175,6 @@ class Utilities(Configs): if [black for black in blacklist if fnmatch.fnmatch(name, black)]: return True - def is_binary_repo(self, repo: str) -> bool: - """ Returns True if the repository is binary. """ - if repo in tuple(self.repos.repositories.keys())[2:]: - return True - @staticmethod def change_owner_privileges(folder: Path) -> None: """ Changes the owner privileges. """ diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 05237d2d..61400658 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -9,6 +9,7 @@ from slpkg.upgrade import Upgrade from slpkg.utilities import Utilities from slpkg.dialog_box import DialogBox from slpkg.views.asciibox import AsciiBox +from slpkg.repositories import Repositories class View(Configs): @@ -21,6 +22,7 @@ class View(Configs): self.repository = repository self.data: dict = data + self.repos = Repositories() self.utils = Utilities() self.dialogbox = DialogBox() self.ascii = AsciiBox() @@ -28,7 +30,6 @@ class View(Configs): self.download_only = None self.summary_message: str = '' - self.is_binary: bool = self.utils.is_binary_repo(repository) self.option_for_resolve_off: bool = self.utils.is_option( ('-O', '--resolve-off'), flags) @@ -106,7 +107,7 @@ class View(Configs): color: str = self.yellow version: str = self.data[package]['version'] - if self.is_binary: + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: size: str = self.utils.convert_file_sizes(int(self.data[package]['size_comp'])) self.ascii.draw_package_line(package, version, size, color, self.repository) @@ -118,7 +119,7 @@ class View(Configs): installed: str = self.utils.is_package_installed(package) upgradable: bool = self.upgrade.is_package_upgradeable(package) - if self.is_binary: + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: size: str = self.utils.convert_file_sizes(int(self.data[package]['size_comp'])) if installed: @@ -139,7 +140,7 @@ class View(Configs): color: str = self.cyan version: str = self.data[package]['version'] - if self.is_binary: + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: size: str = self.utils.convert_file_sizes(int(self.data[package]['size_comp'])) self.ascii.draw_package_line(package, version, size, color, self.repository) @@ -168,7 +169,7 @@ class View(Configs): for pkg in packages: installed: str = self.utils.is_package_installed(pkg) - if self.is_binary: + if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]: size_comp += int(self.data[pkg]['size_comp']) size_uncomp += int(self.data[pkg]['size_uncomp'])