diff mbox series

support/scripts/size-stats: avoid divide-by-zero

Message ID 20171128033707.15072-1-yurovsky@gmail.com
State Accepted
Headers show
Series support/scripts/size-stats: avoid divide-by-zero | expand

Commit Message

Andrey Yurovsky Nov. 28, 2017, 3:37 a.m. UTC
Some packages (ex: skeleton-init-systemd) have a zero size so we cannot
divide by the package size. In that case make their percent zero
explicitly and avoid a ZeroDivisionError exception.

Signed-off-by: Andrey Yurovsky <yurovsky@gmail.com>
---
 support/scripts/size-stats | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Yann E. MORIN Nov. 28, 2017, 10:09 a.m. UTC | #1
Andrey, Thomas, All,

On 2017-11-27 19:37 -0800, Andrey Yurovsky spake thusly:
> Some packages (ex: skeleton-init-systemd) have a zero size so we cannot
> divide by the package size. In that case make their percent zero
> explicitly and avoid a ZeroDivisionError exception.
> 
> Signed-off-by: Andrey Yurovsky <yurovsky@gmail.com>

Acked-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

Regards,
Yann E. MORIN.

> ---
>  support/scripts/size-stats | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/support/scripts/size-stats b/support/scripts/size-stats
> index af45000359..3ff2a1ce18 100755
> --- a/support/scripts/size-stats
> +++ b/support/scripts/size-stats
> @@ -178,9 +178,17 @@ def gen_files_csv(filesdict, pkgsizes, outputf):
>                       "File size in system (%)"])
>          for f, (pkgname, filesize) in filesdict.items():
>              pkgsize = pkgsizes[pkgname]
> +
> +            if pkgsize == 0:
> +                percent_pkg = 0
> +            else:
> +                percent_pkg = float(filesize) / pkgsize * 100
> +
> +            percent_total = float(filesize) / total * 100
> +
>              wr.writerow([f, pkgname, filesize, pkgsize,
> -                         "%.1f" % (float(filesize) / pkgsize * 100),
> -                         "%.1f" % (float(filesize) / total * 100)])
> +                         "%.1f" % percent_pkg,
> +                         "%.1f" % percent_total])
>  
>  
>  #
> -- 
> 2.14.3
> 
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Thomas Petazzoni Nov. 29, 2017, 8:36 p.m. UTC | #2
Hello,

On Mon, 27 Nov 2017 19:37:07 -0800, Andrey Yurovsky wrote:
> Some packages (ex: skeleton-init-systemd) have a zero size so we cannot
> divide by the package size. In that case make their percent zero
> explicitly and avoid a ZeroDivisionError exception.
> 
> Signed-off-by: Andrey Yurovsky <yurovsky@gmail.com>
> ---
>  support/scripts/size-stats | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)

Applied to master, thanks.

Thomas
Peter Korsgaard Dec. 20, 2017, 8:52 p.m. UTC | #3
>>>>> "Andrey" == Andrey Yurovsky <yurovsky@gmail.com> writes:

 > Some packages (ex: skeleton-init-systemd) have a zero size so we cannot
 > divide by the package size. In that case make their percent zero
 > explicitly and avoid a ZeroDivisionError exception.

 > Signed-off-by: Andrey Yurovsky <yurovsky@gmail.com>

Committed to 2017.02.x, thanks.
diff mbox series

Patch

diff --git a/support/scripts/size-stats b/support/scripts/size-stats
index af45000359..3ff2a1ce18 100755
--- a/support/scripts/size-stats
+++ b/support/scripts/size-stats
@@ -178,9 +178,17 @@  def gen_files_csv(filesdict, pkgsizes, outputf):
                      "File size in system (%)"])
         for f, (pkgname, filesize) in filesdict.items():
             pkgsize = pkgsizes[pkgname]
+
+            if pkgsize == 0:
+                percent_pkg = 0
+            else:
+                percent_pkg = float(filesize) / pkgsize * 100
+
+            percent_total = float(filesize) / total * 100
+
             wr.writerow([f, pkgname, filesize, pkgsize,
-                         "%.1f" % (float(filesize) / pkgsize * 100),
-                         "%.1f" % (float(filesize) / total * 100)])
+                         "%.1f" % percent_pkg,
+                         "%.1f" % percent_total])
 
 
 #