예제 #1
0
def _get_parameter_value(string_value):
    """
    Guess the desired type of the parameter based on the string value

    @param string_value: The string value of a parameter
    """
    value = ParameterValue()
    try:
        yaml_value = yaml.safe_load(string_value)
    except yaml.parser.ParserError:
        value.type = ParameterType.PARAMETER_STRING
        value.string_value = string_value
        return value
    if isinstance(yaml_value, bool):
        value.type = ParameterType.PARAMETER_BOOL
        value.bool_value = yaml_value
    elif isinstance(yaml_value, int):
        value.type = ParameterType.PARAMETER_INTEGER
        value.integer_value = yaml_value
    elif isinstance(yaml_value, float):
        value.type = ParameterType.PARAMETER_DOUBLE
        value.double_value = yaml_value
    elif isinstance(yaml_value, list):
        if all((isinstance(v, bool) for v in yaml_value)):
            value.type = ParameterType.PARAMETER_BOOL_ARRAY
            value.bool_array_value = yaml_value
        elif all((isinstance(v, int) for v in yaml_value)):
            value.type = ParameterType.PARAMETER_INTEGER_ARRAY
            value.integer_array_value = yaml_value
        elif all((isinstance(v, float) for v in yaml_value)):
            value.type = ParameterType.PARAMETER_DOUBLE_ARRAY
            value.double_array_value = yaml_value
        elif all((isinstance(v, str) for v in yaml_value)):
            value.type = ParameterType.PARAMETER_STRING_ARRAY
            value.string_array_value = yaml_value
        else:
            value.type = ParameterType.PARAMETER_STRING
            value.string_value = string_value
    else:
        value.type = ParameterType.PARAMETER_STRING
        value.string_value = string_value
    return value
예제 #2
0
 def get_parameter_value(self):
     parameter_value = ParameterValue(type=self.type_.value)
     if Parameter.Type.BOOL == self.type_:
         parameter_value.bool_value = self.value
     elif Parameter.Type.INTEGER == self.type_:
         parameter_value.integer_value = self.value
     elif Parameter.Type.DOUBLE == self.type_:
         parameter_value.double_value = self.value
     elif Parameter.Type.STRING == self.type_:
         parameter_value.string_value = self.value
     elif Parameter.Type.BYTE_ARRAY == self.type_:
         parameter_value.byte_array_value = self.value
     elif Parameter.Type.BOOL_ARRAY == self.type_:
         parameter_value.bool_array_value = self.value
     elif Parameter.Type.INTEGER_ARRAY == self.type_:
         parameter_value.integer_array_value = self.value
     elif Parameter.Type.DOUBLE_ARRAY == self.type_:
         parameter_value.double_array_value = self.value
     elif Parameter.Type.STRING_ARRAY == self.type_:
         parameter_value.string_array_value = self.value
     return parameter_value