class Config:
+ iec = False
size_limit = 0.01
colors = ['#e60004', '#009836', '#2e1d86', '#ffed00',
'#0068b5', '#f28e00', '#940084', '#97c000']
#
def draw_graph(pkgsize, outputf):
def size2string(sz):
- divider = 1000.0
- prefixes = ['', 'k', 'M', 'G', 'T']
+ if Config.iec:
+ divider = 1024.0
+ prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti']
+ else:
+ divider = 1000.0
+ prefixes = ['', 'k', 'M', 'G', 'T']
while sz > divider and len(prefixes) > 1:
prefixes = prefixes[1:]
sz = sz/divider
wr.writerow([pkg, size, "%.1f" % (float(size) / total * 100)])
+#
+# Our special action for --iec, --binary, --si, --decimal
+#
+class PrefixAction(argparse.Action):
+ def __init__(self, option_strings, dest, **kwargs):
+ for key in ["type", "nargs"]:
+ if key in kwargs:
+ raise ValueError('"{}" not allowed'.format(key))
+ super(PrefixAction, self).__init__(option_strings, dest, nargs=0,
+ type=bool, **kwargs)
+
+ def __call__(self, parser, namespace, values, option_string=None):
+ setattr(namespace, self.dest, option_string in ["--iec", "--binary"])
+
+
def main():
parser = argparse.ArgumentParser(description='Draw size statistics graphs')
help="CSV output file with file size statistics")
parser.add_argument("--package-size-csv", '-p', metavar="PKG_SIZE_CSV",
help="CSV output file with package size statistics")
+ parser.add_argument("--iec", "--binary", "--si", "--decimal",
+ action=PrefixAction,
+ help="Use IEC (binary, powers of 1024) or SI (decimal, "
+ "powers of 1000, the default) prefixes")
parser.add_argument("--size-limit", "-l", type=float,
help='Under this size ratio, files are accounted to ' +
'the generic "Other" package. Default: 0.01 (1%%)')
args = parser.parse_args()
+ Config.iec = args.iec
if args.size_limit is not None:
if args.size_limit < 0.0 or args.size_limit > 1.0:
parser.error("--size-limit must be in [0.0..1.0]")