mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-27 09:58:10 +01:00
Added progress bar
This commit is contained in:
parent
d27c353d9e
commit
9223d9af14
1 changed files with 36 additions and 3 deletions
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue