Updated for progress bar option

This commit is contained in:
Dimitris Zlatanidis 2024-03-23 18:56:21 +02:00
parent 370f9bcfb7
commit 42aa69ab56
10 changed files with 81 additions and 76 deletions

View file

@ -4,23 +4,25 @@
- Updated:
* Blacklist using regex pattern
* Move command check-updates to option --check
* Rename option --no-silent to --silent
* Rename option --no-silent to --progress-bar
* Config default silent mode to false
- Removed:
* Remove SQLAlchemy dependency
* Remove help command, instead use manpage
* Remove clean-logs and clean-data commands
* Remove rules.toml config file
* Remove --install-data option
* Remove FILE_PATTERN from configs
* Remove --jobs option
* Removed SQLAlchemy dependency
* Removed help command, instead use manpage
* Removed clean-logs and clean-data commands
* Removed rules.toml config file
* Removed --install-data option
* Removed FILE_PATTERN from configs
* Removed --jobs option
* Removed spinni_bar config
- Added:
* Check for upgrade packages using the option --check
* MAKEFLAGS config to specify the number of jobs
* Support GPG verification
- Bugfixes:
* Double view message when update repositories
* Package file size for remove

View file

@ -33,10 +33,6 @@ CHECKSUM_MD5 = true
# Default is true. [true/false]
DIALOG = true
# If silent mode is true, it does not print the commands as they are executed.
# Default is false. [true/false]
SILENT_MODE = false
# Choose ascii printable characters.
# If true, it uses the extended characters, otherwise the basic ones.
# Default is true. [true/false].
@ -50,8 +46,9 @@ ASK_QUESTION = true
# Alternatively, you can use the option '--parallel'.
PARALLEL_DOWNLOADS = false
# Enable or disable the spinning bar. Default is true. [true/false]
SPINNING_BAR = true
# If progress bar is true, it does not print the commands as they are executed.
# Default is false. [true/false]
PROGRESS_BAR = false
# There are 5 predefined spinners for the progress bar.
# Default is pixel. [spinner/pie/moon/line/pixel]

View file

@ -137,10 +137,10 @@ Example try: '\fIslpkg install python3 --search\fR' or '\fIslpkg download python
-s, search, -e, dependees, -t, tracking)
.RE
.P
.B -n, --silent
.B -B, --progress-bar
.RS
Enable silent mode, if it is false in the configuration file. (to be used with: -U, upgrade, -b, build,
-i, install, -R, remove)
Apply it to see a static progress bar instead of process execute like building, installing or removing.
(to be used with: -u, update, -U, upgrade, -b, build, -i, install, -R, remove)
.RE
.P
.B -p, --pkg-version

View file

@ -39,13 +39,17 @@ class CheckUpdates(Configs):
self.option_for_check: bool = self.utils.is_option(
('-c', '--check'), flags)
def check_the_repositories(self, queue) -> None:
self.option_for_progress_bar: bool = self.utils.is_option(
('-B', '--progress-bar'), flags)
def check_the_repositories(self, queue=None) -> None:
if self.option_for_repository:
self.repositories(self.repository)
else:
self.check_updates_for_repositories()
queue.put(self.compare)
if queue is not None:
queue.put(self.compare)
self.view_messages(self.compare)
def check_updates_for_repositories(self) -> None:
@ -129,29 +133,34 @@ class CheckUpdates(Configs):
print(f'\n\n{self.endc}{self.yellow}No updated packages since the last check.{self.endc}')
def updates(self) -> dict:
queue = Queue()
message: str = 'Checking for news, please wait...'
if self.progress_bar or self.option_for_progress_bar:
queue = Queue()
# Starting multiprocessing
process_1 = Process(target=self.check_the_repositories, args=(queue,))
process_2 = Process(target=self.progress.progress_bar, args=(message,))
# Starting multiprocessing
process_1 = Process(target=self.check_the_repositories, args=(queue,))
process_2 = Process(target=self.progress.progress_bar, args=(message,))
process_1.start()
process_2.start()
process_1.start()
process_2.start()
# Wait until process 1 finish
process_1.join()
# Wait until process 1 finish
process_1.join()
# Terminate process 2 if process 1 finished
if not process_1.is_alive():
process_2.terminate()
# Terminate process 2 if process 1 finished
if not process_1.is_alive():
process_2.terminate()
compare: dict = queue.get()
compare: dict = queue.get()
# Restore the terminal cursor
if not self.option_for_check and not any(list(compare.values())):
print('\x1b[?25h', end='')
# Restore the terminal cursor
if not self.option_for_check and not any(list(compare.values())):
print('\x1b[?25h', end='')
else:
print('\x1b[?25h')
return compare
else:
print('\x1b[?25h')
return compare
print(f'\r{message} ', end='')
self.check_the_repositories()
return self.compare

