| 295 | |
| 296 | |
| 297 | def convert_size(desc: Union[str, int]) -> int: |
| 298 | if type(desc) == int: |
| 299 | return desc |
| 300 | |
| 301 | parsed = re.match(r"^(\d+)([kmgtp]b?)?$", desc, flags=re.I) |
| 302 | g = parsed.groups() |
| 303 | |
| 304 | if len(g) < 1 or len(g) > 2: |
| 305 | raise ValueError(f"Could not parse the string '{desc}'") |
| 306 | |
| 307 | amount: str = g[0] |
| 308 | if not amount.isdigit(): |
| 309 | raise ValueError(f"'{amount}' is not a valid number") |
| 310 | |
| 311 | amount: int = int(amount) |
| 312 | |
| 313 | if len(g) == 2 and g[1] is not None: |
| 314 | unit = g[1].lower() |
| 315 | if not unit.endswith("b"): |
| 316 | unit += "b" |
| 317 | |
| 318 | pos = SIZE_UNITS.index(unit) + 1 |
| 319 | else: |
| 320 | pos = 0 |
| 321 | |
| 322 | return amount * (1024**pos) |
| 323 | |
| 324 | |
| 325 | def convert_time(desc: int) -> timedelta: |