Added progress bar

This commit is contained in:
Dimitris Zlatanidis 2023-01-03 22:56:22 +02:00
parent d27c353d9e
commit 9223d9af14

View file

@ -4,8 +4,10 @@
import os
import urllib3
from pathlib import Path
from multiprocessing import Process
from slpkg.configs import Configs
from slpkg.progress_bar import ProgressBar
class CheckUpdates:
@ -13,6 +15,12 @@ class CheckUpdates:
def __init__(self):
self.configs = Configs
self.colors = self.configs.colour
self.color = self.colors()
self.green = self.color['green']
self.yellow = self.color['yellow']
self.endc = self.color['endc']
self.progress = ProgressBar()
def check(self) -> bool:
""" Checks the ChangeLogs and returns True or False. """
@ -33,8 +41,33 @@ class CheckUpdates:
return repo_date != local_date
def updates(self):
def view_message(self):
if self.check():
print('\n\nThere are new updates available!\n')
print(f'\n\n{self.endc}There are new updates available!')
else:
print('\n\nNo updated packages since the last check.\n')
print(f'\n\n{self.endc}No updated packages since the last check.')
def updates(self):
""" Starting multiprocessing download process. """
message = f'Checking for news in the Changelog.txt file...'
# Starting multiprocessing
p1 = Process(target=self.view_message)
p2 = Process(target=self.progress.bar, args=(message, ''))
p1.start()
p2.start()
# Wait until process 1 finish
p1.join()
# Terminate process 2 if process 1 finished
if not p1.is_alive():
# print(f'{self.endc}{self.yellow} Done{self.endc}', end='')
p2.terminate()
# Wait until process 2 finish
p2.join()
# Restore the terminal cursor
print('\x1b[?25h')