diff options
| author | Yeoh Ee Peng <ee.peng.yeoh@intel.com> | 2019-01-04 14:46:01 +0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-01-08 11:16:44 +0000 |
| commit | 71a1c1119b6cbe2f09a4eeb2ed54ee3de1315e28 (patch) | |
| tree | 80f7169b931ee7ef437d3ca6f0dc13ccb79a4a0f /scripts/oe-git-archive | |
| parent | a9b1f9eca96357be0081f5a421ffa314252b209e (diff) | |
| download | poky-71a1c1119b6cbe2f09a4eeb2ed54ee3de1315e28.tar.gz | |
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>
sys.exit(main())
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@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/oe-git-archive')
| -rwxr-xr-x | scripts/oe-git-archive | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/scripts/oe-git-archive b/scripts/oe-git-archive index ab19cb9aa3..913291a99c 100755 --- a/scripts/oe-git-archive +++ b/scripts/oe-git-archive | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/env python3 |
| 2 | # | 2 | # |
| 3 | # Helper script for committing data to git and pushing upstream | 3 | # Helper script for committing data to git and pushing upstream |
| 4 | # | 4 | # |
| @@ -208,6 +208,13 @@ def parse_args(argv): | |||
| 208 | help="Data to commit") | 208 | help="Data to commit") |
| 209 | return parser.parse_args(argv) | 209 | return parser.parse_args(argv) |
| 210 | 210 | ||
| 211 | def get_nested(d, list_of_keys): | ||
| 212 | try: | ||
| 213 | for k in list_of_keys: | ||
| 214 | d = d[k] | ||
| 215 | return d | ||
| 216 | except KeyError: | ||
| 217 | return "" | ||
| 211 | 218 | ||
| 212 | def main(argv=None): | 219 | def main(argv=None): |
| 213 | """Script entry point""" | 220 | """Script entry point""" |
| @@ -223,11 +230,11 @@ def main(argv=None): | |||
| 223 | 230 | ||
| 224 | # Get keywords to be used in tag and branch names and messages | 231 | # Get keywords to be used in tag and branch names and messages |
| 225 | metadata = metadata_from_bb() | 232 | metadata = metadata_from_bb() |
| 226 | keywords = {'hostname': metadata['hostname'], | 233 | keywords = {'hostname': get_nested(metadata, ['hostname']), |
| 227 | 'branch': metadata['layers']['meta']['branch'], | 234 | 'branch': get_nested(metadata, ['layers', 'meta', 'branch']), |
| 228 | 'commit': metadata['layers']['meta']['commit'], | 235 | 'commit': get_nested(metadata, ['layers', 'meta', 'commit']), |
| 229 | 'commit_count': metadata['layers']['meta']['commit_count'], | 236 | 'commit_count': get_nested(metadata, ['layers', 'meta', 'commit_count']), |
| 230 | 'machine': metadata['config']['MACHINE']} | 237 | 'machine': get_nested(metadata, ['config', 'MACHINE'])} |
| 231 | 238 | ||
| 232 | # Expand strings early in order to avoid getting into inconsistent | 239 | # Expand strings early in order to avoid getting into inconsistent |
| 233 | # state (e.g. no tag even if data was committed) | 240 | # state (e.g. no tag even if data was committed) |
