comparison src/memory/params.py @ 1836:fb94f92dc740

core (params): return given profile for ProfileUnknownError
author Goffi <goffi@goffi.org>
date Mon, 25 Jan 2016 17:03:45 +0100
parents d17772b0fe22
children 2c55e7e99ef3
comparison
equal deleted inserted replaced
1835:5b8a859d5bb4 1836:fb94f92dc740
188 To be used for direct calls only (not through the bridge). 188 To be used for direct calls only (not through the bridge).
189 @return: a Deferred instance 189 @return: a Deferred instance
190 """ 190 """
191 if not self.storage.hasProfile(profile): 191 if not self.storage.hasProfile(profile):
192 log.info(_('Trying to delete an unknown profile')) 192 log.info(_('Trying to delete an unknown profile'))
193 return defer.fail(Failure(exceptions.ProfileUnknownError)) 193 return defer.fail(Failure(exceptions.ProfileUnknownError(profile)))
194 if self.host.isConnected(profile): 194 if self.host.isConnected(profile):
195 if force: 195 if force:
196 self.host.disconnect(profile) 196 self.host.disconnect(profile)
197 else: 197 else:
198 log.info(_("Trying to delete a connected profile")) 198 log.info(_("Trying to delete a connected profile"))
216 log.info(_('No default profile, returning first one')) 216 log.info(_('No default profile, returning first one'))
217 try: 217 try:
218 default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0] 218 default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0]
219 except IndexError: 219 except IndexError:
220 log.info(_('No profile exist yet')) 220 log.info(_('No profile exist yet'))
221 raise exceptions.ProfileUnknownError 221 raise exceptions.ProfileUnknownError(profile_key)
222 return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists 222 return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists
223 elif profile_key == C.PROF_KEY_NONE: 223 elif profile_key == C.PROF_KEY_NONE:
224 raise exceptions.ProfileNotSetError 224 raise exceptions.ProfileNotSetError
225 elif return_profile_keys and profile_key in [C.PROF_KEY_ALL]: 225 elif return_profile_keys and profile_key in [C.PROF_KEY_ALL]:
226 return profile_key # this value must be managed by the caller 226 return profile_key # this value must be managed by the caller
227 if not self.storage.hasProfile(profile_key): 227 if not self.storage.hasProfile(profile_key):
228 log.error(_(u'Trying to access an unknown profile (%s)') % profile_key) 228 log.error(_(u'Trying to access an unknown profile (%s)') % profile_key)
229 raise exceptions.ProfileUnknownError 229 raise exceptions.ProfileUnknownError(profile_key)
230 return profile_key 230 return profile_key
231 231
232 def __get_unique_node(self, parent, tag, name): 232 def __get_unique_node(self, parent, tag, name):
233 """return node with given tag 233 """return node with given tag
234 234
433 param_cat = node.parentNode.getAttribute('name') 433 param_cat = node.parentNode.getAttribute('name')
434 param_name = node.getAttribute('name') 434 param_name = node.getAttribute('name')
435 if ((param_cat, param_name) == C.PROFILE_PASS_PATH) or not value: 435 if ((param_cat, param_name) == C.PROFILE_PASS_PATH) or not value:
436 return defer.succeed(value) # profile password and empty passwords are returned "as is" 436 return defer.succeed(value) # profile password and empty passwords are returned "as is"
437 if not profile: 437 if not profile:
438 raise exceptions.ProfileUnknownError('The profile is needed to decrypt a password') 438 raise exceptions.ProfileNotSetError('The profile is needed to decrypt a password')
439 d = self.host.memory.decryptValue(value, profile) 439 d = self.host.memory.decryptValue(value, profile)
440 440
441 def gotPlainPassword(password): 441 def gotPlainPassword(password):
442 if password is None: # empty value means empty password, None means decryption failure 442 if password is None: # empty value means empty password, None means decryption failure
443 raise exceptions.InternalError(_('The stored password could not be decrypted!')) 443 raise exceptions.InternalError(_('The stored password could not be decrypted!'))
489 assert node[0] == C.INDIVIDUAL 489 assert node[0] == C.INDIVIDUAL
490 490
491 profile = self.getProfileName(profile_key) 491 profile = self.getProfileName(profile_key)
492 if not profile: 492 if not profile:
493 log.error(_('Requesting a param for an non-existant profile')) 493 log.error(_('Requesting a param for an non-existant profile'))
494 raise exceptions.ProfileUnknownError 494 raise exceptions.ProfileUnknownError(profile_key)
495 495
496 if profile not in self.params: 496 if profile not in self.params:
497 log.error(_('Requesting synchronous param for not connected profile')) 497 log.error(_('Requesting synchronous param for not connected profile'))
498 raise exceptions.ProfileNotConnected(profile) 498 raise exceptions.ProfileNotConnected(profile)
499 499
812 # FIXME: setParam should accept the right type for value, not only str ! 812 # FIXME: setParam should accept the right type for value, not only str !
813 if profile_key != C.PROF_KEY_NONE: 813 if profile_key != C.PROF_KEY_NONE:
814 profile = self.getProfileName(profile_key) 814 profile = self.getProfileName(profile_key)
815 if not profile: 815 if not profile:
816 log.error(_(u'Trying to set parameter for an unknown profile')) 816 log.error(_(u'Trying to set parameter for an unknown profile'))
817 raise exceptions.ProfileUnknownError 817 raise exceptions.ProfileUnknownError(profile_key)
818 818
819 node = self._getParamNode(name, category, '@ALL@') 819 node = self._getParamNode(name, category, '@ALL@')
820 if not node: 820 if not node:
821 log.error(_(u'Requesting an unknown parameter (%(category)s/%(name)s)') 821 log.error(_(u'Requesting an unknown parameter (%(category)s/%(name)s)')
822 % {'category': category, 'name': name}) 822 % {'category': category, 'name': name})