| Conditions | 2 |
| Total Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | # -*- coding: utf8 -*- |
||
| 28 | def convert_size(size_bytes): |
||
| 29 | """ |
||
| 30 | Transform bytesize to a human readable filesize |
||
| 31 | |||
| 32 | :param size_bytes: bytesize |
||
| 33 | :return: human readable filesize |
||
| 34 | """ |
||
| 35 | if size_bytes == 0: |
||
| 36 | return "0B" |
||
| 37 | size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") |
||
| 38 | i = int(math.floor(math.log(size_bytes, 1024))) |
||
| 39 | p = math.pow(1024, i) |
||
| 40 | s = round(size_bytes / p, 2) |
||
| 41 | return "%s %s" % (s, size_name[i]) |
||
| 42 |