Show size of database file next to download link, closes #172

This commit is contained in:
Simon Willison 2019-02-05 20:53:44 -08:00
commit 4462a5ab28
7 changed files with 37 additions and 1 deletions

View file

@ -901,3 +901,15 @@ class StaticMount(click.ParamType):
if not os.path.exists(dirpath) or not os.path.isdir(dirpath):
self.fail("%s is not a valid directory path" % value, param, ctx)
return path, dirpath
def format_bytes(bytes):
current = float(bytes)
for unit in ("bytes", "KB", "MB", "GB", "TB"):
if current < 1024:
break
current = current / 1024
if unit == "bytes":
return "{} {}".format(int(current), unit)
else:
return "{:.1f} {}".format(current, unit)