comparison src/core/sat_main.py @ 1603:2b82d846848e

core: added callback_id in DataError message of launchCallback
author Goffi <goffi@goffi.org>
date Sun, 15 Nov 2015 23:11:41 +0100
parents e2ed8009e66e
children 5b24d6bf5d15
comparison
equal deleted inserted replaced
1602:33728a2f17bf 1603:2b82d846848e
859 progress_dict[progress_id] = data 859 progress_dict[progress_id] = data
860 progress_dict[progress_id] = progress_cb(progress_id, data, profile) 860 progress_dict[progress_id] = progress_cb(progress_id, data, profile)
861 return progress_all 861 return progress_all
862 862
863 def registerCallback(self, callback, *args, **kwargs): 863 def registerCallback(self, callback, *args, **kwargs):
864 """ Register a callback. 864 """Register a callback.
865
865 Use with_data=True in kwargs if the callback use the optional data dict 866 Use with_data=True in kwargs if the callback use the optional data dict
866 use force_id=id to avoid generated id. Can lead to name conflict, avoid if possible 867 use force_id=id to avoid generated id. Can lead to name conflict, avoid if possible
867 use one_shot=True to delete callback once it have been called 868 use one_shot=True to delete callback once it have been called
868 @param callback: any callable 869 @param callback: any callable
869 @return: id of the registered callback 870 @return: id of the registered callback
908 raise exceptions.ProfileUnknownError(_('trying to launch action with a non-existant profile')) 909 raise exceptions.ProfileUnknownError(_('trying to launch action with a non-existant profile'))
909 910
910 try: 911 try:
911 callback, args, kwargs = self._cb_map[callback_id] 912 callback, args, kwargs = self._cb_map[callback_id]
912 except KeyError: 913 except KeyError:
913 raise exceptions.DataError("Unknown callback id") 914 raise exceptions.DataError(u"Unknown callback id {}".format(callback_id))
914 915
915 if kwargs.get("with_data", False): 916 if kwargs.get("with_data", False):
916 if data is None: 917 if data is None:
917 raise exceptions.DataError("Required data for this callback is missing") 918 raise exceptions.DataError("Required data for this callback is missing")
918 args,kwargs=list(args)[:],kwargs.copy() # we don't want to modify the original (kw)args 919 args,kwargs=list(args)[:],kwargs.copy() # we don't want to modify the original (kw)args