From 3d87e299ea958cca7426dcf08a0e0e3b08b5aa43 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 19 Nov 2016 15:42:06 +0900 Subject: [PATCH] Move formatted_time to library --- lib/util.py | 8 ++++++++ server/block_processor.py | 10 +--------- server/db.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/util.py b/lib/util.py index f41d4f2..3feab9d 100644 --- a/lib/util.py +++ b/lib/util.py @@ -37,6 +37,14 @@ class cachedproperty(object): return value +def formatted_time(t): + '''Return a number of seconds as a string in days, hours, mins and + secs.''' + t = int(t) + return '{:d}d {:02d}h {:02d}m {:02d}s'.format( + t // 86400, (t % 86400) // 3600, (t % 3600) // 60, t % 60) + + def deep_getsizeof(obj): """Find the memory footprint of a Python object. diff --git a/server/block_processor.py b/server/block_processor.py index 55a28f0..d9fd11f 100644 --- a/server/block_processor.py +++ b/server/block_processor.py @@ -21,7 +21,7 @@ from functools import partial from server.daemon import Daemon, DaemonError from server.version import VERSION from lib.hash import hash_to_str -from lib.util import chunks, LoggedClass +from lib.util import chunks, formatted_time, LoggedClass import server.db from server.storage import open_db @@ -30,14 +30,6 @@ HIST_ENTRIES_PER_KEY = 1024 HIST_VALUE_BYTES = HIST_ENTRIES_PER_KEY * 4 -def formatted_time(t): - '''Return a number of seconds as a string in days, hours, mins and - secs.''' - t = int(t) - return '{:d}d {:02d}h {:02d}m {:02d}s'.format( - t // 86400, (t % 86400) // 3600, (t % 3600) // 60, t % 60) - - class ChainError(Exception): pass diff --git a/server/db.py b/server/db.py index c44b17c..c1b3ff9 100644 --- a/server/db.py +++ b/server/db.py @@ -15,7 +15,7 @@ from struct import pack, unpack from bisect import bisect_right from collections import namedtuple -from lib.util import chunks, LoggedClass +from lib.util import chunks, formatted_time, LoggedClass from lib.hash import double_sha256, hash_to_str from server.storage import open_db from server.version import VERSION