mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-15 03:41:16 +01:00
Updated for process messages
This commit is contained in:
parent
5a10cf2e8f
commit
eac7fafc1a
2 changed files with 11 additions and 11 deletions
|
@ -4,10 +4,10 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
|
|
||||||
from slpkg.views.asciibox import AsciiBox
|
|
||||||
from slpkg.configs import Configs
|
from slpkg.configs import Configs
|
||||||
from slpkg.utilities import Utilities
|
from slpkg.utilities import Utilities
|
||||||
from slpkg.progress_bar import ProgressBar
|
from slpkg.progress_bar import ProgressBar
|
||||||
|
from slpkg.views.asciibox import AsciiBox
|
||||||
|
|
||||||
|
|
||||||
class MultiProcess(Configs):
|
class MultiProcess(Configs):
|
||||||
|
@ -28,15 +28,13 @@ class MultiProcess(Configs):
|
||||||
def process(self, command: str, filename: str, process_message: str, progress_message: str) -> None:
|
def process(self, command: str, filename: str, process_message: str, progress_message: str) -> None:
|
||||||
""" Starting multiprocessing install/upgrade process. """
|
""" Starting multiprocessing install/upgrade process. """
|
||||||
if self.silent_mode and not self.option_for_no_silent:
|
if self.silent_mode and not self.option_for_no_silent:
|
||||||
done: str = f"{'':>1}{self.yellow}Done{self.endc}"
|
done: str = f'{self.yellow}✔️{self.endc}'
|
||||||
self.stderr = subprocess.DEVNULL
|
self.stderr = subprocess.DEVNULL
|
||||||
self.stdout = subprocess.DEVNULL
|
self.stdout = subprocess.DEVNULL
|
||||||
|
|
||||||
# Starting multiprocessing
|
# Starting multiprocessing
|
||||||
p1 = Process(target=self.utils.process, args=(command, self.stderr, self.stdout))
|
p1 = Process(target=self.utils.process, args=(command, self.stderr, self.stdout))
|
||||||
p2 = Process(target=self.progress.progress_bar, args=(
|
p2 = Process(target=self.progress.progress_bar, args=(filename, progress_message))
|
||||||
f"{'':>2}{self.bold}{self.ascii.bullet} {progress_message}:", filename)
|
|
||||||
)
|
|
||||||
|
|
||||||
p1.start()
|
p1.start()
|
||||||
p2.start()
|
p2.start()
|
||||||
|
@ -47,10 +45,9 @@ class MultiProcess(Configs):
|
||||||
# Terminate process 2 if process 1 finished
|
# Terminate process 2 if process 1 finished
|
||||||
if not p1.is_alive():
|
if not p1.is_alive():
|
||||||
if p1.exitcode != 0:
|
if p1.exitcode != 0:
|
||||||
done: str = f'{self.bred}Failed: {self.endc}{process_message}.'
|
print(f'{self.bred}Failed: {self.endc}{process_message}.')
|
||||||
|
|
||||||
print(f'{self.endc}{done}', end='')
|
|
||||||
p2.terminate()
|
p2.terminate()
|
||||||
|
print(f"\r{'':>2}{self.bgreen}{self.ascii.bullet}{self.endc} {filename} {done}{' ' * 17}", end='\r')
|
||||||
|
|
||||||
# Restore the terminal cursor
|
# Restore the terminal cursor
|
||||||
print('\x1b[?25h', self.endc)
|
print('\x1b[?25h', self.endc)
|
||||||
|
|
|
@ -6,6 +6,7 @@ from progress.spinner import (PixelSpinner, LineSpinner,
|
||||||
MoonSpinner, PieSpinner, Spinner)
|
MoonSpinner, PieSpinner, Spinner)
|
||||||
|
|
||||||
from slpkg.configs import Configs
|
from slpkg.configs import Configs
|
||||||
|
from slpkg.views.asciibox import AsciiBox
|
||||||
|
|
||||||
|
|
||||||
class ProgressBar(Configs):
|
class ProgressBar(Configs):
|
||||||
|
@ -13,11 +14,13 @@ class ProgressBar(Configs):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Configs, self).__init__()
|
super(Configs, self).__init__()
|
||||||
self.spinner = PixelSpinner
|
self.spinner = PixelSpinner
|
||||||
|
self.ascii = AsciiBox()
|
||||||
|
|
||||||
self.color: str = self.endc
|
self.color: str = self.endc
|
||||||
self.spinners: dict = {}
|
self.spinners: dict = {}
|
||||||
self.spinners_color: dict = {}
|
self.spinners_color: dict = {}
|
||||||
|
|
||||||
def progress_bar(self, message: str, filename: str) -> None:
|
def progress_bar(self, filename: str, message: str) -> None:
|
||||||
""" Creating progress bar. """
|
""" Creating progress bar. """
|
||||||
self.assign_spinners()
|
self.assign_spinners()
|
||||||
self.assign_spinner_colors()
|
self.assign_spinner_colors()
|
||||||
|
@ -25,7 +28,7 @@ class ProgressBar(Configs):
|
||||||
self.set_color()
|
self.set_color()
|
||||||
|
|
||||||
if self.spinning_bar:
|
if self.spinning_bar:
|
||||||
bar_spinner = self.spinner(f'{self.endc}{message} {filename} {self.color}')
|
bar_spinner = self.spinner(f"{'':>2}{self.red}{self.ascii.bullet}{self.endc} {filename}: {message}... {self.color}")
|
||||||
# print('\033[F', end='', flush=True)
|
# print('\033[F', end='', flush=True)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
@ -34,7 +37,7 @@ class ProgressBar(Configs):
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
else:
|
else:
|
||||||
print(f'{message} ', end='', flush=True)
|
print(f"{'':>2}{self.red}{self.ascii.bullet}{self.endc} {filename}: {message}... {self.color}", end='')
|
||||||
|
|
||||||
def assign_spinners(self) -> None:
|
def assign_spinners(self) -> None:
|
||||||
self.spinners: dict[str] = {
|
self.spinners: dict[str] = {
|
||||||
|
|
Loading…
Reference in a new issue