fix `valid_parted_position()` (#1382)

* fix `valid_parted_position()`

* make lines shorter

* change `pos` to `pos.lower()`

* revert changing `if not len(pos):` to `if not pos:`

* `b` can not have decimal places

* add `.lower()`
This commit is contained in:
Samaoo 2022-08-01 14:07:04 +02:00 committed by GitHub
parent 68d89a07df
commit 5626c10927
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 5 deletions

View File

@ -7,13 +7,11 @@ def valid_parted_position(pos :str) -> bool:
if pos.isdigit():
return True
if pos[-1] == '%' and pos[:-1].isdigit():
if pos.lower().endswith('b') and pos[:-1].isdigit():
return True
if pos[-3:].lower() in ['mib', 'kib', 'b', 'tib'] and pos[:-3].replace(".", "", 1).isdigit():
return True
if pos[-2:].lower() in ['kb', 'mb', 'gb', 'tb'] and pos[:-2].replace(".", "", 1).isdigit():
if any(pos.lower().endswith(size) and pos[:-len(size)].replace(".", "", 1).isdigit()
for size in ['%', 'kb', 'mb', 'gb', 'tb', 'kib', 'mib', 'gib', 'tib']):
return True
return False