Skip to content

Commit

Permalink
version 0.1.12 - fixed space keeper runner shared status
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Berenz committed Oct 29, 2024
1 parent 83eb7d7 commit 8391dc4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
Binary file removed dist/nightskycam-0.1.7-py3-none-any.whl
Binary file not shown.
Binary file removed dist/nightskycam-0.1.7.tar.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions nightskycam/space_keeper/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from nightskyrunner.status import Level
from nightskyrunner.wait_interrupts import RunnerWaitInterruptors

from .utils import (DiskSpaceInfo, bits_to_human, convert_mb_to_bits,
from .utils import (DiskSpaceInfo, bits_to_human, bytes_to_human, convert_mb_to_bits,
disk_space_info, disk_space_info_str, files_to_delete,
folder_content, to_GB)

Expand Down Expand Up @@ -95,7 +95,7 @@ def iterate(self):
folder=f"content size: {bits_to_human(folder_size)}{files_listing}",
disk=disk_space_info_str(disk_info),
threshold=bits_to_human(convert_mb_to_bits(threshold_MB)),
free_space=to_GB(bits_to_human(disk_info["free_space"])),
free_space=to_GB(bytes_to_human(disk_info["free_space"])),
deleting=len(to_delete) > 0,
)
)
Expand Down
13 changes: 7 additions & 6 deletions nightskycam/space_keeper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import psutil

from ..utils.formating import bits_to_human
from ..utils.formating import bits_to_human, bytes_to_human

_BITS_PER_BYTE = 8

Expand Down Expand Up @@ -71,17 +71,18 @@ def disk_space_info(path: Path = _root_folder) -> DiskSpaceInfo:

disk_usage = psutil.disk_usage(str(path))
return {
"total_space": disk_usage.total * _BITS_PER_BYTE,
"free_space": disk_usage.free * _BITS_PER_BYTE,
"used_space": disk_usage.used * _BITS_PER_BYTE,
"total_space": disk_usage.total,
"free_space": disk_usage.free,
"used_space": disk_usage.used,
"percent_used": float(disk_usage.percent),
}


def disk_space_info_str(dsi: DiskSpaceInfo) -> str:
return str(
f"{bits_to_human(dsi['total_space'] * _BITS_PER_BYTE)} "
f"- free: {dsi['percent_used']}% ({bits_to_human(dsi['free_space'] * _BITS_PER_BYTE)})"
f"{bytes_to_human(dsi['total_space'])} "
f"- used: {dsi['percent_used']}% "
f"({bytes_to_human(dsi['free_space'])} free)"
)


Expand Down
25 changes: 25 additions & 0 deletions nightskycam/utils/formating.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,28 @@ def bits_to_human(bits: int) -> str:
return f"{megabytes:.2f} MB"
gigabytes = megabytes / 1024
return f"{gigabytes:.2f} GB"


def bytes_to_human(bytes_value):
# Define conversion factors
KB = 1024
MB = KB * 1024
GB = MB * 1024
TB = GB * 1024

# Determine the appropriate unit
if bytes_value >= TB:
value = bytes_value / TB
unit = "TB"
elif bytes_value >= GB:
value = bytes_value / GB
unit = "GB"
elif bytes_value >= MB:
value = bytes_value / MB
unit = "MB"
else:
value = bytes_value / KB
unit = "KB"

# Format the output
return f"{value:.2f} {unit}"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nightskycam"
version = "0.1.11"
version = "0.1.12"
description = "taking pictures at night"
authors = ["Vincent Berenz <[email protected]>"]
packages = [{ include = "nightskycam" }]
Expand Down

0 comments on commit 8391dc4

Please sign in to comment.