File: helpers.py

package info (click to toggle)
python-aioasuswrt 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 168 kB
  • sloc: python: 1,283; makefile: 5
file content (11 lines) | stat: -rw-r--r-- 309 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
import math


def convert_size(size_bytes):
    if size_bytes == 0:
        return "0 B"
    size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
    i = int(math.floor(math.log(size_bytes, 1024)))
    p = math.pow(1024, i)
    s = round(size_bytes / p, 2)
    return "%s %s" % (s, size_name[i])