diff options
author | Simon Glass <sjg@chromium.org> | 2022-08-13 11:40:44 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2022-08-20 18:07:32 -0600 |
commit | cdadadab7df4a938c54131b40828e7b4dfd5ef2f (patch) | |
tree | cfa795e113b67a7ceaba82948214878d6c21dc5a /tools/binman/entry.py | |
parent | 24474dc20a0626ebba2e9c95449dfdc1d9933eee (diff) |
binman: Add a way to check for missing properties
Some new entries are likely to have required properties. Support this in a
standard way, with a list of required properties which can be set up by
base classes. Check for missing properties when the entry is read.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/entry.py')
-rw-r--r-- | tools/binman/entry.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 28a7510990..d159d90e4c 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -84,6 +84,8 @@ class Entry(object): update_hash: True if this entry's "hash" subnode should be updated with a hash of the entry contents fake_fname: Fake filename, if one was created, else None + required_props (dict of str): Properties which must be present. This can + be added to by subclasses """ fake_dir = None @@ -121,6 +123,7 @@ class Entry(object): self.missing_bintools = [] self.update_hash = True self.fake_fname = None + self.required_props = [] @staticmethod def FindEntryClass(etype, expanded): @@ -238,6 +241,7 @@ class Entry(object): This reads all the fields we recognise from the node, ready for use. """ + self.ensure_props() if 'pos' in self._node.props: self.Raise("Please use 'offset' instead of 'pos'") if 'expand-size' in self._node.props: @@ -1184,3 +1188,19 @@ features to produce new behaviours. if not os.path.exists(cls.fake_dir): os.mkdir(cls.fake_dir) tout.notice(f"Fake-blob dir is '{cls.fake_dir}'") + + def ensure_props(self): + """Raise an exception if properties are missing + + Args: + prop_list (list of str): List of properties to check for + + Raises: + ValueError: Any property is missing + """ + not_present = [] + for prop in self.required_props: + if not prop in self._node.props: + not_present.append(prop) + if not_present: + self.Raise(f"'{self.etype}' entry is missing properties: {' '.join(not_present)}") |