you'd like to expose the web server to anyone on your network (dangerous!) you
can omit the bind address to bind to all available interfaces: `:8080`.
+# OPTIONS
+
+--human-readable
+: display human readable file sizes (i.e. 3.9K, 4.7M)
+
# EXAMPLE
$ bup web
display = sub.name + '@'
else:
size = sub.size()
+ size = (opt.human_readable and format_filesize(size)) or size
yield (display, link + url_append, size)
optspec = """
bup web [[hostname]:port]
--
+human-readable display human readable file sizes (i.e. 3.9K, 4.7M)
"""
o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])
import hashlib, heapq, operator, time, grp
from bup import _version, _helpers
import bup._helpers as _helpers
+import math
# This function should really be in helpers, not in bup.options. But we
# want options.py to be standalone so people can include it in other projects.
_resource_path = os.environ.get('BUP_RESOURCE_PATH') or '.'
return os.path.join(_resource_path, subdir)
+def format_filesize(size):
+ unit = 1024.0
+ size = float(size)
+ if size < unit:
+ return "%d" % (size)
+ exponent = int(math.log(size) / math.log(unit))
+ size_prefix = "KMGTPE"[exponent - 1]
+ return "%.1f%s" % (size / math.pow(unit, exponent), size_prefix)
+
class NotOk(Exception):
pass