[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

@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [0.9.27] ## [0.9.27]
### Improvements
- code refactoring (String formatting method)
### Fixes ### Fixes
- Arch - Arch
- silent crash when handling and displaying transaction sub-status - silent crash when handling and displaying transaction sub-status
@@ -13,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- AppImage - AppImage
- search: displaying duplicate installed apps for some cases - search: displaying duplicate installed apps for some cases
## [0.9.26] 2022-01-31 ## [0.9.26] 2022-01-31
### Improvements ### Improvements

View File

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