| Total Complexity | 4 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import os |
||
| 2 | import shutil |
||
| 3 | from dirutility.backup import ZipBackup |
||
| 4 | |||
| 5 | directory = 'data/games' |
||
| 6 | destination = os.path.join(os.path.dirname(__file__), 'data') |
||
| 7 | if os.path.exists(destination): |
||
| 8 | shutil.rmtree(destination) |
||
| 9 | if not os.path.exists(destination): |
||
| 10 | os.mkdir(destination) |
||
| 11 | |||
| 12 | |||
| 13 | def humanize_bytes(bytes, precision=2): |
||
| 14 | """Return a humanized string representation of a number of bytes.""" |
||
| 15 | abbrevs = ((1 << 50, 'PB'), (1 << 40, 'TB'), (1 << 30, 'GB'), (1 << 20, 'MB'), (1 << 10, 'kB'), (1, 'bytes')) |
||
| 16 | if bytes == 1: |
||
| 17 | return '1 byte' |
||
| 18 | for factor, suffix in abbrevs: |
||
| 19 | if bytes >= factor: |
||
| 20 | break |
||
| 21 | return '%.*f %s' % (precision, bytes / factor, suffix) |
||
| 22 | |||
| 23 | |||
| 24 | for i in range(0, 10): |
||
| 25 | d = ZipBackup(directory, destination, compress_level=i).backup() |
||
| 26 | print(humanize_bytes(os.path.getsize(str(d))), d) |
||
| 27 |