summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-10-31 06:15:06 -0300
committerVictor Shyba <victor1984@riseup.net>2017-10-31 06:15:06 -0300
commitc8234da89b198064f1d1f14bec6811c0883e705c (patch)
tree78fbf8fbb0ca149897acf2cfb6c5b4c753cd9cf5
parent72956174187fa2fccbb060d04d4809797657e029 (diff)
[feature] add sync progress attribute
--Resolves: #8848
-rw-r--r--src/leap/soledad/client/_db/blobs/sql.py14
-rw-r--r--src/leap/soledad/client/_db/blobs/sync.py4
-rw-r--r--tests/blobs/test_blob_manager.py16
3 files changed, 34 insertions, 0 deletions
diff --git a/src/leap/soledad/client/_db/blobs/sql.py b/src/leap/soledad/client/_db/blobs/sql.py
index 72fc250b..e81580a7 100644
--- a/src/leap/soledad/client/_db/blobs/sql.py
+++ b/src/leap/soledad/client/_db/blobs/sql.py
@@ -105,6 +105,20 @@ class SQLiteBlobBackend(object):
defer.returnValue((result[0][0], result[0][1]))
@defer.inlineCallbacks
+ def get_sync_progress(self):
+ query = 'SELECT sync_status, COUNT(sync_status) FROM sync_state'
+ query += ' GROUP BY sync_status'
+
+ def by_value(value):
+ statuses = SyncStatus.__dict__.items()
+ return filter(lambda x: x[1] == value, statuses)[0][0]
+ result = yield self.dbpool.runQuery(query)
+ if result:
+ defer.returnValue(dict([(by_value(r[0]), r[1]) for r in result]))
+ else:
+ defer.returnValue([])
+
+ @defer.inlineCallbacks
def list(self, namespace=''):
query = 'select blob_id from blobs where namespace = ?'
values = (namespace,)
diff --git a/src/leap/soledad/client/_db/blobs/sync.py b/src/leap/soledad/client/_db/blobs/sync.py
index ee10443d..d47033b2 100644
--- a/src/leap/soledad/client/_db/blobs/sync.py
+++ b/src/leap/soledad/client/_db/blobs/sync.py
@@ -126,3 +126,7 @@ class BlobsSynchronizer(object):
yield self.send_missing(namespace)
except defer.FirstError as e:
e.subFailure.raiseException()
+
+ @property
+ def sync_progress(self):
+ return self.local.get_sync_progress()
diff --git a/tests/blobs/test_blob_manager.py b/tests/blobs/test_blob_manager.py
index f1872ab1..d36b3cda 100644
--- a/tests/blobs/test_blob_manager.py
+++ b/tests/blobs/test_blob_manager.py
@@ -128,6 +128,22 @@ class BlobManagerTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
+ def test_sync_progress(self):
+ deferreds = []
+ local = self.manager.local
+ pending_download = SyncStatus.PENDING_DOWNLOAD
+ pending_upload = SyncStatus.PENDING_UPLOAD
+ synced = SyncStatus.SYNCED
+ for status in [pending_download, pending_upload, synced, synced]:
+ deferreds.append(local.update_sync_status(uuid4().hex, status))
+ yield defer.gatherResults(deferreds)
+
+ progress = yield self.manager.sync_progress
+ self.assertEquals(progress, {
+ 'PENDING_DOWNLOAD': 1, 'PENDING_UPLOAD': 1, 'SYNCED': 2})
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
def test_duplicated_blob_error_on_put(self):
self.manager._encrypt_and_upload = Mock(return_value=None)
content, existing_id = "Blob content", uuid4().hex