Added for view process messages

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2024-05-03 00:00:04 +03:00
parent c945a624c8
commit 6e9607c4cc
2 changed files with 57 additions and 35 deletions

View file

@ -3,16 +3,14 @@
import json import json
import time
from pathlib import Path from pathlib import Path
from multiprocessing import Process
from slpkg.configs import Configs from slpkg.configs import Configs
from slpkg.utilities import Utilities from slpkg.utilities import Utilities
from slpkg.blacklist import Blacklist from slpkg.blacklist import Blacklist
from slpkg.views.asciibox import AsciiBox from slpkg.views.asciibox import AsciiBox
from slpkg.progress_bar import ProgressBar
from slpkg.repositories import Repositories from slpkg.repositories import Repositories
from slpkg.views.view_process import ViewProcess
class LoadData(Configs): class LoadData(Configs):
@ -23,19 +21,14 @@ class LoadData(Configs):
def __init__(self, flags: list = None): def __init__(self, flags: list = None):
super(Configs, self).__init__() super(Configs, self).__init__()
if flags is None:
flags = []
self.repos = Repositories() self.repos = Repositories()
self.utils = Utilities() self.utils = Utilities()
self.black = Blacklist() self.black = Blacklist()
self.ascii = AsciiBox() self.ascii = AsciiBox()
self.progress = ProgressBar() self.view_process = ViewProcess(flags)
if flags is None:
flags = []
self.bar_process = None
self.option_for_progress_bar: bool = self.utils.is_option(
('-B', '--progress-bar'), flags)
def load(self, repository: str, message: bool = True) -> dict: def load(self, repository: str, message: bool = True) -> dict:
""" Load data to the dictionary. """ Load data to the dictionary.
@ -48,7 +41,7 @@ class LoadData(Configs):
dict: Dictionary data. dict: Dictionary data.
""" """
if message: if message:
self.progress_bar_message() self.view_process.message('Database loading')
data: dict = {} data: dict = {}
if repository == '*': if repository == '*':
@ -69,7 +62,7 @@ class LoadData(Configs):
self._remove_blacklist_from_a_repo(data) self._remove_blacklist_from_a_repo(data)
if message: if message:
self.done_process() self.view_process.done()
return data return data
@ -128,24 +121,3 @@ class LoadData(Configs):
deps.remove(blk) deps.remove(blk)
data[pkg]['requires'] = deps data[pkg]['requires'] = deps
return data return data
def progress_bar_message(self) -> None:
""" Show spinner with message.
"""
if self.progress_bar_conf or self.option_for_progress_bar:
message: str = 'Database loading'
self.bar_process = Process(target=self.progress.progress_bar, args=(message,))
self.bar_process.start()
else:
print('\rDatabase loading... ', end='')
def done_process(self) -> None:
""" Show done message.
"""
if self.progress_bar_conf or self.option_for_progress_bar:
time.sleep(0.1)
self.bar_process.terminate()
self.bar_process.join()
print('\x1b[?25h')
else:
print(f'{self.bgreen}{self.ascii.done}{self.endc}')

View file

@ -0,0 +1,50 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import time
from multiprocessing import Process
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.progress_bar import ProgressBar
from slpkg.views.asciibox import AsciiBox
class ViewProcess(Configs):
"""
View the process messages.
"""
def __init__(self, flags: list):
super(Configs, self).__init__()
self.progress = ProgressBar()
self.utils = Utilities()
self.ascii = AsciiBox()
self.bar_process = None
self.option_for_progress_bar: bool = self.utils.is_option(
('-B', '--progress-bar'), flags)
def message(self, message: str) -> None:
""" Show spinner with message.
"""
if self.progress_bar_conf or self.option_for_progress_bar:
self.bar_process = Process(target=self.progress.progress_bar, args=(message,))
self.bar_process.start()
else:
print(f'\r{message}... ', end='')
def done(self) -> None:
""" Show done message.
"""
if self.progress_bar_conf or self.option_for_progress_bar:
time.sleep(0.1)
self.bar_process.terminate()
self.bar_process.join()
print('\x1b[?25h')
else:
print(f'{self.bgreen}{self.ascii.done}{self.endc}')