aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageia.org>2024-01-27 11:15:56 +0100
committerPapoteur <papoteur@mageia.org>2024-01-27 11:15:56 +0100
commit30172e7e9bdc6cb0404a6b611fe9bbab5101e44a (patch)
tree3145ef48e818adcf4256c77ec065f942aac285b2
parent9ed7d2f462b94e37fb3bb52e33ac37b0232292bc (diff)
downloadmgarepo-30172e7e9bdc6cb0404a6b611fe9bbab5101e44a.tar
mgarepo-30172e7e9bdc6cb0404a6b611fe9bbab5101e44a.tar.gz
mgarepo-30172e7e9bdc6cb0404a6b611fe9bbab5101e44a.tar.bz2
mgarepo-30172e7e9bdc6cb0404a6b611fe9bbab5101e44a.tar.xz
mgarepo-30172e7e9bdc6cb0404a6b611fe9bbab5101e44a.zip
Add a progress bar when uploading a binary filetopic/progress
-rw-r--r--MgaRepo/binrepo.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/MgaRepo/binrepo.py b/MgaRepo/binrepo.py
index 874a091..d96507c 100644
--- a/MgaRepo/binrepo.py
+++ b/MgaRepo/binrepo.py
@@ -2,6 +2,7 @@ from MgaRepo import Error, config, mirror, layout
from MgaRepo.util import execcmd, rellink, get_helper
from MgaRepo.svn import SVN
+from tqdm import tqdm
import sys
import os
import string
@@ -11,8 +12,8 @@ import re
import tempfile
import hashlib
import urllib.parse
-import threading
import httplib2
+import subprocess
from io import StringIO
@@ -101,13 +102,31 @@ def upload_binary(topdir, filename):
if binary_exists(sha1sum):
return
host = config.get("binrepo", "upload_host")
+ # upload_bin_helper by default: /usr/local/bin/wrapper.upload-bin
upload_bin_helper = get_helper("upload-bin")
- command = "ssh %s %s %s" % (host, upload_bin_helper, filename)
+ command = ["ssh", host, upload_bin_helper, filename]
try:
- filein = open(filepath, 'r')
+ b = os.path.getsize(filepath)
except Error as e:
raise Error("Could not open file %s\n" % filepath)
- status, output = execcmd(command, show=True, geterr=True, stdin=filein)
+ with open(filepath, "rb") as f:
+ # file is sent chunk by chunk to allow displaying of a progress bar
+ bs = 4096 * 128
+ written = 0
+ ncuts = int(b / bs)
+ pbar = tqdm(total=b, unit='B', unit_scale=True, unit_divisor=1024, desc=filename)
+ while ncuts <= 100:
+ bs = int(bs / 2)
+ ncuts = int(b / bs)
+ p = subprocess.Popen(command, stdin=subprocess.PIPE)
+ for i in range(0, int(ncuts) + 1):
+ buf = f.read(bs)
+ p.stdin.write(buf)
+ written += len(buf)
+ pbar.update(len(buf))
+ p.stdin.flush()
+ pbar.close()
+ p.communicate()
def import_binaries(topdir, pkgname):
"""Import all binaries from a given package checkout