mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-18 01:08:12 +00:00
Misc cleanup (#73)
* Stop previously running zeroconf instances * Lots of formatting fixes * Use f-strings for time delta * More line fixes * Update requirements.txt * More misc cleanup * Simplify README.md
This commit is contained in:
@@ -36,9 +36,9 @@ def file_exists_in_mounts(filepath):
|
||||
path = os.path.normpath(path)
|
||||
components = []
|
||||
while True:
|
||||
path, component = os.path.split(path)
|
||||
if component:
|
||||
components.append(component)
|
||||
path, comp = os.path.split(path)
|
||||
if comp:
|
||||
components.append(comp)
|
||||
else:
|
||||
if path:
|
||||
components.append(path)
|
||||
@@ -64,20 +64,17 @@ def file_exists_in_mounts(filepath):
|
||||
|
||||
def get_time_elapsed(start_time=None, end_time=None):
|
||||
|
||||
from string import Template
|
||||
|
||||
class DeltaTemplate(Template):
|
||||
delimiter = "%"
|
||||
|
||||
def strfdelta(tdelta, fmt='%H:%M:%S'):
|
||||
d = {"D": tdelta.days}
|
||||
days = tdelta.days
|
||||
hours, rem = divmod(tdelta.seconds, 3600)
|
||||
minutes, seconds = divmod(rem, 60)
|
||||
d["H"] = '{:02d}'.format(hours)
|
||||
d["M"] = '{:02d}'.format(minutes)
|
||||
d["S"] = '{:02d}'.format(seconds)
|
||||
t = DeltaTemplate(fmt)
|
||||
return t.substitute(**d)
|
||||
|
||||
# Using f-strings for formatting
|
||||
formatted_str = fmt.replace('%D', f'{days}')
|
||||
formatted_str = formatted_str.replace('%H', f'{hours:02d}')
|
||||
formatted_str = formatted_str.replace('%M', f'{minutes:02d}')
|
||||
formatted_str = formatted_str.replace('%S', f'{seconds:02d}')
|
||||
return formatted_str
|
||||
|
||||
# calculate elapsed time
|
||||
elapsed_time = None
|
||||
@@ -95,7 +92,7 @@ def get_time_elapsed(start_time=None, end_time=None):
|
||||
def get_file_size_human(file_path):
|
||||
size_in_bytes = os.path.getsize(file_path)
|
||||
|
||||
# Convert size to a human readable format
|
||||
# Convert size to a human-readable format
|
||||
if size_in_bytes < 1024:
|
||||
return f"{size_in_bytes} B"
|
||||
elif size_in_bytes < 1024 ** 2:
|
||||
|
||||
Reference in New Issue
Block a user