Files
mealie/mealie/utils/fs_stats.py
Hayden dce84c3937 refactor: ♻️ rewrite admin CRUD interface for admins (#825)
* docs: 📝 general documentation + add FAQ page

* fix(frontend): 🐛 readd missing upload button to backups.

* feat(backend):  add support for backup sizes to be displayed on frontend

* feat(backend):  add backend for administrator CRUD of users

* add admin support for user

* refactor(frontend): ♻️ rewrite admin CRUD interface for admins

* fix build errors

Co-authored-by: hay-kot <hay-kot@pm.me>
2021-11-23 18:57:24 -09:00

16 lines
552 B
Python

def pretty_size(size: int) -> str:
"""
Pretty size takes in a integer value of a file size and returns the most applicable
file unit and the size.
"""
if size < 1024:
return f"{size} bytes"
elif size < 1024 ** 2:
return f"{round(size / 1024, 2)} KB"
elif size < 1024 ** 2 * 1024:
return f"{round(size / 1024 / 1024, 2)} MB"
elif size < 1024 ** 2 * 1024 * 1024:
return f"{round(size / 1024 / 1024 / 1024, 2)} GB"
else:
return f"{round(size / 1024 / 1024 / 1024 / 1024, 2)} TB"