Exemple #1
0
 def property_convert(self, name, value):
     """
     Convert the given value into the type which is declared in the
     property schema at the specified path. The original value is returned
     when the property type can not be processed, e.g. 'any', 'array',
     'object' or 'null'.
     :param name: The path of the property, e.g. "aaa.bbb.ccc".
     :param value: The value to convert.
     :returns: The converted value.
     """
     prop_schema = self.schema.get_by_path(name)
     if isinstance(prop_schema['type'], list):
         raise openmediavault.json.SchemaException(
             "The attribute 'type' must not be an array at '%s'." % name)
     if "boolean" == prop_schema['type']:
         result = openmediavault.bool(value)
     elif "integer" == prop_schema['type']:
         result = int(value)
     elif prop_schema['type'] in ["number", "double", "float"]:
         result = float(value)
     elif "string" == prop_schema['type']:
         result = str(value)
     else:
         result = value
     return result
Exemple #2
0
 def property_convert(self, name, value):
     """
     Convert the given value into the type which is declared in the
     property schema at the specified path. The original value is returned
     when the property type can not be processed, e.g. 'any', 'array',
     'object' or 'null'.
     :param name: The path of the property, e.g. "aaa.bbb.ccc".
     :param value: The value to convert.
     :returns: The converted value.
     """
     prop_schema = self.schema.get_by_path(name)
     if isinstance(prop_schema['type'], list):
         raise openmediavault.json.SchemaException(
             "The attribute 'type' must not be an array at '%s'." % name)
     try:
         if "boolean" == prop_schema['type']:
             result = openmediavault.bool(value)
         elif "integer" == prop_schema['type']:
             result = int(value)
         elif prop_schema['type'] in ['number', 'double', 'float']:
             result = float(value)
         elif "string" == prop_schema['type']:
             result = str(value)
         else:
             result = value
     except ValueError as e:
         # Re-raise the exception, but with a more meaningful message.
         raise ValueError("Failed to convert property '{}': {}".format(
             name, str(e)))
     return result
 def property_convert(self, name, value):
     """
     Convert the given value into the type which is declared in the
     property schema at the specified path. The original value is returned
     when the property type can not be processed, e.g. 'any', 'array',
     'object' or 'null'.
     :param name: The path of the property, e.g. "aaa.bbb.ccc".
     :param value: The value to convert.
     :returns: The converted value.
     """
     prop_schema = self.schema.get_by_path(name)
     if isinstance(prop_schema['type'], list):
         raise openmediavault.json.SchemaException(
             "The attribute 'type' must not be an array at '%s'." % name
         )
     if "boolean" == prop_schema['type']:
         result = openmediavault.bool(value)
     elif "integer" == prop_schema['type']:
         result = int(value)
     elif prop_schema['type'] in ["number", "double", "float"]:
         result = float(value)
     elif "string" == prop_schema['type']:
         result = str(value)
     else:
         result = value
     return result
Exemple #4
0
 def get_bool(key, default=None):
     value = __class__.get(key, default)
     return openmediavault.bool(value)
Exemple #5
0
 def test_bool_no(self):
     value = openmediavault.bool("no")
     self.assertEqual(value, False)
Exemple #6
0
 def test_bool_yes(self):
     value = openmediavault.bool("yes")
     self.assertEqual(value, True)
Exemple #7
0
 def get_bool(key, default=None):
     value = __class__.get(key, default)
     return omv.bool(value)
Exemple #8
0
 def get_bool(key, default=None):
     value = Environment.get(key, default)
     return openmediavault.bool(value)
	def test_bool_no(self):
		value = openmediavault.bool("no")
		self.assertEqual(value, False)
	def test_bool_yes(self):
		value = openmediavault.bool("yes")
		self.assertEqual(value, True)