Shutdown VM, ListUserFiles added. Able to parse units included in specs

This commit is contained in:
ahmadbilalkhalid 2019-07-11 13:34:21 +05:00
commit 68f9bebccb
4 changed files with 115 additions and 35 deletions

25
specs_parser.py Normal file
View 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))