Merge remote-tracking branch 'origin/pr/237'

* origin/pr/237:
  progress thresold removed as Marek suggested
  Avoid progress events flooding

Fixes QubesOS/qubes-issues#4406
Fixes QubesOS/qubes-issues#3035
This commit is contained in:
Marek Marczykowski-Górecki 2018-10-29 22:54:01 +01:00
commit fa2429aae4
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -326,6 +326,7 @@ class Backup:
#: callback for progress reporting. Will be called with one argument #: callback for progress reporting. Will be called with one argument
#: - progress in percents #: - progress in percents
self.progress_callback = None self.progress_callback = None
self.last_progress_time = time.time()
#: backup ID, needs to be unique (for a given user), #: backup ID, needs to be unique (for a given user),
#: not necessary unpredictable; automatically generated #: not necessary unpredictable; automatically generated
self.backup_id = datetime.datetime.now().strftime( self.backup_id = datetime.datetime.now().strftime(
@ -521,11 +522,13 @@ class Backup:
if not self.total_backup_bytes: if not self.total_backup_bytes:
return return
if callable(self.progress_callback): if callable(self.progress_callback):
progress = ( if time.time() - self.last_progress_time >= 1: # avoid flooding
100 * (self._done_vms_bytes + self._current_vm_bytes) / progress = (
self.total_backup_bytes) 100 * (self._done_vms_bytes + self._current_vm_bytes) /
# pylint: disable=not-callable self.total_backup_bytes)
self.progress_callback(progress) self.last_progress_time = time.time()
# pylint: disable=not-callable
self.progress_callback(progress)
def _add_vm_progress(self, bytes_done): def _add_vm_progress(self, bytes_done):
self._current_vm_bytes += bytes_done self._current_vm_bytes += bytes_done