MCPcopy Index your code
hub / github.com/SourceCode-AI/aura / convert_size

Function convert_size

aura/utils.py:297–322  ·  view source on GitHub ↗
(desc: Union[str, int])

Source from the content-addressed store, hash-verified

295
296
297def 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
325def convert_time(desc: int) -> timedelta:

Callers

nothing calls this directly

Calls 1

matchMethod · 0.45

Tested by

no test coverage detected