mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 14:24:15 +02:00
[commons.util] improvement: returning a float for 'size_to_byte' parsing
This commit is contained in:
@@ -58,7 +58,7 @@ class SearchResult:
|
||||
|
||||
class UpgradeRequirement:
|
||||
|
||||
def __init__(self, pkg: SoftwarePackage, reason: str = None, required_size: int = None, extra_size: int = None, sorting_priority: int = 0):
|
||||
def __init__(self, pkg: SoftwarePackage, reason: str = None, required_size: float = None, extra_size: float = None, sorting_priority: int = 0):
|
||||
"""
|
||||
|
||||
:param pkg:
|
||||
|
||||
@@ -28,7 +28,7 @@ def deep_update(source: dict, overrides: dict):
|
||||
return source
|
||||
|
||||
|
||||
def size_to_byte(size: float, unit: str) -> int:
|
||||
def size_to_byte(size: float, unit: str) -> float:
|
||||
lower_unit = unit.lower()
|
||||
final_size = size
|
||||
|
||||
@@ -36,19 +36,17 @@ def size_to_byte(size: float, unit: str) -> int:
|
||||
final_size /= 8
|
||||
|
||||
if lower_unit[0] == 'b':
|
||||
pass
|
||||
return final_size
|
||||
elif lower_unit[0] == 'k':
|
||||
final_size = final_size * 1024
|
||||
return final_size * 1024
|
||||
elif lower_unit[0] == 'm':
|
||||
final_size = final_size * (1024 ** 2)
|
||||
return final_size * (1024 ** 2)
|
||||
elif lower_unit[0] == 'g':
|
||||
final_size = final_size * (1024 ** 3)
|
||||
return final_size * (1024 ** 3)
|
||||
elif lower_unit[0] == 't':
|
||||
final_size = final_size * (1024 ** 4)
|
||||
return final_size * (1024 ** 4)
|
||||
else:
|
||||
final_size = final_size * (1024 ** 5)
|
||||
|
||||
return round(final_size)
|
||||
return final_size * (1024 ** 5)
|
||||
|
||||
|
||||
def datetime_as_milis(date: datetime = datetime.utcnow()) -> int:
|
||||
|
||||
@@ -474,7 +474,7 @@ def is_mirrors_available() -> bool:
|
||||
return bool(shutil.which('pacman-mirrors'))
|
||||
|
||||
|
||||
def map_update_sizes(pkgs: List[str]) -> Dict[str, int]: # bytes:
|
||||
def map_update_sizes(pkgs: List[str]) -> Dict[str, float]: # bytes:
|
||||
output = run_cmd('pacman -Si {}'.format(' '.join(pkgs)))
|
||||
|
||||
if output:
|
||||
@@ -483,7 +483,7 @@ def map_update_sizes(pkgs: List[str]) -> Dict[str, int]: # bytes:
|
||||
return {}
|
||||
|
||||
|
||||
def map_download_sizes(pkgs: List[str]) -> Dict[str, int]: # bytes:
|
||||
def map_download_sizes(pkgs: List[str]) -> Dict[str, float]: # bytes:
|
||||
output = run_cmd('pacman -Si {}'.format(' '.join(pkgs)))
|
||||
|
||||
if output:
|
||||
@@ -492,7 +492,7 @@ def map_download_sizes(pkgs: List[str]) -> Dict[str, int]: # bytes:
|
||||
return {}
|
||||
|
||||
|
||||
def get_installed_size(pkgs: List[str]) -> Dict[str, int]: # bytes
|
||||
def get_installed_size(pkgs: List[str]) -> Dict[str, float]: # bytes
|
||||
output = run_cmd('pacman -Qi {}'.format(' '.join(pkgs)))
|
||||
|
||||
if output:
|
||||
|
||||
@@ -58,7 +58,7 @@ class DebianPackage(SoftwarePackage):
|
||||
description: Optional[str] = None, maintainer: Optional[str] = None, installed: bool = False,
|
||||
update: bool = False, app: Optional[DebianApplication] = None, compressed_size: Optional[int] = None,
|
||||
uncompressed_size: Optional[int] = None, categories: Tuple[str] = None,
|
||||
updates_ignored: Optional[bool] = None, transaction_size: Optional[int] = None):
|
||||
updates_ignored: Optional[bool] = None, transaction_size: Optional[float] = None):
|
||||
super(DebianPackage, self).__init__(id=name, name=name, version=version, installed=installed,
|
||||
description=description, update=update,
|
||||
latest_version=latest_version if latest_version is not None else version)
|
||||
|
||||
@@ -410,7 +410,7 @@ def run(app_id: str):
|
||||
subprocess.Popen((f'flatpak run {app_id}',), shell=True, env={**os.environ})
|
||||
|
||||
|
||||
def map_update_download_size(app_ids: Iterable[str], installation: str, version: Version) -> Dict[str, int]:
|
||||
def map_update_download_size(app_ids: Iterable[str], installation: str, version: Version) -> Dict[str, float]:
|
||||
success, output = ProcessHandler().handle_simple(SimpleProcess(('flatpak', 'update', f'--{installation}')))
|
||||
if version >= VERSION_1_2:
|
||||
res = {}
|
||||
|
||||
@@ -270,7 +270,7 @@ class UpgradeSelected(AsyncAction):
|
||||
read_only=True,
|
||||
icon_path=icon_path)
|
||||
|
||||
def _sum_pkgs_size(self, reqs: List[UpgradeRequirement]) -> Tuple[int, int]:
|
||||
def _sum_pkgs_size(self, reqs: List[UpgradeRequirement]) -> Tuple[float, float]:
|
||||
required, extra = 0, 0
|
||||
for r in reqs:
|
||||
if r.required_size is not None:
|
||||
|
||||
Reference in New Issue
Block a user