mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[arch.output] refactoring: String formatting method
This commit is contained in:
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [0.9.27]
|
||||
|
||||
### Improvements
|
||||
- code refactoring (String formatting method)
|
||||
|
||||
### Fixes
|
||||
- Arch
|
||||
- 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
|
||||
- search: displaying duplicate installed apps for some cases
|
||||
|
||||
|
||||
## [0.9.26] 2022-01-31
|
||||
|
||||
### Improvements
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user