]> arthur.barton.de Git - bup.git/blobdiff - t/data-size
Compute exact sizes via t/data-size in test-gc.sh
[bup.git] / t / data-size
diff --git a/t/data-size b/t/data-size
new file mode 100755 (executable)
index 0000000..d7da545
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+from os.path import getsize, isdir
+from sys import argv, stderr
+import os
+
+def listdir_failure(ex):
+    raise ex
+
+def usage():
+    print >> stderr, "Usage: data-size PATH ..."
+
+total = 0
+for path in argv[1:]:
+    if isdir(path):
+        for root, dirs, files in os.walk(path, onerror=listdir_failure):
+            total += sum(getsize(os.path.join(root, name)) for name in files)
+    else:
+        total += getsize(path)
+
+print total