From 02affb458224f39eb4593cfba8dead8d2faa5084 Mon Sep 17 00:00:00 2001 From: Mariana Ulaieva Date: Dec 16 2019 16:52:09 +0000 Subject: Don't expect module build tasks to have "rpms" There are module builds, which won't build any components.There are module builds, which won't build any components. These module builds won't have an "rpms" key in "tasks". Expect this to happen and don't fail when watching module builds of this kind. Merges: https://pagure.io/rpkg/pull-request/476 Signed-off-by: Mariana Ulaieva --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 2dddad7..3271a03 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -3795,7 +3795,8 @@ class Commands(object): continue stats[stats_key_mapping[task_state]] = n stats['completion_percentage'] = \ - int(float(stats['done'] + stats['failed']) / stats['total'] * 100) + int(float(stats['done'] + stats['failed']) / stats['total'] * 100) \ + if stats['total'] > 0 else 100 # to avoid zero division when there were no task_infos return stats def get_watched_module_builds(self, build_ids): @@ -3823,7 +3824,7 @@ class Commands(object): # with -1 so that None does not impact the comparison for # sort. formatted_tasks = [] - for pkg_name, task_info in module_build['tasks']['rpms'].items(): + for pkg_name, task_info in module_build['tasks'].get('rpms', {}).items(): new_task_info = task_info.copy() new_task_info['package_name'] = pkg_name if new_task_info['state'] is None: