From cd9b465f898ed9d89fff91e47bd84bd0df13a22a Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 9 Feb 2022 11:01:21 -0300 Subject: [PATCH] [arch.output] refactoring: String formatting method --- CHANGELOG.md | 4 ++++ bauh/gems/arch/output.py | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20867d23..418b2334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/bauh/gems/arch/output.py b/bauh/gems/arch/output.py index 7cd66a06..b0eca16d 100644 --- a/bauh/gems/arch/output.py +++ b/bauh/gems/arch/output.py @@ -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