# HG changeset patch # User Goffi # Date 1447841184 -3600 # Node ID 7e749e8eefd08fd088dea76f9d8e9b4b0ecf2f9d # Parent ec48b35309dcf845ccf003d96ab8a0cb45d5c93b 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 diff -r ec48b35309dc -r 7e749e8eefd0 src/core/exceptions.py --- a/src/core/exceptions.py Tue Nov 17 21:29:03 2015 +0100 +++ b/src/core/exceptions.py Wed Nov 18 11:06:24 2015 +0100 @@ -33,16 +33,16 @@ pass -class ConnectedProfileError(Exception): +class ProfileConnected(Exception): """This error is raised when trying to delete a connected profile.""" pass -class NotConnectedProfileError(Exception): +class ProfileNotConnected(Exception): pass -class ProfileKeyUnknownError(Exception): +class ProfileKeyUnknown(Exception): pass diff -r ec48b35309dc -r 7e749e8eefd0 src/core/sat_main.py --- a/src/core/sat_main.py Tue Nov 17 21:29:03 2015 +0100 +++ b/src/core/sat_main.py Wed Nov 18 11:06:24 2015 +0100 @@ -455,11 +455,19 @@ def getClient(self, profile_key): """Convenient method to get client from profile key - @return: client or None if it doesn't exist""" + + @return: client or None if it doesn't exist + @raise exceptions.ProfileKeyUnknown: the profile or profile key doesn't exist + @raise exceptions.NotFound: client is not available + This happen if profile has not been use yet + """ profile = self.memory.getProfileName(profile_key) if not profile: - raise exceptions.ProfileKeyUnknownError - return self.profiles[profile] + raise exceptions.ProfileKeyUnknown + try: + return self.profiles[profile] + except KeyError: + raise exceptions.NotFound def getClients(self, profile_key): """Convenient method to get list of clients from profile key (manage list through profile_key like C.PROF_KEY_ALL) @@ -474,7 +482,7 @@ if profile == C.PROF_KEY_ALL: return self.profiles.values() elif profile.count('@') > 1: - raise exceptions.ProfileKeyUnknownError + raise exceptions.ProfileKeyUnknown return [self.profiles[profile]] def _getConfig(self, section, name): @@ -925,13 +933,23 @@ - C.BOOL_TRUE - C.BOOL_FALSE """ - client = self.getClient(profile_key) try: - action_tuple = client.actions[callback_id] - except KeyError: - pass + client = self.getClient(profile_key) + except exceptions.NotFound: + # client is not available yet + profile = self.memory.getProfileName(profile_key) + if not profile: + raise exceptions.ProfileUnknownError(_('trying to launch action with a non-existant profile')) else: - action_tuple[-1].cancel() # the last item is the action timer + profile = client.profile + # we check if the action is kept, and remove it + try: + action_tuple = client.actions[callback_id] + except KeyError: + pass + else: + action_tuple[-1].cancel() # the last item is the action timer + del client.actions[callback_id] try: callback, args, kwargs = self._cb_map[callback_id] @@ -943,7 +961,7 @@ raise exceptions.DataError("Required data for this callback is missing") args,kwargs=list(args)[:],kwargs.copy() # we don't want to modify the original (kw)args args.insert(0, data) - kwargs["profile"] = client.profile + kwargs["profile"] = profile del kwargs["with_data"] if kwargs.pop('one_shot', False): diff -r ec48b35309dc -r 7e749e8eefd0 src/memory/params.py --- a/src/memory/params.py Tue Nov 17 21:29:03 2015 +0100 +++ b/src/memory/params.py Wed Nov 18 11:06:24 2015 +0100 @@ -183,7 +183,7 @@ self.host.disconnect(profile) else: log.info(_("Trying to delete a connected profile")) - return defer.fail(Failure(exceptions.ConnectedProfileError)) + return defer.fail(Failure(exceptions.ProfileConnected)) return self.storage.deleteProfile(profile) def getProfileName(self, profile_key, return_profile_keys=False): @@ -482,7 +482,7 @@ if profile not in self.params: log.error(_('Requesting synchronous param for not connected profile')) - raise exceptions.NotConnectedProfileError(profile) + raise exceptions.ProfileNotConnected(profile) if attr == "value": value = self._getParam(category, name, profile=profile) diff -r ec48b35309dc -r 7e749e8eefd0 src/test/helpers.py --- a/src/test/helpers.py Tue Nov 17 21:29:03 2015 +0100 +++ b/src/test/helpers.py Wed Nov 18 11:06:24 2015 +0100 @@ -124,7 +124,7 @@ @return: client or None if it doesn't exist""" profile = self.memory.getProfileName(profile_key) if not profile: - raise exceptions.ProfileKeyUnknownError + raise exceptions.ProfileKeyUnknown if profile not in self.profiles: self.profiles[profile] = FakeClient(self, profile) return self.profiles[profile]