View file

@ -43,11 +43,10 @@ class Configs:
curl_options: str = ''
lftp_get_options: str = '-c get -e'
lftp_mirror_options: str = '-c mirror --parallel=100 --only-newer --delete'
silent_mode: bool = False
ascii_characters: bool = True
ask_question: bool = True
parallel_downloads: bool = False
spinning_bar: str = True
progress_bar: bool = False
progress_spinner: str = 'pixel'
spinner_color: str = 'green'
border_color: str = 'bold_green'
@ -88,11 +87,10 @@ class Configs:
curl_options: str = config['CURL_OPTIONS']
lftp_get_options: str = config['LFTP_GET_OPTIONS']
lftp_mirror_options: str = config['LFTP_MIRROR_OPTIONS']
silent_mode: bool = config['SILENT_MODE']
ascii_characters: bool = config['ASCII_CHARACTERS']
file_list_suffix: str = config['FILE_LIST_SUFFIX']
parallel_downloads: bool = config['PARALLEL_DOWNLOADS']
spinning_bar: str = config['SPINNING_BAR']
progress_bar: str = config['PROGRESS_BAR']
progress_spinner: str = config['PROGRESS_SPINNER']
spinner_color: str = config['SPINNER_COLOR']
border_color: str = config['BORDER_COLOR']

View file

