From 869aa5354ff74be9e0203c37c5d54c79d8e32863 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 26 Nov 2015 22:13:34 -0400 Subject: [feat] set syncable attribute this allows to switch the online/offline mode on a running soledad instance. --- client/src/leap/soledad/client/api.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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. -- cgit v1.2.3