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

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>
This commit is contained in:
Andrey Yurovsky 2017-11-27 19:37:07 -08:00 committed by Thomas Petazzoni
parent 86ad37b948
commit 88af7d330d

View File

@ -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])
#