def get_unit_size(value, unit):
     if value is None:
         return None
     if value == '0' or value == 0:
         return 0
     unit_array = unit.split('/')
     capacity = Tools.change_capacity_to_bytes(unit_array[0])
     if capacity == 1:
         return value
     return round(int(value) / capacity, 3)
示例#2
0
 def parse_string_to_bytes(value):
     capacity = 0
     if value:
         if value.isdigit():
             capacity = float(value)
         else:
             if value == '0B':
                 capacity = 0
             else:
                 unit = value[-2:]
                 capacity = float(value[:-2]) * int(
                     Tools.change_capacity_to_bytes(unit))
     return capacity