(size)
| 19 | |
| 20 | |
| 21 | def parse_size(size): |
| 22 | units = { |
| 23 | "B": 1, |
| 24 | "KB": 2 ** 10, |
| 25 | "MB": 2 ** 20, |
| 26 | "GB": 2 ** 30, |
| 27 | "TB": 2 ** 40, |
| 28 | "": 1, |
| 29 | "KIB": 10 ** 3, |
| 30 | "MIB": 10 ** 6, |
| 31 | "GIB": 10 ** 9, |
| 32 | "TIB": 10 ** 12, |
| 33 | } |
| 34 | m = re.match(r"^([\d\.]+)\s*([a-zA-Z]{0,3})$", str(size).strip()) |
| 35 | assert m is not None |
| 36 | number, unit = float(m.group(1)), m.group(2).upper() |
| 37 | return int(number * units[unit]) |
| 38 | |
| 39 | |
| 40 | def set_budget(budget: str): |