Updated for colors

This commit is contained in:
Dimitris Zlatanidis 2023-04-24 18:39:08 +03:00
parent 698c1998ed
commit 581b9aa428
22 changed files with 108 additions and 219 deletions

View file

@ -7,6 +7,7 @@ import subprocess
from collections import OrderedDict
from multiprocessing import Process
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.checksum import Md5sum
from slpkg.upgrade import Upgrade
@ -21,18 +22,18 @@ from slpkg.models.models import LogsDependencies
from slpkg.models.models import session as Session
class Packages(Configs):
class Packages(Configs, Colors):
def __init__(self, data: dict, packages: list, flags: list, mode: str):
__slots__ = 'data', 'packages', 'flags', 'mode'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.data: dict = data
self.packages: list = packages
self.flags: list = flags
self.mode: str = mode
self.progress = ProgressBar()
self.color = self.colour()
self.utils = Utilities()
self.repos = Repositories()
self.dialogbox = DialogBox()
@ -44,13 +45,6 @@ class Packages(Configs):
self.stderr = None
self.stdout = None
self.process_message: str = ''
self.bold: str = self.color['bold']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
self.yellow: str = self.color['yellow']
self.endc: str = self.color['endc']
self.byellow: str = f'{self.bold}{self.yellow}'
self.bred: str = f'{self.bold}{self.red}'
self.packages_requires: list = []
self.install_order: list = []

View file

@ -6,33 +6,29 @@ from pathlib import Path
from multiprocessing import Process
from urllib3 import PoolManager, ProxyManager, make_headers
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.progress_bar import ProgressBar
from slpkg.repositories import Repositories
class CheckUpdates(Configs):
class CheckUpdates(Configs, Colors):
""" Check for changes in the ChangeLog file. """
def __init__(self, flags: list, repo: str):
__slots__ = 'flags', 'repo'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.flags: list = flags
self.repo = repo
self.utils = Utilities()
self.progress = ProgressBar()
self.color = self.colour()
self.repos = Repositories()
self.compare: dict = {}
self.local_chg_txt = None
self.repo_chg_txt = None
self.bold: str = self.color['bold']
self.green: str = self.color['green']
self.yellow: str = self.color['yellow']
self.bgreen: str = f'{self.bold}{self.green}'
self.endc: str = self.color['endc']
self.option_for_binaries: bool = self.utils.is_option(
['-B', '--bin-repo='], self.flags)

34
slpkg/colors.py Normal file
View file

@ -0,0 +1,34 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from dataclasses import dataclass
from slpkg.configs import Configs
@dataclass
class Colors:
configs = Configs()
bold: str = '\033[1m'
red: str = '\x1b[91m'
bred: str = f'{bold}{red}'
green: str = '\x1b[32m'
bgreen: str = f'{bold}{green}'
yellow: str = '\x1b[93m'
byellow: str = f'{bold}{yellow}'
cyan: str = '\x1b[96m'
blue: str = '\x1b[94m'
grey: str = '\x1b[38;5;247m'
violet: str = '\x1b[35m'
endc: str = '\x1b[0m'
if not configs.colors:
bold: str = ''
red: str = ''
green: str = ''
yellow: str = ''
cyan: str = ''
blue: str = ''
grey: str = ''
violet: str = ''
endc: str = ''

View file

@ -14,12 +14,7 @@ from slpkg.logging_config import LoggingConfig
class Load:
def __init__(self):
bold = '\033[1m'
red = '\x1b[91m'
self.errors = Errors()
self.endc: str = '\x1b[0m'
self.bred: str = f'{bold}{red}'
def config_file(self, path: Path, file: str) -> dict: # type: ignore
try:
@ -29,6 +24,7 @@ class Load:
with open(config_path_file, 'rb') as conf:
return tomli.load(conf)
except tomli.TOMLDecodeError as error:
pass
self.errors.raise_toml_error_message(error, toml_file='/etc/slpkg/slpkg.toml')
@ -37,18 +33,6 @@ class Configs:
""" Default configurations. """
errors = Errors()
color = {
'bold': '\033[1m',
'red': '\x1b[91m',
'green': '\x1b[32m',
'yellow': '\x1b[93m',
'cyan': '\x1b[96m',
'blue': '\x1b[94m',
'grey': '\x1b[38;5;247m',
'violet': '\x1b[35m',
'endc': '\x1b[0m'
}
prog_name: str = 'slpkg'
os_arch: str = platform.machine()
tmp_path: str = '/tmp/'
@ -132,22 +116,3 @@ class Configs:
for path in paths:
if not os.path.isdir(path):
os.makedirs(path)
@classmethod
def colour(cls) -> dict:
if not cls.colors:
cls.color = {
'bold': '',
'red': '',
'green': '',
'yellow': '',
'cyan': '',
'blue': '',
'grey': '',
'violet': '',
'endc': ''
}
return cls.color

