summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-08-14 23:18:19 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-08-26 17:20:21 -0300
commite5d2beafe62c2f654bf39ba6cbfa9a2e7d9c9c8b (patch)
tree174619fddf7c154c0e02d80451a7635ab572bfaf /client
parentfd6c054bf11deba4ca5680cc406db7d4ce98d58d (diff)
[refactor] extract logging and emitting on target
Creating a message, emitting an event and logging afterwards is a single operation outside of of those method's responsabilities.
Diffstat (limited to 'client')
-rw-r--r--client/src/leap/soledad/client/http_target.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/client/src/leap/soledad/client/http_target.py b/client/src/leap/soledad/client/http_target.py
index a6ef2b0d..c9670711 100644
--- a/client/src/leap/soledad/client/http_target.py
+++ b/client/src/leap/soledad/client/http_target.py
@@ -418,12 +418,7 @@ class SoledadHTTPSyncTarget(SyncTarget):
if self._defer_encryption:
self._sync_enc_pool.delete_encrypted_doc(
doc.doc_id, doc.rev)
-
- msg = "%d/%d" % (idx, total)
- content = {'sent': idx, 'total': total}
- emit(SOLEDAD_SYNC_SEND_STATUS, content)
- logger.debug("Sync send status: %s" % msg)
-
+ _emit_send(idx, total)
response_dict = json.loads(result)[0]
gen_after_send = response_dict['new_generation']
trans_id_after_send = response_dict['new_transaction_id']
@@ -619,10 +614,7 @@ class SoledadHTTPSyncTarget(SyncTarget):
# end of symmetric decryption
# -------------------------------------------------------------
self._received_docs += 1
- msg = "%d/%d" % (self._received_docs, total)
- content = {'received': self._received_docs, 'total': total}
- emit(SOLEDAD_SYNC_RECEIVE_STATUS, content)
- logger.debug("Sync receive status: %s" % msg)
+ _emit_received(self._received_docs, total)
return number_of_changes, new_generation, new_transaction_id
def _parse_received_doc_response(self, response):
@@ -709,3 +701,17 @@ def _unauth_to_invalid_token_error(failure):
if failure.getErrorMessage() == "401 Unauthorized":
raise InvalidAuthTokenError
return failure
+
+
+def _emit_send(idx, total):
+ msg = "%d/%d" % (idx, total)
+ emit(
+ SOLEDAD_SYNC_SEND_STATUS,
+ "Soledad sync send status: %s" % msg)
+ logger.debug("Sync send status: %s" % msg)
+
+
+def _emit_received(received_docs, total):
+ msg = "%d/%d" % (received_docs, total)
+ emit(SOLEDAD_SYNC_RECEIVE_STATUS, msg)
+ logger.debug("Sync receive status: %s" % msg)