summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Björklund <anders.f.bjorklund@gmail.com>2022-05-08 13:24:44 +0200
committerGitHub <noreply@github.com>2022-05-08 13:24:44 +0200
commit16c493657671a7bb6b82776f6ad2f5682afdad91 (patch)
tree40e2c29c3544c355b4737971cac62803d9bd158c
parentb4d257467b747c81e111b0d8f5cda9a6dc1055dd (diff)
downloadccache-16c493657671a7bb6b82776f6ad2f5682afdad91.tar.gz
feat: Make upload-redis output more like other tools (#1070)
-rwxr-xr-xmisc/upload-redis29
1 files changed, 20 insertions, 9 deletions
diff --git a/misc/upload-redis b/misc/upload-redis
index ff54603f..1fed79d6 100755
--- a/misc/upload-redis
+++ b/misc/upload-redis
@@ -6,6 +6,9 @@
import redis
import os
+import progress.bar
+import humanize
+
config = os.getenv("REDIS_CONF", "localhost")
if ":" in config:
host, port = config.rsplit(":", 1)
@@ -16,9 +19,8 @@ else:
host, port, sock = config, 6379, None
username = os.getenv("REDIS_USERNAME")
password = os.getenv("REDIS_PASSWORD")
-context = redis.Redis(
- host=host, port=port, unix_socket_path=sock, password=password
-)
+context = redis.Redis(host=host, port=port, unix_socket_path=sock, password=password)
+pipe = context.pipeline(transaction=False)
ccache = os.getenv("CCACHE_DIR", os.path.expanduser("~/.cache/ccache"))
filelist = []
@@ -28,10 +30,16 @@ for dirpath, dirnames, filenames in os.walk(ccache):
if filename.endswith(".lock"):
continue
stat = os.stat(os.path.join(dirpath, filename))
- filelist.append((stat.st_mtime, dirpath, filename))
+ filelist.append((stat.st_mtime, dirpath, filename, stat.st_size))
filelist.sort()
files = result = manifest = objects = 0
-for mtime, dirpath, filename in filelist:
+size = 0
+columns = os.get_terminal_size()[0]
+width = min(columns - 22, 100)
+bar = progress.bar.Bar(
+ "Uploading...", max=len(filelist), fill="=", suffix="%(percent).1f%%", width=width
+)
+for mtime, dirpath, filename, filesize in filelist:
dirname = dirpath.replace(ccache + os.path.sep, "")
if dirname == "tmp":
continue
@@ -48,11 +56,14 @@ for mtime, dirpath, filename in filelist:
key = "ccache:" + "".join(list(os.path.split(dirname)) + [base])
val = open(os.path.join(dirpath, filename), "rb").read() or None
if val:
- print("%s: %s %d" % (key, ext, len(val)))
- context.set(key, val)
+ # print("%s: %s %d" % (key, ext, len(val)))
+ pipe.set(key, val)
objects = objects + 1
files = files + 1
+ size = size + filesize
+ bar.next()
+bar.finish()
print(
- "%d files, %d result (%d manifest) = %d objects"
- % (files, result, manifest, objects)
+ "%d files, %d result (%d manifest) = %d objects (%s)"
+ % (files, result, manifest, objects, humanize.naturalsize(size, binary=True))
)