Meaningless aesthetical fix
This commit is contained in:
parent
c8b0d02e8c
commit
2de52c525b
@ -7,6 +7,33 @@ from math import floor
|
|||||||
|
|
||||||
SIZE_PREFIXES = ('', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
SIZE_PREFIXES = ('', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
|
||||||
|
|
||||||
|
class ActionItem:
|
||||||
|
def __init__(self, text, action, show_progress=True):
|
||||||
|
self.text = text
|
||||||
|
self.action = action
|
||||||
|
self.show_progress = show_progress
|
||||||
|
self.units_total = 1
|
||||||
|
self.units_done = 0
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
if self.show_progress:
|
||||||
|
with ThreadPoolExecutor() as executor:
|
||||||
|
future = executor.submit(self.action, self)
|
||||||
|
while not future.done():
|
||||||
|
time.sleep(0.2)
|
||||||
|
self.print_progress()
|
||||||
|
# Get the result of the future and let it raise exception, if there was any
|
||||||
|
data = future.result()
|
||||||
|
self.print_progress('\n')
|
||||||
|
else:
|
||||||
|
self.print_progress()
|
||||||
|
self.action()
|
||||||
|
self.units_done = 1
|
||||||
|
self.print_progress('\n')
|
||||||
|
|
||||||
|
def print_progress(self, end='\r'):
|
||||||
|
print(f'\x1b[K{self.text} ({self.units_done}/{self.units_total}) [{floor(self.units_done/self.units_total*100)} %]', end=end)
|
||||||
|
|
||||||
class ActionQueue:
|
class ActionQueue:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.queue = []
|
self.queue = []
|
||||||
@ -39,33 +66,6 @@ class ActionQueue:
|
|||||||
item.text = f'[{index}/{queue_length}] {item.text}'
|
item.text = f'[{index}/{queue_length}] {item.text}'
|
||||||
item.run()
|
item.run()
|
||||||
|
|
||||||
class ActionItem:
|
|
||||||
def __init__(self, text, action, has_progress=True):
|
|
||||||
self.text = text
|
|
||||||
self.action = action
|
|
||||||
self.has_progress = has_progress
|
|
||||||
self.units_total = 1
|
|
||||||
self.units_done = 0
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
if self.has_progress:
|
|
||||||
with ThreadPoolExecutor() as executor:
|
|
||||||
future = executor.submit(self.action, self)
|
|
||||||
while not future.done():
|
|
||||||
time.sleep(0.2)
|
|
||||||
self.print_progress()
|
|
||||||
# Get the result of the future and let it raise exception, if there was any
|
|
||||||
data = future.result()
|
|
||||||
self.print_progress('\n')
|
|
||||||
else:
|
|
||||||
self.print_progress()
|
|
||||||
self.action()
|
|
||||||
self.units_done = 1
|
|
||||||
self.print_progress('\n')
|
|
||||||
|
|
||||||
def print_progress(self, end='\r'):
|
|
||||||
print(f'\x1b[K{self.text} ({self.units_done}/{self.units_total}) [{floor(self.units_done/self.units_total*100)} %]', end=end)
|
|
||||||
|
|
||||||
def readable_size(bytes):
|
def readable_size(bytes):
|
||||||
i = 0
|
i = 0
|
||||||
while bytes > 1024:
|
while bytes > 1024:
|
||||||
|
Loading…
Reference in New Issue
Block a user