summaryrefslogtreecommitdiff
path: root/client/src/leap/soledad
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-11-26 22:13:34 -0400
committerKali Kaneko <kali@leap.se>2015-12-15 15:19:41 -0400
commit869aa5354ff74be9e0203c37c5d54c79d8e32863 (patch)
tree71ab98710a249f7337b6e7213d3bb0fac078cf27 /client/src/leap/soledad
parentdef5b89e6066335708b93b1dda1e65aaca8598ac (diff)
[feat] set syncable attribute
this allows to switch the online/offline mode on a running soledad instance.
Diffstat (limited to 'client/src/leap/soledad')
-rw-r--r--client/src/leap/soledad/client/api.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/client/src/leap/soledad/client/api.py b/client/src/leap/soledad/client/api.py
index 619671fd..78f9c652 100644
--- a/client/src/leap/soledad/client/api.py
+++ b/client/src/leap/soledad/client/api.py
@@ -187,6 +187,7 @@ class Soledad(object):
self._defer_encryption = defer_encryption
self._secrets_path = None
self._sync_enc_pool = None
+ self._dbsyncer = None
self.shared_db = shared_db
@@ -217,6 +218,7 @@ class Soledad(object):
#
# initialization/destruction methods
#
+
def _init_config_with_defaults(self):
"""
Initialize configuration using default values for missing params.
@@ -658,6 +660,21 @@ class Soledad(object):
# ISyncableStorage
#
+ def set_syncable(self, syncable):
+ """
+ Toggle the syncable state for this database.
+
+ This can be used to start a database with offline state and switch it
+ online afterwards. Or the opposite: stop syncs when connection is lost.
+
+ :param syncable: new status for syncable.
+ :type syncable: bool
+ """
+ # TODO should check that we've got a token!
+ self.shared_db.syncable = syncable
+ if syncable and not self._dbsyncer:
+ self._init_u1db_syncer()
+
def sync(self, defer_decryption=True):
"""
Synchronize documents with the server replica.
@@ -754,6 +771,14 @@ class Soledad(object):
"""
return self.sync_lock.locked
+ @property
+ def syncable(self):
+ if self.shared_db:
+ return self.shared_db.syncable
+ else:
+ return False
+
+
def _set_token(self, token):
"""
Set the authentication token for remote database access.