def _handle_message_SYNC_FILES_LIST(self, message): """Received the remote filelist from the server. Compute differences, perform integrity checks on it and ask the user confirmation to proceed with the synchronization. Message: SYNC_FILES_LIST Parameters: last_commit_client_id: String or None last_commit_client_hostname: String or None last_commit_client_platform: String or None last_commit_timestamp: Number used_space: Number basis: String user_quota: Number optional parameters: plan: a dictionary as follows (mandatory) { id: <plan_id>, # a number space: <plan_space_in_GB>, # a number (within a plan this is mandatory and 'not None') price: <price_in_$>, # a number (if absent or ==None it means "free") payment_type: <(SINGLE|SUBSCRIPTION)>, # unicode (present if price is not None) payment_recurrence: <(MONTHLY|YEARLY)> # unicode (present if price is not None) } expires_on: <GMT-Date-or-None> # a number representing a unix timestamp UTC (mandatory) (it might None if plan is "forever", this is the expiration date of the subscription, it does not change when in grace time). status: <(TRIAL|ACTIVE|GRACE|SUSPENDED|MAINTAINANCE)> # unicode (mandatory) """ storage_content = message.getParameter('dataset') self.storage_content = storage_content self._validate_storage_content(storage_content) self.server_basis = message.getParameter('basis') self.candidate_basis = self._try_load_candidate_basis() self.client_basis = self._load_trusted_basis() fields = [ 'last_commit_client_id', 'last_commit_client_hostname', 'last_commit_client_platform', 'last_commit_timestamp', 'used_space', 'user_quota', 'plan', 'status', 'expires_on' ] info = dict(map(lambda f: (f, message.getParameter(f)), fields)) # trial # info.update(status='ACTIVE_TRIAL', # expires_on=1366814411, # plan=dict( # space=1 # ) # ) # beta # info.update(status='ACTIVE_BETA', # expires_on=None, # plan=dict( # space=3 # ) # ) # expired # info.update(status='ACTIVE_GRACE', # expires_on=1366810000, # plan=dict( # space=1, # payment_type='SUBSCRIPTION', # payment_recurrence='MONTHLY' # ) # ) # good yearly # info.update(status='ACTIVE_PAID', # expires_on=1366810000, # plan=dict( # space=1, # payment_type='SUBSCRIPTION', # payment_recurrence='YEARLY' # ) # ) self._context._ui_controller.update_session_info(info) # No blacklisted pathname should be found on the storage. If any, tell # the user and then shut down the application. remote_pathnames = [entry['key'] for entry in storage_content] blacklisted = filter(lambda x: self._context.warebox.is_blacklisted(x), remote_pathnames) if len(blacklisted) > 0: self.logger.critical( 'The following blacklisted pathnames have been found on the ' 'storage %s' % format_to_log(blacklisted)) self._context._ui_controller.ask_for_user_input( 'blacklisted_pathname_on_storage', blacklisted) # self._internal_facade.terminate() self._context._internal_facade.pause() return # Detect actions to be taken for synchronization as well as conflicts self.logger.debug(u"Starting computing the three-way diff...") try: self._context.startup_synchronization.prepare( storage_content, self._context.must_die) except ExecutionInterrupted: self.logger.debug(u'ExecutionInterrupted, terminating...') self._set_next_state(StateRegister.get('DisconnectedState')) return self.logger.debug(u"Finished computing the three-way diff.") # Conflicts on encrypted files need extra data from the server to be # solved. If there are any, handle them. encrypted_pathnames = CryptoUtils.filter_encrypted_pathname( self._context.startup_synchronization.edit_conflicts) if len(encrypted_pathnames) > 0: self.logger.debug(u'Encrypted file in conflict: %r' % encrypted_pathnames) message = SYNC_GET_ENCRYPTED_FILES_IVS( 'SYNC_GET_ENCRYPTED_FILES_IVS', {'requested_files_list': encrypted_pathnames}) self._context.output_message_queue.put(message) return # If there are no conflicts on encrypted files, just proceed normally. try: if self._check_hash_mismatch(): self._start_syncing() else: # self._internal_facade.terminate() self._context._internal_facade.pause() except HashMismatchException as excp: self.logger.critical('Integrity error %s' % excp) self._set_next_state(StateRegister.get('IntegrityErrorState'))
def _handle_message_SYNC_FILES_LIST(self, message): """Received the remote filelist from the server. Compute differences, perform integrity checks on it and ask the user confirmation to proceed with the synchronization. Message: SYNC_FILES_LIST Parameters: last_commit_client_id: String or None last_commit_client_hostname: String or None last_commit_client_platform: String or None last_commit_timestamp: Number used_space: Number basis: String user_quota: Number """ storage_content = message.getParameter('dataset') self.storage_content = storage_content self._validate_storage_content(storage_content) self.server_basis = message.getParameter('basis') self.candidate_basis = self._context._try_load_candidate_basis() self.client_basis = self._context._load_trusted_basis() fields = [ 'last_commit_client_id', 'last_commit_client_hostname', 'last_commit_client_platform', 'last_commit_timestamp', 'used_space', 'user_quota' ] info = dict(map(lambda f: (f, message.getParameter(f)), fields)) self._context._ui_controller.update_session_info(info) # No blacklisted pathname should be found on the storage. If any, tell # the user and then shut down the application. remote_pathnames = [entry['key'] for entry in storage_content] blacklisted = filter( lambda x: self._context.warebox.is_blacklisted(x), remote_pathnames) if len(blacklisted) > 0: self.logger.critical( 'The following blacklisted pathnames have been found on the ' 'storage %s' % format_to_log(blacklisted)) self._context._ui_controller.ask_for_user_input( 'blacklisted_pathname_on_storage', blacklisted) # self._internal_facade.terminate() self._context._internal_facade.pause() return # Detect actions to be taken for synchronization as well as conflicts self.logger.debug(u"Starting computing the three-way diff...") self._context.startup_synchronization.prepare(storage_content) self.logger.debug(u"Finished computing the three-way diff.") # Conflicts on encrypted files need extra data from the server to be # solved. If there are any, handle them. encrypted_pathnames = CryptoUtils.filter_encrypted_pathname( self._context.startup_synchronization.edit_conflicts) if len(encrypted_pathnames) > 0: self.logger.debug( u'Encrypted file in conflict: %r' % encrypted_pathnames) message = SYNC_GET_ENCRYPTED_FILES_IVS( 'SYNC_GET_ENCRYPTED_FILES_IVS', {'requested_files_list': encrypted_pathnames}) self._context.output_message_queue.put(message) return # If there are no conflicts on encrypted files, just proceed normally. try: if self._check_hash_mismatch(): self._start_syncing() else: # self._internal_facade.terminate() self._context._internal_facade.pause() except HashMismatchException as excp: self.logger.critical('BASISMISMATCH %s' % excp) self._set_next_state(StateRegister.get('BasisMismatchState'))
def _handle_message_SYNC_FILES_LIST(self, message): """Received the remote filelist from the server. Compute differences, perform integrity checks on it and ask the user confirmation to proceed with the synchronization. Message: SYNC_FILES_LIST Parameters: last_commit_client_id: String or None last_commit_client_hostname: String or None last_commit_client_platform: String or None last_commit_timestamp: Number used_space: Number basis: String user_quota: Number optional parameters: plan: a dictionary as follows (mandatory) { id: <plan_id>, # a number space: <plan_space_in_GB>, # a number (within a plan this is mandatory and 'not None') price: <price_in_$>, # a number (if absent or ==None it means "free") payment_type: <(SINGLE|SUBSCRIPTION)>, # unicode (present if price is not None) payment_recurrence: <(MONTHLY|YEARLY)> # unicode (present if price is not None) } expires_on: <GMT-Date-or-None> # a number representing a unix timestamp UTC (mandatory) (it might None if plan is "forever", this is the expiration date of the subscription, it does not change when in grace time). status: <(TRIAL|ACTIVE|GRACE|SUSPENDED|MAINTAINANCE)> # unicode (mandatory) """ storage_content = message.getParameter('dataset') self.storage_content = storage_content self._validate_storage_content(storage_content) self.server_basis = message.getParameter('basis') self.candidate_basis = self._try_load_candidate_basis() self.client_basis = self._load_trusted_basis() fields = [ 'last_commit_client_id', 'last_commit_client_hostname', 'last_commit_client_platform', 'last_commit_timestamp', 'used_space', 'user_quota', 'plan', 'status', 'expires_on' ] info = dict(map(lambda f: (f, message.getParameter(f)), fields)) # trial # info.update(status='ACTIVE_TRIAL', # expires_on=1366814411, # plan=dict( # space=1 # ) # ) # beta # info.update(status='ACTIVE_BETA', # expires_on=None, # plan=dict( # space=3 # ) # ) # expired # info.update(status='ACTIVE_GRACE', # expires_on=1366810000, # plan=dict( # space=1, # payment_type='SUBSCRIPTION', # payment_recurrence='MONTHLY' # ) # ) # good yearly # info.update(status='ACTIVE_PAID', # expires_on=1366810000, # plan=dict( # space=1, # payment_type='SUBSCRIPTION', # payment_recurrence='YEARLY' # ) # ) self._context._ui_controller.update_session_info(info) # No blacklisted pathname should be found on the storage. If any, tell # the user and then shut down the application. remote_pathnames = [entry['key'] for entry in storage_content] blacklisted = filter( lambda x: self._context.warebox.is_blacklisted(x), remote_pathnames) if len(blacklisted) > 0: self.logger.critical( 'The following blacklisted pathnames have been found on the ' 'storage %s' % format_to_log(blacklisted)) self._context._ui_controller.ask_for_user_input( 'blacklisted_pathname_on_storage', blacklisted) # self._internal_facade.terminate() self._context._internal_facade.pause() return # Detect actions to be taken for synchronization as well as conflicts self.logger.debug(u"Starting computing the three-way diff...") try: self._context.startup_synchronization.prepare( storage_content, self._context.must_die) except ExecutionInterrupted: self.logger.debug(u'ExecutionInterrupted, terminating...') self._set_next_state(StateRegister.get('DisconnectedState')) return self.logger.debug(u"Finished computing the three-way diff.") # Conflicts on encrypted files need extra data from the server to be # solved. If there are any, handle them. encrypted_pathnames = CryptoUtils.filter_encrypted_pathname( self._context.startup_synchronization.edit_conflicts) if len(encrypted_pathnames) > 0: self.logger.debug( u'Encrypted file in conflict: %r' % encrypted_pathnames) message = SYNC_GET_ENCRYPTED_FILES_IVS( 'SYNC_GET_ENCRYPTED_FILES_IVS', {'requested_files_list': encrypted_pathnames}) self._context.output_message_queue.put(message) return # If there are no conflicts on encrypted files, just proceed normally. try: if self._check_hash_mismatch(): self._start_syncing() else: # self._internal_facade.terminate() self._context._internal_facade.pause() except HashMismatchException as excp: self.logger.critical('Integrity error %s' % excp) self._set_next_state(StateRegister.get('IntegrityErrorState'))