View file

@ -2,37 +2,31 @@
# -*- coding: utf-8 -*-
from typing import Generator
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.views.ascii import Ascii
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
class Dependees(Configs):
class Dependees(Configs, Colors):
""" Show which packages depend. """
def __init__(self, data: dict, packages: list, flags: list):
__slots__ = 'data', 'packages', 'flags'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.data: dict = data
self.packages: list = packages
self.flags: list = flags
self.ascii = Ascii()
self.repos = Repositories()
self.color = self.colour()
self.utils = Utilities()
self.llc: str = self.ascii.lower_left_corner
self.hl: str = self.ascii.horizontal_line
self.var: str = self.ascii.vertical_and_right
self.bold: str = self.color['bold']
self.violet: str = self.color['violet']
self.cyan: str = self.color['cyan']
self.grey: str = self.color['grey']
self.yellow: str = self.color['yellow']
self.byellow: str = f'{self.bold}{self.yellow}'
self.endc: str = self.color['endc']
self.option_for_full_reverse: bool = self.utils.is_option(
['-E', '--full-reverse'], self.flags)

View file

@ -5,21 +5,15 @@
class Errors:
def __init__(self):
self.prog_name: str = 'slpkg'
self.bold: str = '\033[1m'
self.red: str = '\x1b[91m'
self.cyan: str = '\x1b[96m'
self.endc: str = '\x1b[0m'
self.bred: str = f'{self.bold}{self.red}'
self.tool_name: str = 'slpkg'
def raise_error_message(self, message: str) -> None:
""" A general method to raise an error message and exit. """
raise SystemExit(f"\n{self.prog_name}: {self.bred}Error{self.endc}: {message}.\n")
raise SystemExit(f"\n{self.tool_name}: Error: {message}.\n")
def raise_toml_error_message(self, error, toml_file) -> None:
""" A general error message for .toml configs files. """
raise SystemExit(f"\n{self.prog_name} {self.bred}Error{self.endc}: {error}: in the configuration file "
raise SystemExit(f"\n{self.tool_name} Error: {error}: in the configuration file "
f"'{toml_file}', edit the file and check for errors.\n"
f"\nIf you have upgraded the '{self.prog_name}' probably you need to run:\n"
f"\n $ {self.cyan}slpkg_new-configs{self.endc}\n")
f"\nIf you have upgraded the '{self.tool_name}' probably you need to run:\n"
f"\n $ slpkg_new-configs\n")

View file

@ -1,26 +1,20 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.utilities import Utilities
class FindInstalled(Configs):
class FindInstalled(Configs, Colors):
""" Find installed packages. """
def __init__(self):
super(Configs, self).__init__()
super(Colors, self).__init__()
self.color = self.colour()
self.utils = Utilities()
self.matching: list = []
self.yellow: str = self.color['yellow']
self.cyan: str = self.color['cyan']
self.green: str = self.color['green']
self.blue: str = self.color['blue']
self.endc: str = self.color['endc']
self.grey: str = self.color['grey']
def find(self, packages: list) -> None:
""" Find the packages. """

View file

@ -3,6 +3,7 @@
from pathlib import Path
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
@ -11,20 +12,14 @@ from slpkg.models.models import (SBoTable, PonceTable,
BinariesTable, LastRepoUpdated)
class InstallData(Configs):
class InstallData(Configs, Colors):
def __init__(self):
super(Configs, self).__init__()
super(Colors, self).__init__()
self.session = Session
self.utils = Utilities()
self.repos = Repositories()
self.color = self.colour()
self.bold: str = self.color['bold']
self.yellow: str = self.color['yellow']
self.cyan: str = self.color['cyan']
self.byellow: str = f'{self.bold}{self.yellow}'
self.endc: str = self.color['endc']
def last_updated(self, repo_file: Path) -> str:
""" Reads the first date of the changelog file."""

View file

@ -7,6 +7,7 @@ import logging
from pathlib import Path
from slpkg.checks import Check
from slpkg.colors import Colors
from slpkg.upgrade import Upgrade
from slpkg.configs import Configs
from slpkg.tracking import Tracking
@ -35,25 +36,22 @@ from slpkg.clean_logs import CleanLogsDependencies
from slpkg.update_repository import UpdateRepository
class Argparse(Configs):
class Argparse(Configs, Colors):
def __init__(self, args: list):
__slots__ = 'args'
super(Configs).__init__()
super(Colors).__init__()
self.args: list = args
self.flags: list = []
self.directory = self.tmp_slpkg
self.dialogbox = DialogBox()
self.utils = Utilities()
self.usage = Usage()
self.form_configs = FormConfigs()
self.color = self.colour()
self.repos = Repositories()
self.bold: str = self.color['bold']
self.red: str = self.color['red']
self.endc: str = self.color['endc']
self.bred: str = f'{self.bold}{self.red}'
self.binary_repo: str = ''
if len(self.args) == 0 or '' in self.args:

View file

@ -5,23 +5,15 @@ import time
from progress.spinner import (PixelSpinner, LineSpinner,
MoonSpinner, PieSpinner, Spinner)
from slpkg.colors import Colors
from slpkg.configs import Configs
class ProgressBar(Configs):
class ProgressBar(Configs, Colors):
def __init__(self):
super(Configs, self).__init__()
self.color = self.colour()
self.violet: str = self.color['violet']
self.green: str = self.color['green']
self.blue: str = self.color['blue']
self.red: str = self.color['red']
self.grey: str = self.color['grey']
self.yellow: str = self.color['yellow']
self.cyan: str = self.color['cyan']
self.endc: str = self.color['endc']
super(Colors, self).__init__()
def bar(self, message: str, filename: str) -> None:
""" Creating progress bar. """

View file

@ -5,6 +5,7 @@ import time
import subprocess
from multiprocessing import Process
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.views.views import ViewMessage
@ -13,17 +14,17 @@ from slpkg.models.models import LogsDependencies
from slpkg.models.models import session as Session
class RemovePackages(Configs):
class RemovePackages(Configs, Colors):
""" Removes installed packages. """
def __init__(self, packages: list, flags: list):
__slots__ = 'packages', 'flags'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.packages: list = packages
self.flags: list = flags
self.session = Session
self.color = self.colour()
self.utils = Utilities()
self.progress = ProgressBar()
self.view = ViewMessage(self.flags)
@ -33,13 +34,6 @@ class RemovePackages(Configs):
self.dependencies: list = []
self.stderr = None
self.stdout = None
self.bold: str = self.color['bold']
self.cyan: str = self.color['cyan']
self.yellow: str = self.color['yellow']
self.red: str = self.color['red']
self.endc: str = self.color['endc']
self.byellow: str = f'{self.bold}{self.yellow}'
self.bred: str = f'{self.bold}{self.red}'
self.option_resolve_off: bool = self.utils.is_option(
['-o', '--resolve-off'], self.flags)

View file

@ -3,6 +3,7 @@
import shutil
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
@ -10,25 +11,16 @@ from slpkg.models.models import session as Session
from slpkg.models.models import LastRepoUpdated, SBoTable, BinariesTable
class RepoInfo(Configs):
class RepoInfo(Configs, Colors):
def __init__(self):
super(Configs, self).__init__()
super(Colors, self).__init__()
self.session = Session
self.utils = Utilities()
self.repos = Repositories()
self.color = self.colour()
self.columns, self.rows = shutil.get_terminal_size()
self.session = Session
self.bold: str = self.color['bold']
self.green: str = self.color['green']
self.red: str = self.color['red']
self.cyan: str = self.color['cyan']
self.grey: str = self.color['grey']
self.yellow: str = self.color['yellow']
self.byellow: str = f'{self.bold}{self.yellow}'
self.endc: str = self.color['endc']
def info(self):
""" Prints information about repositories. """
@ -41,7 +33,6 @@ class RepoInfo(Configs):
print('=' * self.columns)
for repo, value in self.repos.repositories.items():
count: int = 0
status: str = 'Disabled'
color: str = self.red

View file

@ -10,6 +10,7 @@ from pathlib import Path
from collections import OrderedDict
from multiprocessing import Process, cpu_count
from slpkg.colors import Colors
from slpkg.checksum import Md5sum
from slpkg.configs import Configs
from slpkg.upgrade import Upgrade
@ -25,12 +26,13 @@ from slpkg.models.models import LogsDependencies
from slpkg.models.models import session as Session
class Slackbuilds(Configs):
class Slackbuilds(Configs, Colors):
""" Download build and install the SlackBuilds. """
def __init__(self, data: dict, slackbuilds: list, flags: list, mode: str):
__slots__ = 'data', 'slackbuilds', 'flags', 'mode'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.data = data
self.slackbuilds: list = slackbuilds
self.flags: list = flags
@ -44,7 +46,6 @@ class Slackbuilds(Configs):
self.dialogbox = DialogBox()
self.upgrade = Upgrade(self.flags, data)
self.view_message = ViewMessage(self.flags, data)
self.color = self.colour()
self.stderr = None
self.stdout = None
@ -52,13 +53,6 @@ class Slackbuilds(Configs):
self.install_order: list = []
self.dependencies: list = []
self.process_message: str = ''
self.bold: str = self.color['bold']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
self.yellow: str = self.color['yellow']
self.endc: str = self.color['endc']
self.byellow: str = f'{self.bold}{self.yellow}'
self.bred: str = f'{self.bold}{self.red}'
self.option_for_reinstall: bool = self.utils.is_option(
['-r', '--reinstall'], self.flags)

View file

@ -1,30 +1,25 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
from slpkg.binaries.queries import BinQueries
class SearchPackage(Configs):
class SearchPackage(Configs, Colors):
""" Search packages from the repositories. """
def __init__(self, flags=None):
__slots__ = 'flags'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.flags: list = flags
self.color = self.colour()
self.utils = Utilities()
self.repos = Repositories()
self.yellow: str = self.color['yellow']
self.cyan: str = self.color['cyan']
self.green: str = self.color['green']
self.grey: str = self.color['grey']
self.endc: str = self.color['endc']
self.option_for_binaries: bool = self.utils.is_option(
['-B', '--bin-repo='], self.flags)

View file

@ -1,30 +1,27 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.views.ascii import Ascii
from slpkg.utilities import Utilities
class Tracking(Configs):
class Tracking(Configs, Colors):
""" Tracking of the package dependencies. """
def __init__(self, flags: list):
__slots__ = 'flags'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.flags: list = flags
self.ascii = Ascii()
self.color = self.colour()
self.utils = Utilities()
self.llc: str = self.ascii.lower_left_corner
self.hl: str = self.ascii.horizontal_line
self.vl: str = self.ascii.vertical_line
self.cyan: str = self.color['cyan']
self.grey: str = self.color['grey']
self.yellow: str = self.color['yellow']
self.endc: str = self.color['endc']
self.option_for_pkg_version: bool = self.utils.is_option(
['-p', '--pkg-version'], self.flags)

View file

@ -6,6 +6,7 @@ import shutil
from pathlib import Path
from multiprocessing import Process, Queue
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.downloader import Downloader
@ -20,21 +21,21 @@ from slpkg.models.models import (Base, engine, SBoTable,
LastRepoUpdated)
class UpdateRepository(Configs):
class UpdateRepository(Configs, Colors):
""" Deletes and install the data. """
def __init__(self, flags: list, repo: str):
__slots__ = 'flags', 'repo'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.flags: list = flags
self.repo: str = repo
self.session = Session
self.view = ViewMessage(self.flags)
self.repos = Repositories()
self.progress = ProgressBar()
self.utils = Utilities()
self.color = self.colour()
self.data = InstallData()
self.check_updates = CheckUpdates(
@ -42,13 +43,6 @@ class UpdateRepository(Configs):
)
self.repos_for_update: dict = {}
self.bold: str = self.color['bold']
self.green: str = self.color['green']
self.red: str = self.color['red']
self.yellow: str = self.color['yellow']
self.bgreen: str = f'{self.bold}{self.green}'
self.bred: str = f'{self.bold}{self.red}'
self.endc: str = self.color['endc']
self.option_for_generate: bool = self.utils.is_option(
['-G', '--generate-only'], self.flags)

View file

