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)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10 | for flag, value in list(flags.items())) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | else: |
| 12 | flags = {} |
| 13 | |
| 14 | try: |
| 15 | return oe.maketype.create(d.getVar(key, True) or '', var_type, **flags) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 16 | except (TypeError, ValueError) as exc: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | bb.msg.fatal("Data", "%s: %s" % (key, str(exc))) |