[sumo,4/8] toaster/widgets.py: avoid divide by zero issues
Submitted by Belal, Awais on July 6, 2018, 10:43 a.m.
|
Patch ID: 152382
Details
Commit Message
@@ -511,13 +511,15 @@ 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)
+
+ if build_obj.repos_to_clone > 0:
+ build['repos_cloned_percentage'] = \
+ int((build_obj.repos_cloned /
+ build_obj.repos_to_clone) * 100)
tasks_complete_percentage = 0
if build_obj.outcome in (Build.SUCCEEDED, Build.FAILED):
There can be cases where the variables being used to divide in these expressions can be zero. e.g. 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. Signed-off-by: Awais Belal <awais_belal@mentor.com> --- bitbake/lib/toaster/toastergui/widgets.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)