Skip to content

Commit 88af7d3

Browse files
yurovskytpetazzoni
authored andcommitted
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 <[email protected]> Acked-by: "Yann E. MORIN" <[email protected]> Signed-off-by: Thomas Petazzoni <[email protected]>
1 parent 86ad37b commit 88af7d3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

support/scripts/size-stats

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,17 @@ def gen_files_csv(filesdict, pkgsizes, outputf):
178178
"File size in system (%)"])
179179
for f, (pkgname, filesize) in filesdict.items():
180180
pkgsize = pkgsizes[pkgname]
181+
182+
if pkgsize == 0:
183+
percent_pkg = 0
184+
else:
185+
percent_pkg = float(filesize) / pkgsize * 100
186+
187+
percent_total = float(filesize) / total * 100
188+
181189
wr.writerow([f, pkgname, filesize, pkgsize,
182-
"%.1f" % (float(filesize) / pkgsize * 100),
183-
"%.1f" % (float(filesize) / total * 100)])
190+
"%.1f" % percent_pkg,
191+
"%.1f" % percent_total])
184192

185193

186194
#

0 commit comments

Comments
 (0)