aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-06-10 08:06:47 +0300
committerFrederick Muriuki Muriithi2022-06-10 08:06:47 +0300
commit557d1d5c19ab518fa7abb3229c6d9042867e6c00 (patch)
tree97b2ca39fe49600da74dbfa9ca358fa97f114a92 /scripts
parent35a9cf67a9e055925f11a12c9fb964e5dbeb5525 (diff)
downloadgn-uploader-557d1d5c19ab518fa7abb3229c6d9042867e6c00.tar.gz
Enable upload of zipfiles
Diffstat (limited to 'scripts')
-rw-r--r--scripts/worker.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/scripts/worker.py b/scripts/worker.py
index 0ef5ae5..ecdfaa2 100644
--- a/scripts/worker.py
+++ b/scripts/worker.py
@@ -1,6 +1,7 @@
import os
import sys
from typing import Callable
+from zipfile import Path, ZipFile, is_zipfile
import jsonpickle
from redis import Redis
@@ -64,6 +65,10 @@ def make_user_aborted(redis_conn, job_id):
return user_aborted
return __aborted__
+def get_zipfile_size(filepath):
+ with ZipFile(filepath, "r") as zfile:
+ return zfile.infolist()[0].file_size
+
def main():
args = process_cli_arguments()
if args is None:
@@ -72,7 +77,8 @@ def main():
with Redis.from_url(args.redisurl) as redis_conn:
progress_calculator = make_progress_calculator(
- os.stat(args.filepath).st_size)
+ get_zipfile_size(args.filepath) if is_zipfile(args.filepath)
+ else os.stat(args.filepath).st_size)
progress_indicator = make_progress_indicator(
redis_conn, args.job_id, progress_calculator)
count = args.count