From 8daa6330396b7adbf408755882283f1520b48944 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 16 Jul 2020 19:08:37 +0100 Subject: status: Use integer division where appropriate In Python 2, the / operator between two integer-typed values produces another integer. In Python 3, it produces a float. We need to use the // operator to get the old behaviour. The change to floats in get_free_disk_space resulted in unnecessarily precise values for free disk space. The change in formats_secs_nicely doesn't seem to make a difference since we format the quotients with '%d', but I'm making it use // so it's clearer what we want. Closes #14. --- lorrycontroller/status.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lorrycontroller/status.py b/lorrycontroller/status.py index 8fbc1b7..8483485 100644 --- a/lorrycontroller/status.py +++ b/lorrycontroller/status.py @@ -103,8 +103,8 @@ class StatusRenderer(object): free_bytes = result.f_bavail * result.f_bsize return { 'disk_free': free_bytes, - 'disk_free_mib': free_bytes / 1024**2, - 'disk_free_gib': free_bytes / 1024**3, + 'disk_free_mib': free_bytes // 1024**2, + 'disk_free_gib': free_bytes // 1024**3, } def get_run_queue(self, statedb): @@ -130,9 +130,9 @@ class StatusRenderer(object): result = [] - hours = secs / 3600 + hours = secs // 3600 secs %= 3600 - mins = secs / 60 + mins = secs // 60 secs %= 60 if hours > 0: -- cgit v1.2.1 From 16edf0a9cd3a7ee230135f8ed301fc9e8c3c6f2c Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 16 Jul 2020 19:15:14 +0100 Subject: status: Show free disk space in MiB when it's < 1 GiB Showing free disk space as 0 when it drops below 1 GiB may be unncessarily alarming, so show it in units of MiB if that happens. The status dictionary already includes it in both units. --- templates/status.tpl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/templates/status.tpl b/templates/status.tpl index 277b4b8..ff572de 100644 --- a/templates/status.tpl +++ b/templates/status.tpl @@ -46,7 +46,13 @@

Maximum number of jobs: {{max_jobs}}.

-

Free disk space: {{disk_free_gib}} GiB.

+

Free disk space: +% if disk_free_gib: + {{disk_free_gib}} GiB. +% else: + {{disk_free_mib}} MiB. +% end +

Upstream Hosts

-- cgit v1.2.1