| 23 | sys.stderr.write("Error: {} does not exist\n".write()) |
| 24 | |
| 25 | class Mebibyte(int): |
| 26 | iec = {1: 'B', |
| 27 | 1024: 'KiB', |
| 28 | 1024**2: 'MiB', |
| 29 | 1024**3: 'GiB', |
| 30 | 1024**4: 'TiB', |
| 31 | 1024**5: 'PiB', |
| 32 | 1024**6: 'EiB', |
| 33 | 1024**7: 'ZiB', |
| 34 | 1024**8: 'YiB'} |
| 35 | iecl = [1, 1024, 1024**2, 1024**3, 1024**4, 1024**5, 1024**6, 1024**7, 1024**8] |
| 36 | |
| 37 | # custom format class for human readable IEC byte formatting |
| 38 | def __format__(self, spec): |
| 39 | # automatically format based on size |
| 40 | |
| 41 | iiec = max(0, min(bisect.bisect_right(self.iecl, int(self)), len(self.iecl))) |
| 42 | ieck = self.iecl[iiec - 1] |
| 43 | return '{:,.2f} {:s}'.format(int(self) / ieck, self.iec[ieck]) |
| 44 | |
| 45 | |
| 46 | @asyncio.coroutine |
no outgoing calls
searching dependent graphs…