comparison src/core/sat_main.py @ 1624:7e749e8eefd0

core: fixed launchAction: - getClient now raise a NotFound error if client is not available - errors ConnectedProfileError, NotConnectedProfileError anf ProfileKeyUnknownError renamed for consistency (all profile error must prefixed by Profile) - launchAction fixed, the case where client is not available is handled - kept actions are actuall1y removed on launchAction
author Goffi <goffi@goffi.org>
date Wed, 18 Nov 2015 11:06:24 +0100
parents 5b24d6bf5d15
children 63cef4dbf2a4
comparison
equal deleted inserted replaced
1623:ec48b35309dc 1624:7e749e8eefd0
453 return (None, None) 453 return (None, None)
454 return (self.profiles[profile].jid, self.profiles[profile].xmlstream) 454 return (self.profiles[profile].jid, self.profiles[profile].xmlstream)
455 455
456 def getClient(self, profile_key): 456 def getClient(self, profile_key):
457 """Convenient method to get client from profile key 457 """Convenient method to get client from profile key
458 @return: client or None if it doesn't exist""" 458
459 @return: client or None if it doesn't exist
460 @raise exceptions.ProfileKeyUnknown: the profile or profile key doesn't exist
461 @raise exceptions.NotFound: client is not available
462 This happen if profile has not been use yet
463 """
459 profile = self.memory.getProfileName(profile_key) 464 profile = self.memory.getProfileName(profile_key)
460 if not profile: 465 if not profile:
461 raise exceptions.ProfileKeyUnknownError 466 raise exceptions.ProfileKeyUnknown
462 return self.profiles[profile] 467 try:
468 return self.profiles[profile]
469 except KeyError:
470 raise exceptions.NotFound
463 471
464 def getClients(self, profile_key): 472 def getClients(self, profile_key):
465 """Convenient method to get list of clients from profile key (manage list through profile_key like C.PROF_KEY_ALL) 473 """Convenient method to get list of clients from profile key (manage list through profile_key like C.PROF_KEY_ALL)
466 474
467 @param profile_key: %(doc_profile_key)s 475 @param profile_key: %(doc_profile_key)s
472 except exceptions.ProfileUnknownError: 480 except exceptions.ProfileUnknownError:
473 return [] 481 return []
474 if profile == C.PROF_KEY_ALL: 482 if profile == C.PROF_KEY_ALL:
475 return self.profiles.values() 483 return self.profiles.values()
476 elif profile.count('@') > 1: 484 elif profile.count('@') > 1:
477 raise exceptions.ProfileKeyUnknownError 485 raise exceptions.ProfileKeyUnknown
478 return [self.profiles[profile]] 486 return [self.profiles[profile]]
479 487
480 def _getConfig(self, section, name): 488 def _getConfig(self, section, name):
481 """Get the main configuration option 489 """Get the main configuration option
482 490
923 - xmlui: a XMLUI need to be displayed 931 - xmlui: a XMLUI need to be displayed
924 - validated: if present, can be used to launch a callback, it can have the values 932 - validated: if present, can be used to launch a callback, it can have the values
925 - C.BOOL_TRUE 933 - C.BOOL_TRUE
926 - C.BOOL_FALSE 934 - C.BOOL_FALSE
927 """ 935 """
928 client = self.getClient(profile_key) 936 try:
929 try: 937 client = self.getClient(profile_key)
930 action_tuple = client.actions[callback_id] 938 except exceptions.NotFound:
931 except KeyError: 939 # client is not available yet
932 pass 940 profile = self.memory.getProfileName(profile_key)
941 if not profile:
942 raise exceptions.ProfileUnknownError(_('trying to launch action with a non-existant profile'))
933 else: 943 else:
934 action_tuple[-1].cancel() # the last item is the action timer 944 profile = client.profile
945 # we check if the action is kept, and remove it
946 try:
947 action_tuple = client.actions[callback_id]
948 except KeyError:
949 pass
950 else:
951 action_tuple[-1].cancel() # the last item is the action timer
952 del client.actions[callback_id]
935 953
936 try: 954 try:
937 callback, args, kwargs = self._cb_map[callback_id] 955 callback, args, kwargs = self._cb_map[callback_id]
938 except KeyError: 956 except KeyError:
939 raise exceptions.DataError(u"Unknown callback id {}".format(callback_id)) 957 raise exceptions.DataError(u"Unknown callback id {}".format(callback_id))
941 if kwargs.get("with_data", False): 959 if kwargs.get("with_data", False):
942 if data is None: 960 if data is None:
943 raise exceptions.DataError("Required data for this callback is missing") 961 raise exceptions.DataError("Required data for this callback is missing")
944 args,kwargs=list(args)[:],kwargs.copy() # we don't want to modify the original (kw)args 962 args,kwargs=list(args)[:],kwargs.copy() # we don't want to modify the original (kw)args
945 args.insert(0, data) 963 args.insert(0, data)
946 kwargs["profile"] = client.profile 964 kwargs["profile"] = profile
947 del kwargs["with_data"] 965 del kwargs["with_data"]
948 966
949 if kwargs.pop('one_shot', False): 967 if kwargs.pop('one_shot', False):
950 self.removeCallback(callback_id) 968 self.removeCallback(callback_id)
951 969