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