@ -59,8 +59,8 @@ class Menu(Configs):
self.flag_short_full_reverse: str = '-E'
self.flag_search: str = '--search'
self.flag_short_search: str = '-S'
self.flag_for_silent: str = '--silent'
self.flag_short_for_silent: str = '-n'
self.flag_for_progress_bar: str = '--progress-bar'
self.flag_short_for_progress_bar: str = '-B'
self.flag_pkg_version: str = '--pkg-version'
self.flag_short_pkg_version: str = '-p'
self.flag_parallel: str = '--parallel'
@ -97,8 +97,8 @@ class Menu(Configs):
self.flag_short_full_reverse,
self.flag_search,
self.flag_short_search,
self.flag_for_silent,
self.flag_short_for_silent,
self.flag_for_progress_bar,
self.flag_short_for_progress_bar,
self.flag_pkg_version,
self.flag_short_pkg_version,
self.flag_parallel,
@ -123,7 +123,9 @@ class Menu(Configs):
self.flag_repository,
self.flag_short_repository,
self.flag_parallel,
self.flag_short_parallel
self.flag_short_parallel,
self.flag_for_progress_bar,
self.flag_short_for_progress_bar,
],
'upgrade': [
self.flag_yes,
@ -134,8 +136,8 @@ class Menu(Configs):
self.flag_short_resolve_off,
self.flag_reinstall,
self.flag_short_reinstall,
self.flag_for_silent,
self.flag_short_for_silent,
self.flag_for_progress_bar,
self.flag_short_for_progress_bar,
self.flag_repository,
self.flag_short_repository,
self.flag_parallel,
@ -154,8 +156,8 @@ class Menu(Configs):
self.flag_short_resolve_off,
self.flag_search,
self.flag_short_search,
self.flag_for_silent,
self.flag_short_for_silent,
self.flag_for_progress_bar,
self.flag_short_for_progress_bar,
self.flag_repository,
self.flag_short_repository,
self.flag_parallel,
@ -174,8 +176,8 @@ class Menu(Configs):
self.flag_short_skip_installed,
self.flag_search,
self.flag_short_search,
self.flag_for_silent,
self.flag_short_for_silent,
self.flag_for_progress_bar,
self.flag_short_for_progress_bar,
self.flag_repository,
self.flag_short_repository,
self.flag_parallel,
@ -204,8 +206,8 @@ class Menu(Configs):
self.flag_short_resolve_off,
self.flag_search,
self.flag_short_search,
self.flag_for_silent,
self.flag_short_for_silent,
self.flag_for_progress_bar,
self.flag_short_for_progress_bar,
],
'find': [
self.flag_search,

View file

@ -27,8 +27,8 @@ class MultiProcess(Configs):
self.bottom_message: str = 'EOF - End of log file'
if flags is not None:
self.option_for_silent: bool = self.utils.is_option(
('-n', '--silent'), flags)
self.option_for_progress_bar: bool = self.utils.is_option(
('-B', '--progress-bar'), flags)
def run(self, command: str, filename: str, progress_message: str) -> None:
""" Starting a multiprocessing process.
@ -39,7 +39,7 @@ class MultiProcess(Configs):
Returns:
None.
"""
if self.silent_mode or self.option_for_silent:
if self.progress_bar or self.option_for_progress_bar:
done: str = f'{self.bgreen}{self.ascii.done}{self.endc}'
failed: str = f'{self.bred}{self.ascii.failed}{self.endc}'
@ -83,7 +83,7 @@ class MultiProcess(Configs):
# Write the process to the log file and to the terminal.
with process.stdout as output:
for i, line in enumerate(output):
if not self.silent_mode and not self.option_for_silent:
if not self.progress_bar and not self.option_for_progress_bar:
print(line.strip()) # Print to console
if self.process_log:
with open(self.slpkg_log_file, 'a') as log:
@ -100,7 +100,7 @@ class MultiProcess(Configs):
def _error_process(self):
""" Prints error message for a process. """
if not self.silent_mode and not self.option_for_silent:
if not self.progress_bar and not self.option_for_progress_bar:
message: str = f'Error occurred with process. Please check the log file.'
print()
print(len(message) * '=')

View file

@ -29,18 +29,14 @@ class ProgressBar(Configs):
self.set_color()
self.set_the_spinner_message(filename, message)
if self.spinning_bar:
bar_spinner = self.spinner(f'{self.bar_message}{self.color}')
# print('\033[F', end='', flush=True)
try:
while True:
time.sleep(0.1)
bar_spinner.next()
except KeyboardInterrupt:
raise SystemExit(1)
else:
print(f"{'':>2}{self.yellow}{self.ascii.bullet}{self.endc} {filename}: "
f"{message}... {self.color}", end='')
bar_spinner = self.spinner(f'{self.bar_message}{self.color}')
# print('\033[F', end='', flush=True)
try:
while True:
time.sleep(0.1)
bar_spinner.next()
except KeyboardInterrupt:
raise SystemExit(1)
def assign_spinners(self) -> None:
self.spinners: dict = {

View file

@ -75,12 +75,14 @@ class Usage(Configs):
f' {self.yellow}-c, --check{self.endc} Check a procedure before you run it.\n'
f' {self.yellow}-O, --resolve-off{self.endc} Turns off dependency resolving.\n'
f' {self.yellow}-r, --reinstall{self.endc} Upgrade packages of the same version.\n'
f' {self.yellow}-k, --skip-installed{self.endc} Skip installed packages.\n'
f' {self.yellow}-k, --skip-installed{self.endc} Skip installed packages during the building\n'
f'{"":>28}or installation progress.\n'
f' {self.yellow}-E, --full-reverse{self.endc} Display the full reverse dependency.\n'
f' {self.yellow}-S, --search{self.endc} Search and load packages using the dialog.\n'
f' {self.yellow}-n, --silent{self.endc} Enable silent mode.\n'
f' {self.yellow}-B, --progress-bar{self.endc} Display static progress bar instead of\n'
f'{"":>28}process execute.\n'
f' {self.yellow}-p, --pkg-version{self.endc} Print the repository package version.\n'
f' {self.yellow}-P, --parallel{self.endc} Download files in parallel.\n'
f' {self.yellow}-P, --parallel{self.endc} Enable download files in parallel.\n'
f' {self.yellow}-m, --no-case{self.endc} Case-insensitive pattern matching.\n'
f' {self.yellow}-o, --repository={self.endc}NAME Change repository you want to work.\n'
f' {self.yellow}-z, --directory={self.endc}PATH Download files to a specific path.\n'

View file

@ -37,11 +37,10 @@ class TestConfigs(unittest.TestCase):
self.assertEqual('', self.configs.curl_options)
self.assertEqual('-c get -e', self.configs.lftp_get_options)
self.assertEqual('-c mirror --parallel=100 --only-newer --delete', self.configs.lftp_mirror_options)
self.assertEqual(False, self.configs.silent_mode)
self.assertEqual(True, self.configs.ascii_characters)
self.assertEqual(True, self.configs.ask_question)
self.assertEqual(False, self.configs.parallel_downloads)
self.assertEqual(True, self.configs.spinning_bar)
self.assertEqual(True, self.configs.progress_bar)
self.assertEqual('pixel', self.configs.progress_spinner)
self.assertEqual('green', self.configs.spinner_color)
self.assertEqual('bold_green', self.configs.border_color)