From e5d2beafe62c2f654bf39ba6cbfa9a2e7d9c9c8b Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 14 Aug 2015 23:18:19 -0300 Subject: [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. --- client/src/leap/soledad/client/http_target.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'client/src/leap') 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) -- cgit v1.2.3