From d3867baca23f212ed15620faf32c21509e1d7ad3 Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Nov 01 2019 19:24:15 +0000 Subject: Improve reporting and avoid exceptions when watching module builds that failed while still initializing. Signed-off-by: Merlin Mathesius --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index b139fe0..15cbf7f 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -3812,15 +3812,17 @@ class Commands(object): 'completion_percentage': 0 } - for task_state, task_infos in build_info['tasks']['rpms'].items(): + for task_state, task_infos in build_info['tasks'].get('rpms', {}).items(): assert isinstance(task_infos, list) n = len(task_infos) stats['total'] += n if task_state not in stats_key_mapping: continue stats[stats_key_mapping[task_state]] = n - stats['completion_percentage'] = \ - int(float(stats['done'] + stats['failed']) / stats['total'] * 100) + # avoid potential divide by zero exception + if stats['total']: + stats['completion_percentage'] = \ + int(float(stats['done'] + stats['failed']) / stats['total'] * 100) return stats def get_watched_module_builds(self, build_ids): @@ -3845,7 +3847,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: