コード例 #1
0
 def testGetDataType(self):
     self.assertEqual(1, fdt_util.GetDatatype(self.node, 'intval', int))
     self.assertEqual('message',
                      fdt_util.GetDatatype(self.node, 'stringval', str))
     with self.assertRaises(ValueError) as e:
         self.assertEqual(3, fdt_util.GetDatatype(self.node, 'boolval',
                                                  bool))
コード例 #2
0
    def GetArg(self, name, datatype=str):
        """Get the value of an entry argument or device-tree-node property

        Some node properties can be provided as arguments to binman. First check
        the entry arguments, and fall back to the device tree if not found

        Args:
            name: Argument name
            datatype: Data type (str or int)

        Returns:
            Value of argument as a string or int, or None if no value

        Raises:
            ValueError if the argument cannot be converted to in
        """
        value = state.GetEntryArg(name)
        if value is not None:
            if datatype == int:
                try:
                    value = int(value)
                except ValueError:
                    self.Raise(
                        "Cannot convert entry arg '%s' (value '%s') to integer"
                        % (name, value))
            elif datatype == str:
                pass
            else:
                raise ValueError(
                    "GetArg() internal error: Unknown data type '%s'" %
                    datatype)
        else:
            value = fdt_util.GetDatatype(self._node, name, datatype)
        return value