[oe-commits] [openembedded-core] 11/49: scripts/oe-git-archive: fix non-existent key referencing error

git at git.openembedded.org git at git.openembedded.org
Mon Feb 25 22:28:17 UTC 2019

This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch sumo
in repository openembedded-core.

commit 89dcc555f57ce13645c3876b42be3846fe3b7863
Author: Yeoh Ee Peng <ee.peng.yeoh at intel.com>
AuthorDate: Fri Jan 4 14:46:01 2019 +0800

    scripts/oe-git-archive: fix non-existent key referencing error
    Without installing gitpython package, oe-git-archive will face error
    below, where it was referencing key that was non-existent inside
    metadata object.
    Traceback (most recent call last):
      File "<poky_dir>/scripts/oe-git-archive", line 271, in <module>
      File "<poky_dir>/scripts/oe-git-archive", line 229, in main
        'commit_count': metadata['layers']['meta']['commit_count'],
    KeyError: 'commit_count'
    Fix this error by adding exception catch when referencing
    non-existent key (based on inputs provided by Richard Purdie).
    [YOCTO# 13082]
    (From OE-Core rev: 9a3cc9b8523b78dda6c3f3f2e12798b2b907d7e5)
    Signed-off-by: Yeoh Ee Peng <ee.peng.yeoh at intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
    Signed-off-by: Armin Kuster <akuster808 at gmail.com>
 scripts/oe-git-archive | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/scripts/oe-git-archive b/scripts/oe-git-archive
index ab19cb9..913291a 100755
--- a/scripts/oe-git-archive
+++ b/scripts/oe-git-archive
@@ -1,4 +1,4 @@
+#!/usr/bin/env python3
 # Helper script for committing data to git and pushing upstream
@@ -208,6 +208,13 @@ def parse_args(argv):
                         help="Data to commit")
     return parser.parse_args(argv)
+def get_nested(d, list_of_keys):
+    try:
+        for k in list_of_keys:
+            d = d[k]
+        return d
+    except KeyError:
+        return ""
 def main(argv=None):
     """Script entry point"""
@@ -223,11 +230,11 @@ def main(argv=None):
         # Get keywords to be used in tag and branch names and messages
         metadata = metadata_from_bb()
-        keywords = {'hostname': metadata['hostname'],
-                    'branch': metadata['layers']['meta']['branch'],
-                    'commit': metadata['layers']['meta']['commit'],
-                    'commit_count': metadata['layers']['meta']['commit_count'],
-                    'machine': metadata['config']['MACHINE']}
+        keywords = {'hostname': get_nested(metadata, ['hostname']),
+                    'branch': get_nested(metadata, ['layers', 'meta', 'branch']),
+                    'commit': get_nested(metadata, ['layers', 'meta', 'commit']),
+                    'commit_count': get_nested(metadata, ['layers', 'meta', 'commit_count']),
+                    'machine': get_nested(metadata, ['config', 'MACHINE'])}
         # Expand strings early in order to avoid getting into inconsistent
         # state (e.g. no tag even if data was committed)

To stop receiving notification emails like this one, please contact
the administrator of this repository.

More information about the Openembedded-commits mailing list