mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-27 09:58:10 +01:00
Added for view process messages
Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
parent
c945a624c8
commit
6e9607c4cc
2 changed files with 57 additions and 35 deletions
|
@ -3,16 +3,14 @@
|
|||
|
||||
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
from multiprocessing import Process
|
||||
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.utilities import Utilities
|
||||
from slpkg.blacklist import Blacklist
|
||||
from slpkg.views.asciibox import AsciiBox
|
||||
from slpkg.progress_bar import ProgressBar
|
||||
from slpkg.repositories import Repositories
|
||||
from slpkg.views.view_process import ViewProcess
|
||||
|
||||
|
||||
class LoadData(Configs):
|
||||
|
@ -23,19 +21,14 @@ class LoadData(Configs):
|
|||
def __init__(self, flags: list = None):
|
||||
super(Configs, self).__init__()
|
||||
|
||||
if flags is None:
|
||||
flags = []
|
||||
|
||||
self.repos = Repositories()
|
||||
self.utils = Utilities()
|
||||
self.black = Blacklist()
|
||||
self.ascii = AsciiBox()
|
||||
self.progress = ProgressBar()
|
||||
|
||||
if flags is None:
|
||||
flags = []
|
||||
|
||||
self.bar_process = None
|
||||
|
||||
self.option_for_progress_bar: bool = self.utils.is_option(
|
||||
('-B', '--progress-bar'), flags)
|
||||
self.view_process = ViewProcess(flags)
|
||||
|
||||
def load(self, repository: str, message: bool = True) -> dict:
|
||||
""" Load data to the dictionary.
|
||||
|
@ -48,7 +41,7 @@ class LoadData(Configs):
|
|||
dict: Dictionary data.
|
||||
"""
|
||||
if message:
|
||||
self.progress_bar_message()
|
||||
self.view_process.message('Database loading')
|
||||
|
||||
data: dict = {}
|
||||
if repository == '*':
|
||||
|
@ -69,7 +62,7 @@ class LoadData(Configs):
|
|||
self._remove_blacklist_from_a_repo(data)
|
||||
|
||||
if message:
|
||||
self.done_process()
|
||||
self.view_process.done()
|
||||
|
||||
return data
|
||||
|
||||
|
@ -128,24 +121,3 @@ class LoadData(Configs):
|
|||
deps.remove(blk)
|
||||
data[pkg]['requires'] = deps
|
||||
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}')
|
||||
|
|
50
slpkg/views/view_process.py
Normal file
50
slpkg/views/view_process.py
Normal 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}')
|
Loading…
Reference in a new issue