mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 22:54:16 +02:00
[view] improvement: displaying a '+' for positive update sizes (upgrade summary)
This commit is contained in:
@@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- General
|
- General
|
||||||
- code refactoring
|
- code refactoring
|
||||||
|
|
||||||
|
- UI
|
||||||
|
- update summary: displaying a '+' for positive sizes (previously the sign was only displayed for negative numbers) (#250)[https://github.com/vinifmor/bauh/issues/250]
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- Debian
|
- Debian
|
||||||
- info: crashing when the package size has unexpected symbols [#251](https://github.com/vinifmor/bauh/issues/251)
|
- info: crashing when the package size has unexpected symbols [#251](https://github.com/vinifmor/bauh/issues/251)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def new_select(label: str, tip: Optional[str], id_: str, opts: Iterable[Tuple[Op
|
|||||||
capitalize_label=capitalize_label)
|
capitalize_label=capitalize_label)
|
||||||
|
|
||||||
|
|
||||||
def get_human_size_str(size) -> Optional[str]:
|
def get_human_size_str(size, positive_sign: bool = False) -> Optional[str]:
|
||||||
if type(size) in (int, float, str):
|
if type(size) in (int, float, str):
|
||||||
int_size = abs(int(size))
|
int_size = abs(int(size))
|
||||||
|
|
||||||
@@ -34,4 +34,5 @@ def get_human_size_str(size) -> Optional[str]:
|
|||||||
|
|
||||||
if size_unit < 1024:
|
if size_unit < 1024:
|
||||||
size_unit = size_unit if size > 0 else size_unit * -1
|
size_unit = size_unit if size > 0 else size_unit * -1
|
||||||
return f'{int(size_unit)} {unit}' if unit == 'B' else f'{size_unit:.2f} {unit}'
|
size_str = f'{int(size_unit)} {unit}' if unit == 'B' else f'{size_unit:.2f} {unit}'
|
||||||
|
return f'+{size_str}' if positive_sign and size_unit > 0 else size_str
|
||||||
|
|||||||
@@ -238,7 +238,8 @@ class UpgradeSelected(AsyncAction):
|
|||||||
self.internet_checker = internet_checker
|
self.internet_checker = internet_checker
|
||||||
self.screen_width = screen_width
|
self.screen_width = screen_width
|
||||||
|
|
||||||
def _req_as_option(self, req: UpgradeRequirement, tooltip: bool = True, custom_tooltip: str = None, required_size: bool = True, display_sizes: bool = True) -> InputOption:
|
def _req_as_option(self, req: UpgradeRequirement, tooltip: bool = True, custom_tooltip: str = None, required_size: bool = True, display_sizes: bool = True,
|
||||||
|
positive_size_symbol: bool = False) -> InputOption:
|
||||||
if req.pkg.installed:
|
if req.pkg.installed:
|
||||||
icon_path = req.pkg.get_disk_icon_path()
|
icon_path = req.pkg.get_disk_icon_path()
|
||||||
|
|
||||||
@@ -253,7 +254,7 @@ class UpgradeSelected(AsyncAction):
|
|||||||
size_str = None
|
size_str = None
|
||||||
if display_sizes:
|
if display_sizes:
|
||||||
size_str = '{}: {}'.format(self.i18n['size'].capitalize(),
|
size_str = '{}: {}'.format(self.i18n['size'].capitalize(),
|
||||||
'?' if req.extra_size is None else get_human_size_str(req.extra_size))
|
'?' if req.extra_size is None else get_human_size_str(req.extra_size, positive_size_symbol))
|
||||||
if required_size and req.extra_size != req.required_size:
|
if required_size and req.extra_size != req.required_size:
|
||||||
size_str += ' ( {}: {} )'.format(self.i18n['action.update.pkg.required_size'].capitalize(),
|
size_str += ' ( {}: {} )'.format(self.i18n['action.update.pkg.required_size'].capitalize(),
|
||||||
'?' if req.required_size is None else get_human_size_str(req.required_size))
|
'?' if req.required_size is None else get_human_size_str(req.required_size))
|
||||||
@@ -317,7 +318,7 @@ class UpgradeSelected(AsyncAction):
|
|||||||
return FormComponent(label=lb, components=comps)
|
return FormComponent(label=lb, components=comps)
|
||||||
|
|
||||||
def _gen_to_update_form(self, reqs: List[UpgradeRequirement]) -> Tuple[FormComponent, Tuple[int, int]]:
|
def _gen_to_update_form(self, reqs: List[UpgradeRequirement]) -> Tuple[FormComponent, Tuple[int, int]]:
|
||||||
opts = [self._req_as_option(r, tooltip=False) for r in reqs]
|
opts = [self._req_as_option(r, tooltip=False, positive_size_symbol=True) for r in reqs]
|
||||||
comps = [MultipleSelectComponent(label='', options=opts, default_options=set(opts))]
|
comps = [MultipleSelectComponent(label='', options=opts, default_options=set(opts))]
|
||||||
required_size, extra_size = self._sum_pkgs_size(reqs)
|
required_size, extra_size = self._sum_pkgs_size(reqs)
|
||||||
|
|
||||||
@@ -325,7 +326,7 @@ class UpgradeSelected(AsyncAction):
|
|||||||
self.i18n['amount'].capitalize(),
|
self.i18n['amount'].capitalize(),
|
||||||
len(opts),
|
len(opts),
|
||||||
self.i18n['size'].capitalize(),
|
self.i18n['size'].capitalize(),
|
||||||
'?' if extra_size is None else get_human_size_str(extra_size),
|
'?' if extra_size is None else get_human_size_str(extra_size, True),
|
||||||
self.i18n['action.update.pkg.required_size'].capitalize(),
|
self.i18n['action.update.pkg.required_size'].capitalize(),
|
||||||
'?' if required_size is None else get_human_size_str(required_size))
|
'?' if required_size is None else get_human_size_str(required_size))
|
||||||
|
|
||||||
@@ -489,7 +490,9 @@ class UpgradeSelected(AsyncAction):
|
|||||||
extra_size += updates_size[1]
|
extra_size += updates_size[1]
|
||||||
comps.append(updates_form)
|
comps.append(updates_form)
|
||||||
|
|
||||||
extra_size_text = '{}: {}'.format(self.i18n['action.update.total_size'].capitalize(), get_human_size_str(extra_size))
|
extra_size_text = '{}: {}'.format(self.i18n['action.update.total_size'].capitalize(),
|
||||||
|
get_human_size_str(extra_size, True))
|
||||||
|
|
||||||
req_size_text = '{}: {}'.format(self.i18n['action.update.required_size'].capitalize(),
|
req_size_text = '{}: {}'.format(self.i18n['action.update.required_size'].capitalize(),
|
||||||
get_human_size_str(required_size))
|
get_human_size_str(required_size))
|
||||||
comps.insert(0, TextComponent('{} | {}'.format(extra_size_text, req_size_text), size=14))
|
comps.insert(0, TextComponent('{} | {}'.format(extra_size_text, req_size_text), size=14))
|
||||||
|
|||||||
@@ -33,3 +33,12 @@ class GetHumanSizeStrTest(TestCase):
|
|||||||
def test__must_properly_convert_to_Pb(self):
|
def test__must_properly_convert_to_Pb(self):
|
||||||
self.assertEqual('1.00 Pb', get_human_size_str(1125899906842624))
|
self.assertEqual('1.00 Pb', get_human_size_str(1125899906842624))
|
||||||
self.assertEqual('57.30 Pb', get_human_size_str(64514064662082350))
|
self.assertEqual('57.30 Pb', get_human_size_str(64514064662082350))
|
||||||
|
|
||||||
|
def test__must_concatenate_the_plus_sign_if_positive_sign_is_true_and_value_is_positive(self):
|
||||||
|
self.assertEqual('+1023 B', get_human_size_str(1023, positive_sign=True))
|
||||||
|
self.assertEqual('+1.00 Kb', get_human_size_str(1024, positive_sign=True))
|
||||||
|
|
||||||
|
def test__must_not_concatenate_the_plus_sign_if_positive_sign_is_true_and_value_is_negative(self):
|
||||||
|
self.assertEqual('-1023 B', get_human_size_str(-1023, positive_sign=True))
|
||||||
|
self.assertEqual('-1.00 Kb', get_human_size_str(-1024, positive_sign=True))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user