import transport
from pakfire.constants import *
+from pakfire.i18n import _
import logging
log = logging.getLogger("pakfire.client")
upload_id = self.conn.upload_create(os.path.basename(filename),
size, hash)
+ # Make a nice progressbar.
+ pb = pakfire.util.make_progress(os.path.basename(filename), size, speed=True, eta=True)
+
try:
# Calculate the number of chunks.
chunks = (size // CHUNK_SIZE) + 1
+ transferred = 0
# Cut the file in pieces and upload them one after another.
with open(filename) as f:
break
chunk += 1
- log.info("Uploading chunk %s/%s of %s." % (chunk, chunks,
- os.path.basename(filename)))
+ if pb:
+ transferred += len(data)
+ pb.update(transferred)
data = xmlrpclib.Binary(data)
self.conn.upload_chunk(upload_id, data)
raise
+ finally:
+ if pb:
+ pb.finish()
+
# If the server sends false, something happened with the upload that
# could not be recovered.
- if ret:
- logging.info("Upload of %s succeeded." % filename)
- else:
+ if not ret:
logging.error("Upload of %s was not successful." % filename)
raise Exception, "Upload failed."
bar = (self.left + (m*marked_width).ljust(cwidth) + self.right)
return bar
-def make_progress(message, maxval, eta=True):
+def make_progress(message, maxval, eta=True, speed=False):
# Return nothing if stdout is not a terminal.
if not sys.stdout.isatty():
return
" ",
]
+ if speed:
+ widgets += [
+ progressbar.Percentage(), " ",
+ progressbar.FileTransferSpeed(), " "
+ ]
+
if eta:
widgets += [progressbar.ETA(), " ",]