[arch.output] refactoring: String formatting method

This commit is contained in:
Vinicius Moreira
2022-02-09 11:01:21 -03:00
parent 66ae8eb152
commit cd9b465f89
2 changed files with 17 additions and 12 deletions

View File

@@ -37,7 +37,7 @@ class TransactionStatusHandler(Thread):
def gen_percentage(self) -> str:
if self.percentage:
performed = self.downloading + self.upgrading + self.installing
return '({0:.2f}%) '.format((performed / (2 * self.pkgs_to_sync)) * 100)
return f'({(performed / (2 * self.pkgs_to_sync)) * 100:.2f}%) '
else:
return ''
@@ -52,18 +52,19 @@ class TransactionStatusHandler(Thread):
if self.pkgs_to_remove > 0:
self.removing += 1
self.watcher.change_substatus('[{}/{}] {} {}'.format(self.removing, self.pkgs_to_remove,
self.i18n['uninstalling'].capitalize(), output.split(' ')[1].strip()))
self.watcher.change_substatus(f"[{self.removing}/{self.pkgs_to_remove}] "
f"{self.i18n['uninstalling'].capitalize()} {output.split(' ')[1].strip()}")
else:
self.watcher.change_substatus('{} {}'.format(self.i18n['uninstalling'].capitalize(), output_split[1].strip()))
self.watcher.change_substatus(f"{self.i18n['uninstalling'].capitalize()} {output_split[1].strip()}")
elif len(output_split) >= 2 and output_split[1].lower().startswith('downloading') and (not self.names or (n for n in self.names if output_split[0].startswith(n))):
if self.downloading < self.pkgs_to_sync:
perc = self.gen_percentage()
self.downloading += 1
self.watcher.change_substatus('{}[{}/{}] {} {} {}'.format(perc, self.downloading, self.pkgs_to_sync, bold('[pacman]'),
self.i18n['downloading'].capitalize(), output_split[0].strip()))
self.watcher.change_substatus(f"{perc}[{self.downloading}/{self.pkgs_to_sync}] {bold('[pacman]')} "
f"{self.i18n['downloading'].capitalize()} {output_split[0].strip()}")
elif output_split[0].lower() == 'upgrading' and (not self.names or output_split[1].split('.')[0] in self.names):
if self.get_performed() < self.pkgs_to_sync:
perc = self.gen_percentage()
@@ -72,8 +73,9 @@ class TransactionStatusHandler(Thread):
performed = self.upgrading + self.installing
if performed <= self.pkgs_to_sync:
self.watcher.change_substatus('{}[{}/{}] {} {}'.format(perc, performed, self.pkgs_to_sync,
self.i18n['manage_window.status.upgrading'].capitalize(), output_split[1].strip()))
self.watcher.change_substatus(f"{perc}[{performed}/{self.pkgs_to_sync}] "
f"{self.i18n['manage_window.status.upgrading'].capitalize()} {output_split[1].strip()}")
elif output_split[0].lower() == 'installing' and (not self.names or output_split[1].split('.')[0] in self.names):
if self.get_performed() < self.pkgs_to_sync:
perc = self.gen_percentage()
@@ -82,15 +84,14 @@ class TransactionStatusHandler(Thread):
performed = self.upgrading + self.installing
if performed <= self.pkgs_to_sync:
self.watcher.change_substatus('{}[{}/{}] {} {}'.format(perc, performed, self.pkgs_to_sync,
self.i18n['manage_window.status.installing'].capitalize(),
output_split[1].strip()))
self.watcher.change_substatus(f"{perc}[{performed}/{self.pkgs_to_sync}] "
f"{self.i18n['manage_window.status.installing'].capitalize()} {output_split[1].strip()}")
else:
substatus_found = False
lower_output = output.lower().strip()
for msg, key in self.accepted.items():
if lower_output.startswith(msg):
self.watcher.change_substatus(self.i18n['arch.substatus.{}'.format(key)].capitalize())
self.watcher.change_substatus(self.i18n[f'arch.substatus.{key}'].capitalize())
substatus_found = True
break