mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-26 09:58:31 +01:00
Updated for inheritance classes
This commit is contained in:
parent
644522f2a7
commit
8556d0f30c
11 changed files with 71 additions and 84 deletions
|
@ -12,18 +12,18 @@ from slpkg.views.version import Version
|
|||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
|
||||
class DialogBox:
|
||||
class DialogBox(Configs):
|
||||
""" Class for dialog box"""
|
||||
|
||||
def __init__(self):
|
||||
self.configs = Configs()
|
||||
super(Configs).__init__()
|
||||
self.d = Dialog(dialog="dialog")
|
||||
self.d.set_background_title(f'{self.configs.prog_name} {Version().version} - Software Package Manager')
|
||||
self.d.set_background_title(f'{self.prog_name} {Version().version} - Software Package Manager')
|
||||
|
||||
def checklist(self, text: str, title: str, height: int, width: int,
|
||||
list_height: int, choices: list, packages: list):
|
||||
""" Display a checklist box. """
|
||||
if self.configs.dialog:
|
||||
if self.dialog:
|
||||
code, tags = self.d.checklist(text, title=title, height=height, width=width,
|
||||
list_height=list_height, choices=choices)
|
||||
else:
|
||||
|
@ -34,7 +34,7 @@ class DialogBox:
|
|||
|
||||
def mixedform(self, text: str, title: str, elements: list, height: int, width: int):
|
||||
""" Display a mixedform box. """
|
||||
if self.configs.dialog:
|
||||
if self.dialog:
|
||||
code, tags = self.d.mixedform(text=text, title=title, elements=elements,
|
||||
height=height, width=width, help_button=True)
|
||||
else:
|
||||
|
@ -45,10 +45,10 @@ class DialogBox:
|
|||
|
||||
def msgbox(self, text: str, height: int, width: int):
|
||||
""" Display a message box. """
|
||||
if self.configs.dialog:
|
||||
if self.dialog:
|
||||
self.d.msgbox(text, height, width)
|
||||
|
||||
def textbox(self, text: Union[str, Path], height: int, width: int):
|
||||
""" Display a text box. """
|
||||
if self.configs.dialog:
|
||||
if self.dialog:
|
||||
self.d.textbox(text, height, width)
|
||||
|
|
|
@ -10,7 +10,7 @@ from slpkg.configs import Configs
|
|||
from slpkg.progress_bar import ProgressBar
|
||||
|
||||
|
||||
class Downloader:
|
||||
class Downloader(Configs):
|
||||
""" Wget downloader. """
|
||||
|
||||
def __init__(self, path: Union[str, Path], url: str, flags: list):
|
||||
|
@ -19,9 +19,7 @@ class Downloader:
|
|||
self.flags = flags
|
||||
self.flag_no_silent = '--no-silent'
|
||||
self.filename = url.split('/')[-1]
|
||||
self.configs = Configs
|
||||
self.colors = self.configs.colour
|
||||
self.color = self.colors()
|
||||
self.color = self.colour()
|
||||
self.bold = self.color['bold']
|
||||
self.green = self.color['green']
|
||||
self.yellow = self.color['yellow']
|
||||
|
@ -37,7 +35,7 @@ class Downloader:
|
|||
|
||||
def wget(self):
|
||||
""" Wget downloader. """
|
||||
self.output = subprocess.call(f'wget {self.configs.wget_options} --directory-prefix={self.path} {self.url}',
|
||||
self.output = subprocess.call(f'wget {self.wget_options} --directory-prefix={self.path} {self.url}',
|
||||
shell=True, stderr=self.stderr, stdout=self.stdout)
|
||||
if self.output != 0:
|
||||
raise SystemExit(self.output)
|
||||
|
@ -52,7 +50,7 @@ class Downloader:
|
|||
|
||||
def download(self):
|
||||
""" Starting multiprocessing download process. """
|
||||
if self.configs.silent_mode and self.flag_no_silent not in self.flags:
|
||||
if self.silent_mode and self.flag_no_silent not in self.flags:
|
||||
|
||||
done = f' {self.byellow} Done{self.endc}'
|
||||
self.stderr = subprocess.DEVNULL
|
||||
|
|
|
@ -5,25 +5,24 @@ from slpkg.configs import Configs
|
|||
from slpkg.utilities import Utilities
|
||||
|
||||
|
||||
class FindInstalled:
|
||||
class FindInstalled(Configs, Utilities):
|
||||
""" Find installed packages. """
|
||||
|
||||
def __init__(self):
|
||||
self.configs = Configs
|
||||
self.colors = self.configs.colour
|
||||
self.color = self.colors()
|
||||
super(Configs, self).__init__()
|
||||
super(Utilities, self).__init__()
|
||||
self.color = self.colour()
|
||||
self.yellow = self.color['yellow']
|
||||
self.cyan = self.color['cyan']
|
||||
self.green = self.color['green']
|
||||
self.blue = self.color['blue']
|
||||
self.endc = self.color['endc']
|
||||
self.grey = self.color['grey']
|
||||
self.utils = Utilities()
|
||||
|
||||
def find(self, packages: list):
|
||||
""" Find the packages. """
|
||||
matching = []
|
||||
installed = self.utils.all_installed()
|
||||
installed = self.all_installed()
|
||||
|
||||
print(f'The list below shows the installed packages '
|
||||
f'that contains \'{", ".join([p for p in packages])}\' files:\n')
|
||||
|
@ -38,7 +37,7 @@ class FindInstalled:
|
|||
""" Print the matched packages. """
|
||||
if matching:
|
||||
for package in matching:
|
||||
pkg = self.utils.split_installed_pkg(package)
|
||||
pkg = self.split_installed_pkg(package)
|
||||
print(f'{self.cyan}{pkg[0]}{self.endc}-{self.yellow}{pkg[1]}{self.endc}-{pkg[2]}-'
|
||||
f'{self.blue}{pkg[3]}{self.endc}_{pkg[4]}')
|
||||
print(f'\n{self.grey}Total found {len(matching)} packages.{self.endc}')
|
||||
|
|
|
@ -9,24 +9,22 @@ from slpkg.configs import LoadConfigs
|
|||
from slpkg.dialog_box import DialogBox
|
||||
|
||||
|
||||
class FormConfigs:
|
||||
class FormConfigs(Configs):
|
||||
|
||||
def __init__(self):
|
||||
self.orig_configs = None
|
||||
self.configs = Configs()
|
||||
self.load_configs = LoadConfigs()
|
||||
self.dialog = DialogBox()
|
||||
self.config_file = Path(self.configs.etc_path, f'{self.configs.prog_name}.toml')
|
||||
self.dialogbox = DialogBox()
|
||||
self.config_file = Path(self.etc_path, f'{self.prog_name}.toml')
|
||||
|
||||
def edit(self):
|
||||
""" Read and write the configuration file. """
|
||||
elements = []
|
||||
config_file = Path(self.configs.etc_path, f'{self.configs.prog_name}.toml')
|
||||
config_file = Path(self.etc_path, f'{self.prog_name}.toml')
|
||||
|
||||
if config_file.is_file():
|
||||
# Load the toml config file.
|
||||
configs = self.load_configs.file(self.configs.etc_path,
|
||||
self.configs.prog_name)
|
||||
configs = self.load_configs.file(self.etc_path, self.prog_name)
|
||||
|
||||
# Creating the elements for the dialog form.
|
||||
for i, (key, value) in enumerate(configs['configs'].items(), start=1):
|
||||
|
@ -43,7 +41,7 @@ class FormConfigs:
|
|||
text = f'Edit the configuration file: {config_file}'
|
||||
title = ' Configuration File '
|
||||
|
||||
code, tags = self.dialog.mixedform(text, title, elements, height, width)
|
||||
code, tags = self.dialogbox.mixedform(text, title, elements, height, width)
|
||||
|
||||
os.system('clear')
|
||||
|
||||
|
@ -59,14 +57,14 @@ class FormConfigs:
|
|||
def help(self):
|
||||
""" Load the configuration file on a text box. """
|
||||
self.read_configs()
|
||||
self.dialog.textbox(str(self.config_file), 40, 60)
|
||||
self.dialogbox.textbox(str(self.config_file), 40, 60)
|
||||
self.edit()
|
||||
|
||||
def check_configs(self, configs: dict, tags: list) -> bool:
|
||||
""" Check for true of false values. """
|
||||
for key, value in zip(configs['configs'].keys(), tags):
|
||||
if key in ['colors', 'dialog', 'silent_mode'] and value not in ['true', 'false']:
|
||||
self.dialog.msgbox(f"\nError value for {key}. It must be 'true' or 'false'\n", height=7, width=60)
|
||||
self.dialogbox.msgbox(f"\nError value for {key}. It must be 'true' or 'false'\n", height=7, width=60)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -26,14 +26,13 @@ from slpkg.clean_logs import CleanLogsDependencies
|
|||
from slpkg.update_repository import UpdateRepository
|
||||
|
||||
|
||||
class Argparse:
|
||||
class Argparse(Configs):
|
||||
|
||||
def __init__(self, args: list):
|
||||
self.args = args
|
||||
self.flags = []
|
||||
self.directory = None
|
||||
self.configs = Configs
|
||||
self.dialog = DialogBox()
|
||||
self.dialogbox = DialogBox()
|
||||
self.utils = Utilities()
|
||||
self.usage = Usage()
|
||||
self.check = Check()
|
||||
|
@ -82,8 +81,8 @@ class Argparse:
|
|||
|
||||
def is_dialog_enabled(self):
|
||||
""" Checking if the dialog box is enabled. """
|
||||
if (not self.configs.dialog and self.flag_search in self.args or
|
||||
not self.configs.dialog and 'configs' in self.args):
|
||||
if (not self.dialogbox and self.flag_search in self.args or
|
||||
not self.dialogbox.dialog and 'configs' in self.args):
|
||||
raise SystemExit("\nError: You should enable the dialog "
|
||||
"in the '/etc/slpkg/' folder.\n")
|
||||
|
||||
|
@ -204,8 +203,8 @@ class Argparse:
|
|||
|
||||
text = f'There are {len(choices)} packages:'
|
||||
|
||||
code, tags = self.dialog.checklist(text, title, height, width,
|
||||
list_height, choices, packages)
|
||||
code, tags = self.dialogbox.checklist(text, title, height, width,
|
||||
list_height, choices, packages)
|
||||
|
||||
if not code:
|
||||
return packages
|
||||
|
@ -282,9 +281,9 @@ class Argparse:
|
|||
|
||||
def clean_tmp(self):
|
||||
if len(self.args) == 1:
|
||||
path = self.configs.tmp_path
|
||||
tmp_slpkg = self.configs.tmp_slpkg
|
||||
folder = self.configs.prog_name
|
||||
path = self.tmp_path
|
||||
tmp_slpkg = self.tmp_slpkg
|
||||
folder = self.prog_name
|
||||
|
||||
self.utils.remove_folder_if_exists(path, folder)
|
||||
self.utils.create_folder(tmp_slpkg, 'build')
|
||||
|
|
|
@ -7,12 +7,10 @@ from progress.spinner import PixelSpinner
|
|||
from slpkg.configs import Configs
|
||||
|
||||
|
||||
class ProgressBar:
|
||||
class ProgressBar(Configs):
|
||||
|
||||
def __init__(self):
|
||||
self.configs = Configs
|
||||
self.colors = self.configs.colour
|
||||
self.color = self.colors()
|
||||
self.color = self.colour()
|
||||
self.bold = self.color['bold']
|
||||
self.violet = self.color['violet']
|
||||
self.bviolet = f'{self.bold}{self.violet}'
|
||||
|
|
|
@ -7,13 +7,13 @@ from slpkg.models.models import SBoTable
|
|||
from slpkg.models.models import session as Session
|
||||
|
||||
|
||||
class SBoQueries:
|
||||
class SBoQueries(Configs):
|
||||
""" Queries class for the sbo repository. """
|
||||
|
||||
def __init__(self, name: str):
|
||||
super(Configs, self).__init__()
|
||||
self.name = name
|
||||
self.session = Session
|
||||
self.configs = Configs
|
||||
|
||||
self.black = Blacklist()
|
||||
if self.name in self.black.get():
|
||||
|
@ -48,7 +48,7 @@ class SBoQueries:
|
|||
SBoTable.download, SBoTable.download64).filter(
|
||||
SBoTable.name == self.name).first()
|
||||
|
||||
if self.configs.os_arch == 'x86_64' and source64:
|
||||
if self.os_arch == 'x86_64' and source64:
|
||||
return source64.split()
|
||||
|
||||
return source.split()
|
||||
|
@ -83,7 +83,7 @@ class SBoQueries:
|
|||
SBoTable.md5sum, SBoTable.md5sum64).filter(
|
||||
SBoTable.name == self.name).first()
|
||||
|
||||
if self.configs.os_arch == 'x86_64' and md5s64:
|
||||
if self.os_arch == 'x86_64' and md5s64:
|
||||
return md5s64.split()
|
||||
|
||||
return mds5.split()
|
||||
|
|
|
@ -13,16 +13,14 @@ from slpkg.models.models import LogsDependencies
|
|||
from slpkg.models.models import session as Session
|
||||
|
||||
|
||||
class RemovePackages:
|
||||
class RemovePackages(Configs):
|
||||
""" Removes installed packages. """
|
||||
|
||||
def __init__(self, packages: list, flags: list):
|
||||
self.packages = packages
|
||||
self.flags = flags
|
||||
self.session = Session
|
||||
self.configs = Configs
|
||||
self.colors = self.configs.colour
|
||||
self.color = self.colors()
|
||||
self.color = self.colour()
|
||||
self.bold = self.color['bold']
|
||||
self.yellow = self.color['yellow']
|
||||
self.red = self.color['red']
|
||||
|
@ -65,7 +63,7 @@ class RemovePackages:
|
|||
""" Run Slackware command to remove the packages. """
|
||||
for package in self.installed_packages:
|
||||
self.remove_pkg = package
|
||||
command = f'{self.configs.removepkg} {package}'
|
||||
command = f'{self.removepkg} {package}'
|
||||
self.multi_process(command, package)
|
||||
|
||||
def delete_main_logs(self):
|
||||
|
@ -84,7 +82,7 @@ class RemovePackages:
|
|||
|
||||
def multi_process(self, command, package):
|
||||
""" Starting multiprocessing remove process. """
|
||||
if self.configs.silent_mode and self.flag_no_silent not in self.flags:
|
||||
if self.silent_mode and self.flag_no_silent not in self.flags:
|
||||
|
||||
done = f' {self.byellow} Done{self.endc}'
|
||||
message = f'{self.red}Remove{self.endc}'
|
||||
|
|
|
@ -5,12 +5,11 @@ from slpkg.queries import SBoQueries
|
|||
from slpkg.configs import Configs
|
||||
|
||||
|
||||
class SearchPackage:
|
||||
class SearchPackage(Configs):
|
||||
""" Search slackbuilds from the repository. """
|
||||
|
||||
def __init__(self):
|
||||
self.colors = Configs.colour
|
||||
self.color = self.colors()
|
||||
self.color = self.colour()
|
||||
self.yellow = self.color['yellow']
|
||||
self.cyan = self.color['cyan']
|
||||
self.endc = self.color['endc']
|
||||
|
|
|
@ -22,10 +22,11 @@ from slpkg.models.models import LogsDependencies
|
|||
from slpkg.models.models import session as Session
|
||||
|
||||
|
||||
class Slackbuilds:
|
||||
class Slackbuilds(Configs):
|
||||
""" Download build and install the SlackBuilds. """
|
||||
|
||||
def __init__(self, slackbuilds: list, flags: list, mode: str):
|
||||
super(Configs, self).__init__()
|
||||
self.slackbuilds = slackbuilds
|
||||
self.flags = flags
|
||||
self.mode = mode
|
||||
|
@ -38,12 +39,10 @@ class Slackbuilds:
|
|||
self.process_message = None
|
||||
self.session = Session
|
||||
self.utils = Utilities()
|
||||
self.dialog = DialogBox()
|
||||
self.progress = ProgressBar()
|
||||
self.dialogbox = DialogBox()
|
||||
self.view_message = ViewMessage(self.flags)
|
||||
self.configs = Configs
|
||||
self.colors = self.configs.colour
|
||||
self.color = self.colors()
|
||||
self.color = self.colour()
|
||||
self.bold = self.color['bold']
|
||||
self.cyan = self.color['cyan']
|
||||
self.red = self.color['red']
|
||||
|
@ -131,18 +130,18 @@ class Slackbuilds:
|
|||
|
||||
if self.is_for_skipped(sbo):
|
||||
|
||||
file = f'{sbo}{self.configs.sbo_tar_suffix}'
|
||||
file = f'{sbo}{self.sbo_tar_suffix}'
|
||||
|
||||
self.utils.remove_file_if_exists(self.configs.tmp_slpkg, file)
|
||||
self.utils.remove_folder_if_exists(self.configs.build_path, sbo)
|
||||
self.utils.remove_file_if_exists(self.tmp_slpkg, file)
|
||||
self.utils.remove_folder_if_exists(self.build_path, sbo)
|
||||
|
||||
location = SBoQueries(sbo).location()
|
||||
url = f'{self.configs.sbo_repo_url}/{location}/{file}'
|
||||
url = f'{self.sbo_repo_url}/{location}/{file}'
|
||||
|
||||
down_sbo = Downloader(self.configs.tmp_slpkg, url, self.flags)
|
||||
down_sbo = Downloader(self.tmp_slpkg, url, self.flags)
|
||||
down_sbo.download()
|
||||
|
||||
self.utils.untar_archive(self.configs.tmp_slpkg, file, self.configs.build_path)
|
||||
self.utils.untar_archive(self.tmp_slpkg, file, self.build_path)
|
||||
|
||||
self.patch_sbo_tag(sbo)
|
||||
|
||||
|
@ -155,7 +154,7 @@ class Slackbuilds:
|
|||
|
||||
if self.is_for_skipped(sbo):
|
||||
|
||||
self.build_the_script(self.configs.build_path, sbo)
|
||||
self.build_the_script(self.build_path, sbo)
|
||||
|
||||
if not self.mode == 'build':
|
||||
|
||||
|
@ -171,7 +170,7 @@ class Slackbuilds:
|
|||
|
||||
def patch_sbo_tag(self, sbo):
|
||||
""" Patching SBo TAG from the configuration file. """
|
||||
sbo_script = Path(self.configs.build_path, sbo, f'{sbo}.SlackBuild')
|
||||
sbo_script = Path(self.build_path, sbo, f'{sbo}.SlackBuild')
|
||||
|
||||
if sbo_script.is_file():
|
||||
with open(sbo_script, 'r', encoding='utf-8') as f:
|
||||
|
@ -180,7 +179,7 @@ class Slackbuilds:
|
|||
with open(sbo_script, 'w') as script:
|
||||
for line in lines:
|
||||
if line.startswith('TAG=$'):
|
||||
line = f'TAG=${{TAG:-{self.configs.sbo_repo_tag}}}\n'
|
||||
line = f'TAG=${{TAG:-{self.sbo_repo_tag}}}\n'
|
||||
script.write(line)
|
||||
|
||||
def logging_installed_dependencies(self, name: str):
|
||||
|
@ -206,10 +205,10 @@ class Slackbuilds:
|
|||
""" Install the packages that before created in the tmp directory. """
|
||||
pkg = self.utils.split_installed_pkg(package)[0]
|
||||
|
||||
execute = self.configs.installpkg
|
||||
execute = self.installpkg
|
||||
if (self.flag_reinstall in self.flags and
|
||||
self.utils.is_installed(pkg)):
|
||||
execute = self.configs.reinstall
|
||||
execute = self.reinstall
|
||||
|
||||
message = f'{self.cyan}Installing{self.endc}'
|
||||
self.process_message = f"'{pkg}' to install"
|
||||
|
@ -218,7 +217,7 @@ class Slackbuilds:
|
|||
self.process_message = f"package '{pkg}' to upgrade"
|
||||
message = f'{self.cyan}Upgrade{self.endc}'
|
||||
|
||||
command = f'{execute} {self.configs.tmp_path}/{package}'
|
||||
command = f'{execute} {self.tmp_path}/{package}'
|
||||
|
||||
self.multi_process(command, package, message)
|
||||
|
||||
|
@ -227,9 +226,9 @@ class Slackbuilds:
|
|||
installation. """
|
||||
version = SBoQueries(name).version()
|
||||
|
||||
pattern = f'{name}-{version}*{self.configs.sbo_repo_tag}*'
|
||||
pattern = f'{name}-{version}*{self.sbo_repo_tag}*'
|
||||
|
||||
tmp = Path(self.configs.tmp_path)
|
||||
tmp = Path(self.tmp_path)
|
||||
packages = [file.name for file in tmp.glob(pattern)]
|
||||
|
||||
return max(packages)
|
||||
|
@ -259,7 +258,7 @@ class Slackbuilds:
|
|||
|
||||
def download_sources(self, name: str, sources: list):
|
||||
""" Download the sources. """
|
||||
path = Path(self.configs.build_path, name)
|
||||
path = Path(self.build_path, name)
|
||||
checksums = SBoQueries(name).checksum()
|
||||
|
||||
for source, checksum in zip(sources, checksums):
|
||||
|
@ -271,7 +270,7 @@ class Slackbuilds:
|
|||
|
||||
def multi_process(self, command, filename, message):
|
||||
""" Starting multiprocessing install/upgrade process. """
|
||||
if self.configs.silent_mode and self.flag_no_silent not in self.flags:
|
||||
if self.silent_mode and self.flag_no_silent not in self.flags:
|
||||
|
||||
done = f' {self.byellow} Done{self.endc}'
|
||||
self.stderr = subprocess.DEVNULL
|
||||
|
@ -339,8 +338,8 @@ class Slackbuilds:
|
|||
|
||||
text = f'There are {len(choices)} dependencies:'
|
||||
|
||||
code, tags = self.dialog.checklist(text, title, height, width,
|
||||
list_height, choices, dependencies)
|
||||
code, tags = self.dialogbox.checklist(text, title, height, width,
|
||||
list_height, choices, dependencies)
|
||||
|
||||
if not code:
|
||||
return dependencies
|
||||
|
|
|
@ -6,16 +6,15 @@ from slpkg.views.ascii import Ascii
|
|||
from slpkg.dependencies import Requires
|
||||
|
||||
|
||||
class Tracking:
|
||||
class Tracking(Configs):
|
||||
""" Tracking of the package dependencies. """
|
||||
|
||||
def __init__(self):
|
||||
self.configs = Configs
|
||||
super(Configs).__init__()
|
||||
self.ascii = Ascii()
|
||||
self.llc = self.ascii.lower_left_corner
|
||||
self.hl = self.ascii.horizontal_line
|
||||
self.colors = self.configs.colour
|
||||
self.color = self.colors()
|
||||
self.color = self.colour()
|
||||
self.cyan = self.color['cyan']
|
||||
self.grey = self.color['grey']
|
||||
self.yellow = self.color['yellow']
|
||||
|
|
Loading…
Reference in a new issue