Remove unnecessary code

This commit is contained in:
George Lacey 2021-05-06 08:07:57 +01:00
parent 0576745264
commit 3514aae3aa

View File

@ -18,7 +18,7 @@ class Summary(object):
return_string += f"{repo_name} ({repo.location}):\n" return_string += f"{repo_name} ({repo.location}):\n"
else: else:
return_string += f"{repo.location}:\n" return_string += f"{repo.location}:\n"
return_string += f"\t> Last backup: {self.seconds_to_string(latest_archive.seconds_since(), 'day', True)}" \ return_string += f"\t> Last backup: {self.seconds_to_string(latest_archive.seconds_since(), True)}" \
f" ago\n" f" ago\n"
return_string += f"\t> Un/Compressed size: {self.bytes_to_string(cache.unique_size)}" \ return_string += f"\t> Un/Compressed size: {self.bytes_to_string(cache.unique_size)}" \
f"/{self.bytes_to_string(cache.unique_csize)}\n" f"/{self.bytes_to_string(cache.unique_csize)}\n"
@ -66,21 +66,14 @@ class Summary(object):
return weeks return weeks
@staticmethod @staticmethod
def seconds_to_string(seconds: int, detail='hour', short=False): def seconds_to_string(seconds: int, short=False):
seconds = int(seconds) seconds = int(seconds)
increments = [('year', 31557600), increments = [('year', 'yr', 31557600),
('week', 604800), ('week', 'wk', 604800),
('day', 86400), ('day', 'day', 86400),
('hour', 3600), ('hour', 'hr', 3600),
('minute', 60), ('minute', 'min', 60),
('second', 1)] ('second', 'sec', 1)]
if short:
increments = [('yr', 31557600),
('wk', 604800),
('day', 86400),
('hr', 3600),
('min', 60),
('sec', 1)]
if seconds == 0: if seconds == 0:
return f"0 {increments[-1][0]}s" return f"0 {increments[-1][0]}s"
@ -88,9 +81,11 @@ class Summary(object):
time_string = "" time_string = ""
remainder = seconds remainder = seconds
for st, s in increments: for st, sst, s in increments:
if remainder == 0: if remainder == 0:
break break
if short:
st = sst
if remainder < s or remainder == 0: if remainder < s or remainder == 0:
continue continue
else: else:
@ -100,12 +95,9 @@ class Summary(object):
time_string += f"{exact} {st}s, " time_string += f"{exact} {st}s, "
else: else:
time_string += f"{exact} {st}, " time_string += f"{exact} {st}, "
if st == detail: if short:
break break
if short: return time_string.strip().strip(',')[::-1].replace(' ,', ' dna ', 1)[::-1]
return time_string.split(',')[0]
else:
return time_string.strip().strip(',')[::-1].replace(' ,', ' dna ', 1)[::-1]
@staticmethod @staticmethod
def bytes_to_string(bytes: int): def bytes_to_string(bytes: int):