@ -10,6 +10,7 @@ import subprocess
from pathlib import Path
from typing import Generator, Union
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.blacklist import Blacklist
from slpkg.errors_messages import Errors
@ -17,23 +18,16 @@ from slpkg.repositories import Repositories
from slpkg.logging_config import LoggingConfig
class Utilities:
class Utilities(Colors):
def __init__(self):
super(Colors, self).__init__()
self.configs = Configs
self.colors = self.configs.colour
self.color = self.colors()
self.colors = Colors()
self.black = Blacklist()
self.errors = Errors()
self.repos = Repositories()
self.bold: str = self.color['bold']
self.yellow: str = self.color['yellow']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
self.endc: str = self.color['endc']
self.bred: str = f'{self.bold}{self.red}'
self.installed_packages: dict = dict(self.all_installed())
logging.basicConfig(filename=LoggingConfig.log_file,

View file

@ -3,14 +3,15 @@
import shutil
from slpkg.colors import Colors
from slpkg.configs import Configs
class Ascii(Configs):
class Ascii(Configs, Colors):
""" ascii characters. """
def __init__(self):
super(Configs, self).__init__()
self.color = self.colour()
super(Colors, self).__init__()
self.columns, self.rows = shutil.get_terminal_size()
self.vertical_line: str = '|'
@ -38,17 +39,6 @@ class Ascii(Configs):
self.vertical_and_right: str = ''
self.vertical_and_left: str = ''
self.bold: str = self.color['bold']
self.blue: str = self.color['blue']
self.green: str = self.color['green']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
self.yellow: str = self.color['yellow']
self.violet: str = self.color['violet']
self.endc: str = self.color['endc']
self.bgreen: str = f'{self.bold}{self.green}'
self.bred: str = f'{self.bold}{self.red}'
def draw_package_title_box(self, message: str, title: str) -> None:
""" Drawing package title box. """
title = title.title()

View file

@ -2,20 +2,22 @@
# -*- coding: utf-8 -*-
from typing import NoReturn
from slpkg.colors import Colors
from slpkg.configs import Configs
class Usage(Configs):
class Usage(Configs, Colors):
def __init__(self):
super(Configs, self).__init__()
color = self.colour()
self.bold: str = color['bold']
self.red: str = color['red']
self.cyan: str = color['cyan']
self.yellow: str = color['yellow']
self.endc: str = color['endc']
super(Colors, self).__init__()
# color = self.colour()
#
# self.bold: str = color['bold']
# self.red: str = color['red']
# self.cyan: str = color['cyan']
# self.yellow: str = color['yellow']
# self.endc: str = color['endc']
def help_minimal(self, message: str) -> NoReturn:
""" Prints the minimal help menu. """

View file

@ -1,25 +1,19 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.colors import Colors
from slpkg.configs import Configs
class Help(Configs):
class Help(Configs, Colors):
def __init__(self, command: str, flags: list):
__slots__ = 'command', 'flags'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.command: str = command
self.flags: list = flags
color = self.colour()
self.bold: str = color['bold']
self.green: str = color['green']
self.cyan: str = color['cyan']
self.yellow: str = color['yellow']
self.endc: str = color['endc']
def view(self) -> None:
self.flags.reverse() # Put first the short options.

View file

@ -3,6 +3,7 @@
from pathlib import Path
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
@ -11,27 +12,19 @@ from slpkg.models.models import (SBoTable, PonceTable,
BinariesTable, LastRepoUpdated)
class ViewPackage(Configs):
class ViewPackage(Configs, Colors):
""" View the repository packages. """
def __init__(self, flags: list):
__slots__ = 'flags'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.flags: list = flags
self.utils = Utilities()
self.repos = Repositories()
self.session = Session
self.color = self.colour()
self.green: str = self.color['green']
self.blue: str = self.color['blue']
self.yellow: str = self.color['yellow']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
self.violet: str = self.color['violet']
self.endc: str = self.color['endc']
# Switch between sbo and ponce repository.
self.sbo_table = SBoTable
self.repo_url: str = self.repos.sbo_repo_mirror[0]

View file

@ -6,6 +6,7 @@ import re
from typing import Any
from pathlib import Path
from slpkg.colors import Colors
from slpkg.configs import Configs
from slpkg.upgrade import Upgrade
from slpkg.views.ascii import Ascii
@ -16,11 +17,12 @@ from slpkg.models.models import LogsDependencies
from slpkg.models.models import session as Session
class ViewMessage(Configs):
class ViewMessage(Configs, Colors):
def __init__(self, flags: list, data=None):
__slots__ = 'flags', 'data'
super(Configs, self).__init__()
super(Colors, self).__init__()
self.flags: list = flags
self.data: dict = data
@ -29,15 +31,8 @@ class ViewMessage(Configs):
self.dialogbox = DialogBox()
self.ascii = Ascii()
self.upgrade = Upgrade(self.flags, self.data)
self.color = self.colour()
self.repos = Repositories()
self.yellow: str = self.color['yellow']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
self.grey: str = self.color['grey']
self.violet: str = self.color['violet']
self.endc: str = self.color['endc']
self.download_only = self.tmp_slpkg
self.installed_packages: list = []