Commit 243da606 authored by Sandro Tosi's avatar Sandro Tosi

add a progressbar to sftp uploader

parent 75b10306
......@@ -27,6 +27,8 @@ import os
import pwd
import os.path
from binascii import hexlify
import progressbar
import functools
from dput.core import logger
from dput.uploader import AbstractUploader
......@@ -268,6 +270,10 @@ class SFTPUploader(AbstractUploader):
repr(e)
))
def progressbar(self, pbar, transferred, toBeTransferred):
pbar.maxval = toBeTransferred
pbar.update(transferred)
def upload_file(self, filename, upload_filename=None):
"""
See :meth:`dput.uploader.AbstractUploader.upload_file`
......@@ -280,7 +286,9 @@ class SFTPUploader(AbstractUploader):
logger.debug("Writing to: %s" % (upload_filename))
try:
self._sftp.put(filename, upload_filename, **self.putargs)
self.pbar = progressbar.ProgressBar(widgets=[progressbar.Percentage()]).start()
self._sftp.put(filename, upload_filename, callback=functools.partial(self.progressbar, self.pbar), **self.putargs)
self.pbar.finish()
except IOError as e:
if e.errno == os.errno.EACCES:
self.upload_write_error(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment