support/scripts/size-stats: avoid divide-by-zero
authorAndrey Yurovsky <yurovsky@gmail.com>
Tue, 28 Nov 2017 03:37:07 +0000 (19:37 -0800)
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Wed, 29 Nov 2017 20:36:34 +0000 (21:36 +0100)
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>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
support/scripts/size-stats

index af450003593661ac50fe15b2c978d548b607eb56..3ff2a1ce18faad223754349346ddf71b6f740e81 100755 (executable)
@@ -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])
 
 
 #