Hi Alper, On Tue, 8 Sep 2020 at 10:37, Alper Nebi Yasak <alpernebiya...@gmail.com> wrote: > > On 06/09/2020 19:39, Simon Glass wrote: > > When an external blob is missing it can be quite confusing for the user. > > Add a way to provide a help message that is shown. > > > > Signed-off-by: Simon Glass <s...@chromium.org> > > --- > > > > (no changes since v3) > > > > Changes in v3: > > - Add a way to show help messages for missing blobs > > > > tools/binman/README | 6 ++ > > tools/binman/control.py | 69 +++++++++++++++++++++- > > tools/binman/entry.py | 9 +++ > > tools/binman/ftest.py | 18 +++++- > > tools/binman/missing-blob-help | 11 ++++ > > tools/binman/test/168_fit_missing_blob.dts | 9 ++- > > 6 files changed, 119 insertions(+), 3 deletions(-) > > create mode 100644 tools/binman/missing-blob-help > > > > diff --git a/tools/binman/README b/tools/binman/README > > index 37ee3fc2d3b..f7bf285a915 100644 > > --- a/tools/binman/README > > +++ b/tools/binman/README > > @@ -343,6 +343,12 @@ compress: > > Sets the compression algortihm to use (for blobs only). See the entry > > documentation for details. > > > > +missing-msg: > > + Sets the tag of the message to show if this entry is missing. This is > > + used for external blobs. When they are missing it is helpful to show > > + information about what needs to be fixed. See missing-blob-help for > > the > > + message for each tag. > > + > > The attributes supported for images and sections are described below. > > Several > > are similar to those for entries. > > > > diff --git a/tools/binman/control.py b/tools/binman/control.py > > index 15bfac582a7..ee5771e7292 100644 > > --- a/tools/binman/control.py > > +++ b/tools/binman/control.py > > @@ -9,6 +9,7 @@ from collections import OrderedDict > > import glob > > import os > > import pkg_resources > > +import re > > > > import sys > > from patman import tools > > @@ -22,6 +23,11 @@ from patman import tout > > # Make this global so that it can be referenced from tests > > images = OrderedDict() > > > > +# Help text for each type of missing blob, dict: > > +# key: Value of the entry's 'missing-msg' or entry name > > +# value: Text for the help > > +missing_blob_help = {} > > + > > def _ReadImageDesc(binman_node): > > """Read the image descriptions from the /binman node > > > > @@ -54,6 +60,66 @@ def _FindBinmanNode(dtb): > > return node > > return None > > > > +def _ReadMissingBlobHelp(): > > + """Read the missing-blob-help file > > + > > + This file containins help messages explaining what to do when external > > blobs > > + are missing. > > + > > + Returns: > > + Dict: > > + key: Message tag (str) > > + value: Message text (str) > > + """ > > + > > + def _FinishTag(tag, msg, result): > > + if tag: > > + result[tag] = msg.rstrip() > > + tag = None > > + msg = '' > > + return tag, msg > > + > > + my_data = pkg_resources.resource_string(__name__, 'missing-blob-help') > > + re_tag = re.compile('^([-a-z0-9]+):$') > > + result = {} > > + tag = None > > + msg = '' > > + for line in my_data.decode('utf-8').splitlines(): > > + if not line.startswith('#'): > > + m_tag = re_tag.match(line) > > + if m_tag: > > + _, msg = _FinishTag(tag, msg, result) > > + tag = m_tag.group(1) > > + elif tag: > > + msg += line + '\n' > > + _FinishTag(tag, msg, result) > > + return result > > This looks a bit complex, I think something like this would be clearer: > > result = {} > tag = None > for line in my_data.decode('utf-8').splitlines(): > m_tag = re_tag.match(line) > if line.startswith('#'): > continue > elif m_tag: > tag = m_tag.group(1) > result[tag] = [] > elif tag: > result[tag].append(line) > for tag, lines in result.items(): > result[tag] = "".join(lines).rstrip() > return result >
Yes that is easier, thank you. I'll use this in v4 and perhaps you can reply with your sign-off. Regards, Simon