mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-16 07:47:35 +01:00
Fix file size for remove
This commit is contained in:
parent
ef1adac0b6
commit
69113ab12f
3 changed files with 48 additions and 13 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
- Bugfixes:
|
||||
* Double view message when update repositories
|
||||
* Package file size for remove
|
||||
|
||||
### 4.9.8 - 14/02/2024
|
||||
- Added:
|
||||
|
|
|
@ -132,19 +132,52 @@ class Utilities(Configs):
|
|||
self.errors.raise_error_message(message, output.returncode)
|
||||
raise SystemExit(output.returncode)
|
||||
|
||||
def get_file_size(self, file: Path) -> str:
|
||||
""" Get the local file size and converted to units. """
|
||||
size: int = file.stat().st_size
|
||||
return self.convert_file_sizes(size)
|
||||
# def get_file_size(self, file: Path) -> str:
|
||||
# """ Get the local file size and converted to units. """
|
||||
# size: int = file.stat().st_size
|
||||
# return self.convert_file_sizes(size)
|
||||
|
||||
def count_file_size(self, name: str) -> int:
|
||||
"""
|
||||
Read the contents files from the package file list and count
|
||||
the total installation file size in bytes.
|
||||
Args:
|
||||
name: The name of the package.
|
||||
|
||||
Returns:
|
||||
The total package installation file size.
|
||||
"""
|
||||
count_files: int = 0
|
||||
installed: Path = Path(self.log_packages, self.is_package_installed(name))
|
||||
if installed:
|
||||
file_installed: list = installed.read_text().splitlines()
|
||||
for line in file_installed:
|
||||
file: Path = Path('/', line)
|
||||
if file.is_file():
|
||||
count_files += file.stat().st_size
|
||||
return count_files
|
||||
|
||||
@staticmethod
|
||||
def convert_file_sizes(size: int) -> str:
|
||||
""" Convert file sizes. """
|
||||
units: tuple = ('KB', 'MB', 'GB')
|
||||
for unit in units:
|
||||
if size < 1000:
|
||||
return f'{size:.0f} {unit}'
|
||||
size /= 1000
|
||||
def convert_file_sizes(byte_size: int) -> str:
|
||||
"""
|
||||
Convert bytes to kb, mb and gb.
|
||||
Args:
|
||||
byte_size: The file size in bytes.
|
||||
Returns:
|
||||
The size converted.
|
||||
"""
|
||||
kb_size: float = byte_size / 1024
|
||||
mb_size: float = kb_size / 1024
|
||||
gb_size: float = mb_size / 1024
|
||||
|
||||
if gb_size >= 1:
|
||||
return f"{gb_size:.2f} GB"
|
||||
elif mb_size >= 1:
|
||||
return f"{mb_size:.2f} MB"
|
||||
elif kb_size >= 1:
|
||||
return f"{kb_size:.2f} KB"
|
||||
else:
|
||||
return f"{byte_size} bytes"
|
||||
|
||||
@staticmethod
|
||||
def apply_package_pattern(data: dict, packages: list) -> list:
|
||||
|
|
|
@ -146,10 +146,11 @@ class View(Configs):
|
|||
self.ascii.draw_package_line(package, version, size, color, self.repository)
|
||||
|
||||
def remove_package(self, package: str) -> None:
|
||||
count_size: int = self.utils.count_file_size(package)
|
||||
installed: str = self.utils.is_package_installed(package)
|
||||
version: str = self.utils.split_package(installed)['version']
|
||||
repo_tag: str = self.utils.split_package(installed)['tag']
|
||||
size: str = self.utils.get_file_size(Path(self.log_packages, installed))
|
||||
size: str = self.utils.convert_file_sizes(count_size)
|
||||
repository: str = repo_tag.lower().replace('_', '')
|
||||
|
||||
self.ascii.draw_package_line(package, version, size, self.red, repository)
|
||||
|
@ -173,7 +174,7 @@ class View(Configs):
|
|||
size_uncomp += int(self.data[pkg]['size_uncomp'])
|
||||
|
||||
if installed and option == 'remove':
|
||||
size_rmv += Path(self.log_packages, installed).stat().st_size
|
||||
size_rmv += self.utils.count_file_size(pkg)
|
||||
|
||||
upgradeable: bool = False
|
||||
if option != 'remove':
|
||||
|
|
Loading…
Reference in a new issue