From 20633621a31f331b4cd363cf8d1cceea77b882b2 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 2 Apr 2024 21:53:47 +0300 Subject: [PATCH] Updated for progress bar --- ChangeLog.txt | 6 +++++- configs/slpkg.toml | 8 ++++---- pyproject.toml | 3 +-- requirements.txt | 1 - slpkg/check_updates.py | 2 +- slpkg/progress_bar.py | 39 +++++++++++++++++++-------------------- tests/test_sbo_queries.py | 4 ++-- 7 files changed, 32 insertions(+), 31 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 816a69d4..9c80acbb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,8 +1,12 @@ ## slpkg - ChangeLog -### 5.0.4 - 01/04/2024 +### 5.0.4 - 02/04/2024 - Updated: * Updated to ignore blacklist installed packages + * Updated progress bar spinners + +- Removed: + * python3-progress dependency ### 5.0.3 - 01/04/2024 - Updated: diff --git a/configs/slpkg.toml b/configs/slpkg.toml index 86deb504..359229ce 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -61,12 +61,12 @@ PARALLEL_DOWNLOADS = false PROGRESS_BAR = false # There are 5 predefined spinners for the progress bar. -# Default is pixel. [spinner/pie/moon/line/pixel] -PROGRESS_SPINNER = "pixel" +# Default is spinner. [spinner/pie/moon/line/pixel/ball/clock] +PROGRESS_SPINNER = "spinner" # Choose color for the progress bar spinner. -# Default is green. [white/green/violet/yellow/blue/cyan/grey/red] -SPINNER_COLOR = "green" +# Default is white. [white/green/violet/yellow/blue/cyan/grey/red] +SPINNER_COLOR = "white" # Choose color for the border box. # Bold colors: [bold_green/bold_cyan/bold_yellow/bold_red/bold_blue] diff --git a/pyproject.toml b/pyproject.toml index 6d4b1d0c..8d9690f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,8 +36,7 @@ classifiers = [ ] dependencies = [ - "pythondialog>=3.5.3", - "progress>=1.6", + "pythondialog>=3.5.3" ] [tool.flit_core] diff --git a/requirements.txt b/requirements.txt index 74b34cd1..6d20cf9b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ pythondialog >= 3.5.3 -progress >= 1.6 build >= 0.10.0 [socks] diff --git a/slpkg/check_updates.py b/slpkg/check_updates.py index 03495abd..e4bf9136 100644 --- a/slpkg/check_updates.py +++ b/slpkg/check_updates.py @@ -141,7 +141,7 @@ class CheckUpdates(Configs): print() def updates(self) -> dict: - message: str = 'Checking for news, please wait...' + message: str = 'Checking for news, please wait' if self.progress_bar or self.option_for_progress_bar: queue = Queue() diff --git a/slpkg/progress_bar.py b/slpkg/progress_bar.py index 678e64d1..9331bda0 100644 --- a/slpkg/progress_bar.py +++ b/slpkg/progress_bar.py @@ -2,8 +2,6 @@ # -*- coding: utf-8 -*- import time -from progress.spinner import (PixelSpinner, LineSpinner, - MoonSpinner, PieSpinner, Spinner) from slpkg.configs import Configs from slpkg.views.asciibox import AsciiBox @@ -13,40 +11,32 @@ class ProgressBar(Configs): def __init__(self): super(Configs, self).__init__() - self.spinner = PixelSpinner self.ascii = AsciiBox() self.color: str = self.endc self.spinners: dict = {} self.spinners_color: dict = {} + self.spinner: str = '' self.bar_message: str = '' def progress_bar(self, message: str, filename=None) -> None: """ Creating progress bar. """ - self.assign_spinners() - self.assign_spinner_colors() self.set_spinner() + self.assign_spinner_colors() self.set_color() self.set_the_spinner_message(filename, message) + print('\x1b[?25l', end='') # Hide cursor before starting - bar_spinner = self.spinner(f'{self.bar_message}{self.color}') - # print('\033[F', end='', flush=True) + current_state = 0 # Index of the current state try: while True: + print(f"\r{self.bar_message}{self.color}{self.spinner[current_state]}{self.endc}", end="") time.sleep(0.1) - bar_spinner.next() + current_state = (current_state + 1) % len(self.spinner) except KeyboardInterrupt: + print('\x1b[?25h', end='') raise SystemExit(1) - def assign_spinners(self) -> None: - self.spinners: dict = { - 'pixel': PixelSpinner, - 'line': LineSpinner, - 'moon': MoonSpinner, - 'pie': PieSpinner, - 'spinner': Spinner - } - def assign_spinner_colors(self) -> None: self.spinners_color: dict = { 'green': self.green, @@ -60,16 +50,25 @@ class ProgressBar(Configs): } def set_the_spinner_message(self, filename: str, message: str) -> None: - self.bar_message: str = f"{self.endc}{message} " + self.bar_message: str = f'{message}... ' if filename: self.bar_message: str = (f"{'':>2}{self.yellow}{self.ascii.bullet}{self.endc} {filename}: " f"{message}... ") def set_spinner(self) -> None: + self.spinners: dict = { + 'spinner': ('-', '\\', '|', '/'), + 'pie': ('◷', '◶', '◵', '◴'), + 'moon': ('◑', '◒', '◐', '◓'), + 'line': ('⎺', '⎻', '⎼', '⎽', '⎼', '⎻'), + 'pixel': ('⣾', '⣷', '⣯', '⣟', '⡿', '⢿', '⣻', '⣽'), + 'ball': ('_', '.', '|', 'o'), + 'clock': ('🕛', '🕑', '🕒', '🕔', '🕧', '🕗', '🕘', '🕚') + } try: - self.spinner: str = self.spinners[self.progress_spinner] + self.spinner: tuple = self.spinners[self.progress_spinner] except KeyError: - self.spinner = PixelSpinner + self.spinner: tuple = self.spinners['spinner'] def set_color(self) -> None: try: diff --git a/tests/test_sbo_queries.py b/tests/test_sbo_queries.py index 09484b26..544a45d4 100644 --- a/tests/test_sbo_queries.py +++ b/tests/test_sbo_queries.py @@ -23,11 +23,11 @@ class TestSBoQueries(unittest.TestCase): self.assertEqual([], self.data[self.name]['download64']) def test_requires(self): - self.assertEqual(['python3-build', 'SQLAlchemy', 'python3-pythondialog', 'python3-progress'], + self.assertEqual(['python3-build', 'python3-pythondialog'], self.data[self.name]['requires']) def test_version(self): - self.assertEqual('4.9.8', self.data[self.name]['version']) + self.assertEqual('5.0.4', self.data[self.name]['version']) def test_checksum_x86(self): self.assertListEqual(['9f9cf626d7246202886774c6cbc2cccf'], self.data[self.name]['md5sum'])