From: Awais Belal Date: Sun, 26 Aug 2018 22:33:27 +0000 (-0700) Subject: bitbake: toaster/widgets.py: avoid divide by zero issues X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=215c18771248ab71149b85d4aabd3e12b6409556;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git bitbake: toaster/widgets.py: avoid divide by zero issues There can be cases where the variables being used to divide in build percentage expressions can be zero. For example, a setup consisting of only local repos will have repos_to_clone=0 and will generate a divide by zero scenario. Fix this by checking the divisor in such cases. [YOCTO #12891] (Bitbake rev: 679c70aa32d23e9247f8a68efcb579ad733af84b) Signed-off-by: Awais Belal Signed-off-by: David Reyna Signed-off-by: Richard Purdie --- diff --git a/bitbake/lib/toaster/toastergui/widgets.py b/bitbake/lib/toaster/toastergui/widgets.py index 88dff8a8573..db5c3aa00b7 100644 --- a/bitbake/lib/toaster/toastergui/widgets.py +++ b/bitbake/lib/toaster/toastergui/widgets.py @@ -515,13 +515,18 @@ class MostRecentBuildsView(View): buildrequest_id = build_obj.buildrequest.pk build['buildrequest_id'] = buildrequest_id - build['recipes_parsed_percentage'] = \ - int((build_obj.recipes_parsed / - build_obj.recipes_to_parse) * 100) - - build['repos_cloned_percentage'] = \ - int((build_obj.repos_cloned / - build_obj.repos_to_clone) * 100) + if build_obj.recipes_to_parse > 0: + build['recipes_parsed_percentage'] = \ + int((build_obj.recipes_parsed / + build_obj.recipes_to_parse) * 100) + else: + build['recipes_parsed_percentage'] = 0 + if build_obj.repos_to_clone > 0: + build['repos_cloned_percentage'] = \ + int((build_obj.repos_cloned / + build_obj.repos_to_clone) * 100) + else: + build['repos_cloned_percentage'] = 0 build['progress_item'] = build_obj.progress_item