mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Show size of database file next to download link, closes #172
This commit is contained in:
parent
195a5b3634
commit
4462a5ab28
7 changed files with 37 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue