Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import oe.maketype |
| 2 | |
| 3 | def typed_value(key, d): |
| 4 | """Construct a value for the specified metadata variable, using its flags |
| 5 | to determine the type and parameters for construction.""" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 6 | var_type = d.getVarFlag(key, 'type', True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | flags = d.getVarFlags(key) |
| 8 | if flags is not None: |
| 9 | flags = dict((flag, d.expand(value)) |
| 10 | for flag, value in flags.iteritems()) |
| 11 | else: |
| 12 | flags = {} |
| 13 | |
| 14 | try: |
| 15 | return oe.maketype.create(d.getVar(key, True) or '', var_type, **flags) |
| 16 | except (TypeError, ValueError), exc: |
| 17 | bb.msg.fatal("Data", "%s: %s" % (key, str(exc))) |