fix: Added human readable file size func
This commit is contained in:
parent
26be4a2604
commit
a94db8a5ce
1 changed files with 15 additions and 0 deletions
|
|
@ -706,3 +706,18 @@ def get_html_for_route(route):
|
|||
response = render.render()
|
||||
html = frappe.safe_decode(response.get_data())
|
||||
return html
|
||||
|
||||
def get_file_size(path, format=False):
|
||||
num = os.path.getsize(path)
|
||||
|
||||
if not format:
|
||||
return num
|
||||
|
||||
suffix = 'B'
|
||||
|
||||
for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
|
||||
if abs(num) < 1024:
|
||||
return "{0:3.1f}{1}{2}".format(num, unit, suffix)
|
||||
num /= 1024
|
||||
|
||||
return "{0:.1f}{1}{2}".format(num, 'Yi', suffix)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue