Shutdown VM, ListUserFiles added. Able to parse units included in specs
This commit is contained in:
parent
993fbbc3ac
commit
68f9bebccb
4 changed files with 115 additions and 35 deletions
25
specs_parser.py
Normal file
25
specs_parser.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import bitmath
|
||||
|
||||
class SpecsParser(object):
|
||||
def __init__(self, exceptional_devices, allowed_unit = 10):
|
||||
self.exceptional_devices = exceptional_devices
|
||||
self.allowed_unit = allowed_unit
|
||||
|
||||
def transform_specs(self, specs):
|
||||
try:
|
||||
for device in filter(lambda x: x not in self.exceptional_devices, specs):
|
||||
parsed = bitmath.parse_string_unsafe(specs[device])
|
||||
if parsed.base != self.allowed_unit:
|
||||
return False
|
||||
specs[device] = int(parsed.to_Byte())
|
||||
return True
|
||||
except ValueError as _:
|
||||
return False
|
||||
|
||||
def get_allowed_units(self):
|
||||
if self.allowed_unit == 10:
|
||||
unit_prefix = bitmath.SI_PREFIXES
|
||||
else:
|
||||
unit_prefix = bitmath.NIST_PREFIXES
|
||||
|
||||
return list(map(lambda u: u.upper() + "B", unit_prefix))
|
||||
Loading…
Add table
Add a link
Reference in a new issue